Skip to content

Commit

Permalink
Add (hidden) "When my headset connects to SteamVR" brightness automat…
Browse files Browse the repository at this point in the history
…ion event
  • Loading branch information
Raphiiko committed Sep 28, 2024
1 parent e4cc942 commit 7720506
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 7 deletions.
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"eslint-plugin-json": "^3.1.0",
"flag-icons": "^6.6.6",
"fuse.js": "^6.6.2",
"konami-code-js": "^0.8.1",
"lodash": "^4.17.21",
"marked": "^4.2.2",
"material-icons": "^1.12.1",
Expand Down Expand Up @@ -109,6 +110,7 @@
"@protobuf-ts/plugin": "^2.9.0",
"@tauri-apps/cli": "^1.5.11",
"@types/cookie": "^0.6.0",
"@types/konami-code-js": "^0.8.3",
"@types/lodash": "^4.14.188",
"@types/marked": "^4.0.7",
"@types/set-cookie-parser": "^2.4.2",
Expand Down
13 changes: 13 additions & 0 deletions src-ui/app/models/automations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const BrightnessEvents = [
'SLEEP_PREPARATION',
'AT_SUNSET',
'AT_SUNRISE',
'HMD_CONNECT',
] as const;
export type BrightnessEvent = (typeof BrightnessEvents)[number];

Expand All @@ -133,6 +134,7 @@ export type BrightnessAutomationsConfig = AutomationConfig & {
SLEEP_PREPARATION: GenericBrightnessEventAutomationConfig;
SLEEP_MODE_ENABLE: GenericBrightnessEventAutomationConfig;
SLEEP_MODE_DISABLE: GenericBrightnessEventAutomationConfig;
HMD_CONNECT: GenericBrightnessEventAutomationConfig;
};

