Skip to content

Commit

Permalink
Fix shutdown sequence being triggered over and over by the sleep mode…
Browse files Browse the repository at this point in the history
… trigger, when not using it to shut down or reboot the PC
  • Loading branch information
Raphiiko committed Aug 15, 2024
1 parent e281d05 commit 9ed4ac4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### 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]

Expand All @@ -40,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
11 changes: 9 additions & 2 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 @@ -201,6 +203,8 @@ export class ShutdownAutomationsService {
filter(() => this.config.triggersEnabled),
filter(() => this.config.triggerOnSleep),
filter(() => this.sleepMode),
// Only trigger if we haven't already triggered this sleep (resets once sleep mode disables)
filter(() => !this.triggeredThisSleep),
filter(() => Date.now() - this.sleepModeLastSet >= this.config.triggerOnSleepDuration),
filter(
() =>
Expand All @@ -213,7 +217,10 @@ export class ShutdownAutomationsService {
// 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

0 comments on commit 9ed4ac4

Please sign in to comment.