From 9546dc2aa39ab096ccc723786e718a739d0bdaf9 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Thu, 27 Jan 2022 00:17:22 +0100 Subject: refactor: Coding conventions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure that files have a default import with the same name as the file whenever possible to reduce surprise. Also shuffles around some file names for better legibility. Signed-off-by: Kristóf Marussy --- .../main/src/reactions/synchronizeNativeTheme.ts | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 packages/main/src/reactions/synchronizeNativeTheme.ts (limited to 'packages/main/src/reactions/synchronizeNativeTheme.ts') diff --git a/packages/main/src/reactions/synchronizeNativeTheme.ts b/packages/main/src/reactions/synchronizeNativeTheme.ts new file mode 100644 index 0000000..8c4edb3 --- /dev/null +++ b/packages/main/src/reactions/synchronizeNativeTheme.ts @@ -0,0 +1,47 @@ +/* + * 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 SharedStore from '../stores/SharedStore'; +import type Disposer from '../utils/Disposer'; +import { getLogger } from '../utils/log'; + +const log = getLogger('synchronizeNativeTheme'); + +export default function initNativeTheme(store: SharedStore): Disposer { + const disposeThemeSourceReaction = autorun(() => { + nativeTheme.themeSource = store.settings.themeSource; + log.debug('Set theme source:', store.settings.themeSource); + }); + + store.setShouldUseDarkColors(nativeTheme.shouldUseDarkColors); + const shouldUseDarkColorsListener = () => { + store.setShouldUseDarkColors(nativeTheme.shouldUseDarkColors); + log.debug('Set should use dark colors:', nativeTheme.shouldUseDarkColors); + }; + nativeTheme.on('updated', shouldUseDarkColorsListener); + + return () => { + nativeTheme.off('updated', shouldUseDarkColorsListener); + disposeThemeSourceReaction(); + }; +} -- cgit v1.2.3-54-g00ecf