Skip to content

Commit

Permalink
Fix duration inputs in shutdown sequence triggers on systems with 12 …
Browse files Browse the repository at this point in the history
…hour clock.
  • Loading branch information
Raphiiko committed Aug 15, 2024
1 parent d6d8d7b commit e281d05
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Option for the brightness automations based on sleep mode to run on SteamVR launch. This now happens automatically when a HMD is connected.

### Fixed

- Duration inputs for shutdown sequence triggers being broken on systems using a 12-hour clock.

## [1.13.3]

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
readonly
(mouseenter)="mouseEnter('INPUT')"
(mouseleave)="mouseLeave('INPUT')"
(click)="mouseClickInput()"
[disabled]="disabled"
/>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,10 @@ export class DurationInputSettingComponent {
if (Object.values(this.mouseInside).every((v) => !v)) this.inputOpen = false;
}, 200);
}

mouseClickInput() {
if (this.inputOpen && this.hourInput?.nativeElement) {
this.hourInput.nativeElement.focus();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,10 @@ <h2 translate>shutdown-automations.triggers.triggers</h2>
<span translate>shutdown-automations.triggers.whenAsleepDuration.description</span>
</div>
<div class="setting-row-action">
<div class="input-wrapper">
<input
type="time"
step="1"
[value]="onSleepDurationString"
(change)="onSleepDurationChange(onSleepDurationInput.value)"
#onSleepDurationInput
/>
</div>
<app-duration-input-setting
[value]="config.triggerOnSleepDuration"
(valueChange)="onSleepDurationChange($event)"
></app-duration-input-setting>
</div>
</div>

Expand Down Expand Up @@ -117,15 +112,10 @@ <h2 translate>shutdown-automations.triggers.triggers</h2>
<span translate>shutdown-automations.triggers.whenAloneDuration.description</span>
</div>
<div class="setting-row-action">
<div class="input-wrapper">
<input
type="time"
step="1"
[value]="whenAloneDurationString"
(change)="whenAloneDurationChange(whenAloneDurationInput.value)"
#whenAloneDurationInput
/>
</div>
<app-duration-input-setting
[value]="config.triggerWhenAloneDuration"
(valueChange)="whenAloneDurationChange($event)"
></app-duration-input-setting>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ export class ShutdownAutomationsTriggersTabComponent implements OnInit {
protected onSleepActivationWindowEnd = '00:00';
protected whenAloneActivationWindowStart = '00:00';
protected whenAloneActivationWindowEnd = '00:00';
protected onSleepDurationString = '00:00:00';
protected whenAloneDurationString = '00:00:00';

constructor(private automationConfigs: AutomationConfigService, private destroyRef: DestroyRef) {}

Expand All @@ -32,14 +30,12 @@ export class ShutdownAutomationsTriggersTabComponent implements OnInit {
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((configs) => {
this.config = configs.SHUTDOWN_AUTOMATIONS;
this.onSleepDurationString = this.durationToString(this.config.triggerOnSleepDuration);
this.onSleepActivationWindowStart = this.config.triggerOnSleepActivationWindowStart
.map((v) => v.toString().padStart(2, '0'))
.join(':');
this.onSleepActivationWindowEnd = this.config.triggerOnSleepActivationWindowEnd
.map((v) => v.toString().padStart(2, '0'))
.join(':');
this.whenAloneDurationString = this.durationToString(this.config.triggerWhenAloneDuration);
this.whenAloneActivationWindowStart = this.config.triggerWhenAloneActivationWindowStart
.map((v) => v.toString().padStart(2, '0'))
.join(':');
Expand Down Expand Up @@ -75,12 +71,7 @@ export class ShutdownAutomationsTriggersTabComponent implements OnInit {
);
}

async onSleepDurationChange(value: string) {
let [hours, minutes, seconds] = value.split(':').map((v) => parseInt(v));
if (isNaN(hours)) hours = 0;
if (isNaN(minutes)) minutes = 0;
if (isNaN(seconds)) seconds = 0;
const duration = (hours * 3600 + minutes * 60 + seconds) * 1000;
async onSleepDurationChange(duration: number) {
await this.automationConfigs.updateAutomationConfig<ShutdownAutomationsConfig>(
'SHUTDOWN_AUTOMATIONS',
{
Expand All @@ -89,12 +80,7 @@ export class ShutdownAutomationsTriggersTabComponent implements OnInit {
);
}

async whenAloneDurationChange(value: string) {
let [hours, minutes, seconds] = value.split(':').map((v) => parseInt(v));
if (isNaN(hours)) hours = 0;
if (isNaN(minutes)) minutes = 0;
if (isNaN(seconds)) seconds = 0;
const duration = (hours * 3600 + minutes * 60 + seconds) * 1000;
async whenAloneDurationChange(duration: number) {
await this.automationConfigs.updateAutomationConfig<ShutdownAutomationsConfig>(
'SHUTDOWN_AUTOMATIONS',
{
Expand Down

0 comments on commit e281d05

Please sign in to comment.