export type BrightnessEventAutomationConfig =
Expand Down Expand Up @@ -548,6 +550,17 @@ export const AUTOMATION_CONFIGS_DEFAULT: AutomationConfigs = {
onlyWhenSleepDisabled: true,
activationTime: null,
},
HMD_CONNECT: {
enabled: false,
changeBrightness: true,
changeColorTemperature: true,
brightness: 100,
softwareBrightness: 100,
hardwareBrightness: 100,
transition: true,
transitionTime: 10000,
colorTemperature: 6600,
},
},
// RESOLUTION AUTOMATIONS
RENDER_RESOLUTION_ON_SLEEP_MODE_ENABLE: {
Expand Down
1 change: 1 addition & 0 deletions src-ui/app/models/one-time-flags.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const OneTimeFlags = [
'CCT_CONTROL_WARNING_DIALOG',
'BASESTATION_COUNT_WARNING_DIALOG',
'BRIGHTNESS_AUTOMATION_ON_HMD_CONNECT_EVENT_FEATURE',
] as const;

export type OneTimeFlag = (typeof OneTimeFlags)[number];
4 changes: 4 additions & 0 deletions src-ui/app/services/app-settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
asyncScheduler,
BehaviorSubject,
firstValueFrom,
map,
Observable,
skip,
switchMap,
Expand Down Expand Up @@ -82,6 +83,9 @@ export class AppSettingsService {
public oneTimeFlagSet(flag: OneTimeFlag): boolean {
return this._settings.value.oneTimeFlags.includes(flag);
}
public oneTimeFlagSetAsync(flag: OneTimeFlag): Observable<boolean> {
return this._settings.pipe(map((settings) => settings.oneTimeFlags.includes(flag)));
}

public setOneTimeFlag(flag: OneTimeFlag, set = true): void {
if (set === this.oneTimeFlagSet(flag)) return;
Expand Down
16 changes: 13 additions & 3 deletions src-ui/app/services/brightness-cct-automation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,21 @@ export class BrightnessCctAutomationService {
| 'AT_SUNRISE'
| 'SLEEP_MODE_ENABLE'
| 'SLEEP_MODE_DISABLE'
| 'HMD_CONNECT'
| undefined;
let cctAutomation:
| 'AT_SUNSET'
| 'AT_SUNRISE'
| 'SLEEP_MODE_ENABLE'
| 'SLEEP_MODE_DISABLE'
| 'HMD_CONNECT'
| undefined;
// If sunrise/sunset times are both enabled, use their settings for brightness and CCT, if configured.
// If HMD connect is enabled, use its settings for brightness and CCT, if configured.
if (config.HMD_CONNECT.enabled) {
if (config.HMD_CONNECT.changeBrightness) brightnessAutomation = 'HMD_CONNECT';
if (config.HMD_CONNECT.changeColorTemperature) cctAutomation = 'HMD_CONNECT';
}
// Otherwise 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 @@ -261,8 +268,10 @@ export class BrightnessCctAutomationService {
} else {
runAutomation = timesInverted ? 'AT_SUNSET' : 'AT_SUNRISE';
}
if (config[runAutomation].changeBrightness) brightnessAutomation = runAutomation;
if (config[runAutomation].changeColorTemperature) cctAutomation = runAutomation;
if (!brightnessAutomation && config[runAutomation].changeBrightness)
brightnessAutomation = runAutomation;
if (!cctAutomation && config[runAutomation].changeColorTemperature)
cctAutomation = runAutomation;
}
// Otherwise, use the values configured for the sleep mode automations (if they're enabled)
const sleepMode = await firstValueFrom(this.sleepService.mode);
Expand Down Expand Up @@ -326,6 +335,7 @@ export class BrightnessCctAutomationService {
SLEEP_PREPARATION: 'SLEEP_PREPARATION',
AT_SUNRISE: 'AT_SUNRISE',
AT_SUNSET: 'AT_SUNSET',
HMD_CONNECT: 'HMD_CONNECT',
};
const logReason: SetBrightnessOrCCTReason = eventLogReasonMap[automationType];
// Handle CCT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export type SetBrightnessOrCCTReason =
| 'SLEEP_MODE_DISABLE'
| 'SLEEP_PREPARATION'
| 'AT_SUNSET'
| 'AT_SUNRISE';
| 'AT_SUNRISE'
| 'HMD_CONNECT';

export interface SetBrightnessOrCCTOptions {
cancelActiveTransition: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Component } from '@angular/core';
import { Component, DestroyRef, OnDestroy, OnInit } from '@angular/core';
import { BrightnessEvent } from '../../../../../../models/automations';
import { triggerChildren } from '../../../../../../utils/animations';
import { AppSettingsService } from '../../../../../../services/app-settings.service';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { filter } from 'rxjs';
import KonamiCode from 'konami-code-js';

export interface BrightnessEventViewModel {
name: BrightnessEvent;
Expand All @@ -16,7 +20,7 @@ export interface BrightnessEventViewModel {
styleUrls: ['./brightness-automations-tab.component.scss'],
animations: [triggerChildren()],
})
export class BrightnessAutomationsTabComponent {
export class BrightnessAutomationsTabComponent implements OnInit, OnDestroy {
protected editEvent?: BrightnessEventViewModel;

protected events: Array<BrightnessEventViewModel> = [
Expand All @@ -32,4 +36,26 @@ export class BrightnessAutomationsTabComponent {
sunMode: 'SUNRISE',
},
];

private konami: KonamiCode | undefined;

constructor(private appSettings: AppSettingsService, private destroyRef: DestroyRef) {}

ngOnInit() {
this.appSettings
.oneTimeFlagSetAsync('BRIGHTNESS_AUTOMATION_ON_HMD_CONNECT_EVENT_FEATURE')
.pipe(takeUntilDestroyed(this.destroyRef), filter(Boolean))
.subscribe(() => {
this.events.push({ name: 'HMD_CONNECT', inProgress: false, icon: 'head_mounted_device' });
});

this.konami = new KonamiCode(() => {
this.konami?.disable();
this.appSettings.setOneTimeFlag('BRIGHTNESS_AUTOMATION_ON_HMD_CONNECT_EVENT_FEATURE');
});
}

ngOnDestroy() {
this.konami?.disable();
}
}
5 changes: 4 additions & 1 deletion src-ui/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@
"SLEEP_PREPARATION": {
"title": "When I prepare to go to sleep"
},
"HMD_CONNECT": {
"title": "When my headset connects to SteamVR"
},
"activation": {
"category": "Activation"
},
Expand Down Expand Up @@ -2626,4 +2629,4 @@
},
"title": "VRChat Microphone Mute Automations"
}
}
}

0 comments on commit 7720506

Please sign in to comment.