From 5712e88785d600a63d59cb583f045375c8c16255 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Tue, 28 Dec 2021 13:51:16 +0100 Subject: refactor: Functional design for controllers --- packages/main/src/controllers/nativeTheme.ts | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 packages/main/src/controllers/nativeTheme.ts (limited to 'packages/main/src/controllers/nativeTheme.ts') diff --git a/packages/main/src/controllers/nativeTheme.ts b/packages/main/src/controllers/nativeTheme.ts new file mode 100644 index 0000000..e4390a8 --- /dev/null +++ b/packages/main/src/controllers/nativeTheme.ts @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021-2022 Kristóf Marussy + * + * This file is part of Sophie. + * + * Sophie is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { nativeTheme } from 'electron'; +import { autorun } from 'mobx'; + +import type { MainStore } from '../stores/MainStore'; +import { Disposer } from '../utils'; + +export function initNativeTheme(store: MainStore): Disposer { + const disposeThemeSourceReaction = autorun(() => { + nativeTheme.themeSource = store.config.themeSource; + }); + + store.setShouldUseDarkColors(nativeTheme.shouldUseDarkColors); + const shouldUseDarkColorsListener = () => { + store.setShouldUseDarkColors(nativeTheme.shouldUseDarkColors); + }; + nativeTheme.on('updated', shouldUseDarkColorsListener); + + return () => { + nativeTheme.off('updated', shouldUseDarkColorsListener); + disposeThemeSourceReaction(); + }; +} -- cgit v1.2.3-54-g00ecf