Skip to content

Commit

Permalink
Merge branch 'develop' into steam-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphiiko committed Sep 21, 2024
2 parents a0460e2 + f4f290d commit 0b9504a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src-core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ fn main() {
.build(tauri::generate_context!())
.expect("An error occurred while running the application")
.run(|handler, event| match event {
tauri::RunEvent::Exit { .. } => {
if TELEMETRY_ENABLED.load(Ordering::Relaxed) {
handler.track_event("app_exited", None);
handler.flush_events_blocking();
}
}
// tauri::RunEvent::Exit { .. } => {
// if TELEMETRY_ENABLED.load(Ordering::Relaxed) {
// handler.track_event("app_exited", None);
// handler.flush_events_blocking();
// }
// }
_ => {}
})
}
Expand Down
72 changes: 62 additions & 10 deletions src-ui/app/services/brightness-cct-automation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,19 @@ export class BrightnessCctAutomationService {
const config = await firstValueFrom(this.automationConfigService.configs).then(
(c) => c.BRIGHTNESS_AUTOMATIONS
);
// If sunrise/sunset times are both enabled, use the relevant values configured for those
let brightnessAutomation:
| 'AT_SUNSET'
| 'AT_SUNRISE'
| 'SLEEP_MODE_ENABLE'
| 'SLEEP_MODE_DISABLE'
| undefined;
let cctAutomation:
| 'AT_SUNSET'
| 'AT_SUNRISE'
| 'SLEEP_MODE_ENABLE'
| 'SLEEP_MODE_DISABLE'
| undefined;
// If sunrise/sunset times are both enabled, use their settings for brightness and CCT, if configured.
if (
config.AT_SUNSET.enabled &&
config.AT_SUNRISE.enabled &&
Expand All @@ -249,21 +261,61 @@ export class BrightnessCctAutomationService {
} else {
runAutomation = timesInverted ? 'AT_SUNSET' : 'AT_SUNRISE';
}
await this.onAutomationTrigger(runAutomation, config[runAutomation], true, false);
if (config[runAutomation].changeBrightness) brightnessAutomation = runAutomation;
if (config[runAutomation].changeColorTemperature) cctAutomation = runAutomation;
}
// Otherwise, use the values configured for the sleep mode automations (if they're enabled)
else if (await firstValueFrom(this.sleepService.mode)) {
await this.onAutomationTrigger('SLEEP_MODE_ENABLE', config.SLEEP_MODE_ENABLE, true, false);
} else {
await this.onAutomationTrigger('SLEEP_MODE_DISABLE', config.SLEEP_MODE_DISABLE, true, false);
}
const sleepMode = await firstValueFrom(this.sleepService.mode);
// Brightness
if (
!brightnessAutomation &&
sleepMode &&
config.SLEEP_MODE_ENABLE.enabled &&
config.SLEEP_MODE_ENABLE.changeBrightness
)
brightnessAutomation = 'SLEEP_MODE_ENABLE';
else if (
!brightnessAutomation &&
!sleepMode &&
config.SLEEP_MODE_DISABLE.enabled &&
config.SLEEP_MODE_DISABLE.changeBrightness
)
brightnessAutomation = 'SLEEP_MODE_DISABLE';
// CCT
if (
!cctAutomation &&
sleepMode &&
config.SLEEP_MODE_ENABLE.enabled &&
config.SLEEP_MODE_ENABLE.changeColorTemperature
)
cctAutomation = 'SLEEP_MODE_ENABLE';
else if (
!cctAutomation &&
!sleepMode &&
config.SLEEP_MODE_DISABLE.enabled &&
config.SLEEP_MODE_DISABLE.changeColorTemperature
)
cctAutomation = 'SLEEP_MODE_DISABLE';
if (brightnessAutomation)
this.onAutomationTrigger(
brightnessAutomation,
config[brightnessAutomation],
true,
false,
true,
false
);
if (cctAutomation)
this.onAutomationTrigger(cctAutomation, config[cctAutomation], true, false, false, true);
}

private async onAutomationTrigger(
automationType: BrightnessEvent,
config: BrightnessEventAutomationConfig,
forceInstant = false,
logging = true
logging = true,
runBrightness = true,
runCCT = true
) {
// Stop if the automation is disabled
if (!config.enabled || (!config.changeBrightness && !config.changeColorTemperature)) return;
Expand All @@ -277,7 +329,7 @@ export class BrightnessCctAutomationService {
};
const logReason: SetBrightnessOrCCTReason = eventLogReasonMap[automationType];
// Handle CCT
if (config.changeColorTemperature) {
if (config.changeColorTemperature && runCCT) {
this.cctControl.cancelActiveTransition();
// Apply the CCT changes
if (!forceInstant && config.transition) {
Expand All @@ -303,7 +355,7 @@ export class BrightnessCctAutomationService {
}
}
// Handle Brightness
if (config.changeBrightness) {
if (config.changeBrightness && runBrightness) {
this.simpleBrightnessControl.cancelActiveTransition();
this.hardwareBrightnessControl.cancelActiveTransition();
this.softwareBrightnessControl.cancelActiveTransition();
Expand Down

0 comments on commit 0b9504a

Please sign in to comment.