aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/controllers/NativeThemeController.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/main/src/controllers/NativeThemeController.ts')
-rw-r--r--packages/main/src/controllers/NativeThemeController.ts37
1 files changed, 24 insertions, 13 deletions
diff --git a/packages/main/src/controllers/NativeThemeController.ts b/packages/main/src/controllers/NativeThemeController.ts
index 07a3292..a50d41e 100644
--- a/packages/main/src/controllers/NativeThemeController.ts
+++ b/packages/main/src/controllers/NativeThemeController.ts
@@ -18,21 +18,32 @@
18 * SPDX-License-Identifier: AGPL-3.0-only 18 * SPDX-License-Identifier: AGPL-3.0-only
19 */ 19 */
20 20
21import { nativeTheme } from 'electron';
21import { autorun } from 'mobx'; 22import { autorun } from 'mobx';
22import type { IDisposer } from 'mobx-state-tree'; 23import { IDisposer } from 'mobx-state-tree';
23 24
24import type { NativeThemeService } from '../services/NativeThemeService';
25import type { MainStore } from '../stores/MainStore'; 25import type { MainStore } from '../stores/MainStore';
26 26
27export function initNativeTheme(store: MainStore, service: NativeThemeService): IDisposer { 27export class NativeThemeController {
28 const themeSourceReactionDisposer = autorun(() => { 28 private autorunDisposer: IDisposer | null = null;
29 service.setThemeSource(store.config.themeSource); 29
30 }); 30 private shouldUseDarkColorsListener: (() => void) | null = null;
31 const onShouldUseDarkColorsUpdatedDisposer = service.onShouldUseDarkColorsUpdated( 31
32 store.setShouldUseDarkColors, 32 connect(store: MainStore): void {
33 ); 33 this.autorunDisposer = autorun(() => {
34 return () => { 34 nativeTheme.themeSource = store.config.themeSource;
35 onShouldUseDarkColorsUpdatedDisposer(); 35 });
36 themeSourceReactionDisposer(); 36 store.setShouldUseDarkColors(nativeTheme.shouldUseDarkColors);
37 }; 37 this.shouldUseDarkColorsListener = () => {
38 store.setShouldUseDarkColors(nativeTheme.shouldUseDarkColors);
39 };
40 nativeTheme.on('updated', this.shouldUseDarkColorsListener);
41 }
42
43 dispose(): void {
44 if (this.shouldUseDarkColorsListener !== null) {
45 nativeTheme.off('updated', this.shouldUseDarkColorsListener);
46 }
47 this.autorunDisposer?.();
48 }
38} 49}