Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphiiko committed Aug 16, 2024
2 parents 5e6f175 + 03cc296 commit 7ec172f
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 50 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ 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.
- Shutdown sequence being triggered over and over by the sleep mode trigger, when not using it to shut down or reboot the PC.

## [1.13.3]

### Fixed
Expand All @@ -36,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Certain types of selection in input fields (e.g. Ctrl+A) being blocked

### Changed

- Window titlebar icons

## [1.13.2]
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();
}
}
}
10 changes: 0 additions & 10 deletions src-ui/app/services/mqtt/integrations/hmd-data.mqtt-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,9 @@ export class HMDDataMqttIntegrationService {
value: 'off',
available: false,
});
await this.mqtt.initProperty({
type: 'SENSOR',
id: 'debugHmdActivity',
topicPath: 'debugHmdActivity',
displayName: 'VR HMD Activity (DEBUG)',
value: 'null',
available: false,
});
this.openvr.status.subscribe((status) => {
this.mqtt.setPropertyAvailability('hmdModel', status === 'INITIALIZED');
this.mqtt.setPropertyAvailability('hmdOnHead', status === 'INITIALIZED');
this.mqtt.setPropertyAvailability('debugHmdActivity', status === 'INITIALIZED');
});
this.openvr.devices
.pipe(map((devices) => devices.find((d) => d.class === 'HMD')))
Expand All @@ -47,7 +38,6 @@ export class HMDDataMqttIntegrationService {
[device?.manufacturerName, device?.modelNumber].filter(Boolean).join(' ') ?? 'null';
this.mqtt.setSensorPropertyValue('hmdModel', name);
this.mqtt.setSensorPropertyValue('hmdOnHead', device?.hmdOnHead ? 'on' : 'off');
this.mqtt.setSensorPropertyValue('debugHmdActivity', device?.debugHmdActivity ?? 'null');
});
}
}
22 changes: 16 additions & 6 deletions src-ui/app/services/shutdown-automations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class ShutdownAutomationsService {
);
private sleepMode = false;
private sleepModeLastSet = 0;
private triggeredThisSleep = false;
private aloneSince = 0;
private isAlone = false;
private wasNotAlone = false;
Expand Down Expand Up @@ -105,7 +106,7 @@ export class ShutdownAutomationsService {
this.automationConfigService.configs
.pipe(
map((configs) => configs.SHUTDOWN_AUTOMATIONS),
// Reset the 'last set' in case any of the trigger parameters change, so the user doesn't get any unwanted surprises
// Reset the 'alone since' in case any of the trigger parameters change, so the user doesn't get any unwanted surprises
pairwise(),
filter(([oldConfig, newConfig]) => {
const keys: Array<keyof ShutdownAutomationsConfig> = [
Expand All @@ -125,6 +126,7 @@ export class ShutdownAutomationsService {
// Track sleep mode being set
this.sleepService.mode.pipe(distinctUntilChanged()).subscribe((mode) => {
this.sleepMode = mode;
if (!this.sleepMode) this.triggeredThisSleep = false;
this.sleepModeLastSet = Date.now();
});
// Track being alone
Expand Down Expand Up @@ -197,23 +199,31 @@ export class ShutdownAutomationsService {
private async handleTriggerOnSleep() {
interval(1000)
.pipe(
filter(() => this._stage.value === 'IDLE'),
// Only trigger if this trigger is enabled
filter(() => this.config.triggersEnabled),
filter(() => this.config.triggerOnSleep),
// Only trigger if the shutdown sequence isn't running
filter(() => this._stage.value === 'IDLE'),
// Only trigger if the sleep mode is active
filter(() => this.sleepMode),
// Only trigger if we haven't already triggered this sleep (resets once sleep mode disables)
filter(() => !this.triggeredThisSleep),
// Only trigger if the sleep mode has been active for long enough
filter(() => Date.now() - this.sleepModeLastSet >= this.config.triggerOnSleepDuration),
// Only trigger if we're in the activation window, if it's configured
filter(
() =>
!this.config.triggerOnSleepActivationWindow ||
this.isInActivationWindow(
this.config.triggerOnSleepActivationWindowStart,
this.config.triggerOnSleepActivationWindowEnd
)
),
// Only trigger once every 5 minutes at most
throttleTime(300000, asyncScheduler, { leading: true, trailing: false })
)
)
.subscribe(() => this.runSequence('SLEEP_TRIGGER'));
.subscribe(() => {
this.triggeredThisSleep = true;
this.runSequence('SLEEP_TRIGGER');
});
}

private async handleTriggerWhenAlone() {
Expand Down
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 7ec172f

Please sign in to comment.