From 57a1060ba7a0b8b2f2b36aedcd60999c247076cb Mon Sep 17 00:00:00 2001 From: nathanlesage Date: Sat, 13 Apr 2019 11:36:42 +0200 Subject: [PATCH] Add inverted colour scheme listener for Windows, closes #77 --- CHANGELOG.md | 2 +- source/main/providers/appearance-provider.js | 8 ++++++++ source/renderer/dialog/preferences.js | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6072af925..be212481b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## GUI and Functionality -- **New Feature**: Zettlr can now automatically switch between light and dark mode either based on a fixed schedule or, if you are using macOS, based on the appearance of the operating system. +- **New Feature**: Zettlr can now automatically switch between light and dark mode either based on a fixed schedule or, if you are using macOS or Windows, based on the appearance of the operating system. - **New Feature**: Add words to the user defined dictionary. - Display contributors tab on the about dialog containing the names of all authors of the translation files. - The dictionary loading mechanism works far more reliably now. diff --git a/source/main/providers/appearance-provider.js b/source/main/providers/appearance-provider.js index c13e279aa2..ec9b84248a 100644 --- a/source/main/providers/appearance-provider.js +++ b/source/main/providers/appearance-provider.js @@ -53,6 +53,14 @@ class AppearanceProvider extends EventEmitter { // Set the var accordingly global.config.set('darkTheme', systemPreferences.isDarkMode()) }) + } else if (process.platform === 'win32') { + // On Windows, we achieve the same effect by listening for inverted colour + // scheme changes. + systemPreferences.on('inverted-color-scheme-changed', (event, invertedColorScheme) => { + if (this._mode !== 'system') return + // Also set the var accordingly + global.config.set('darkTheme', invertedColorScheme) + }) } // Subscribe to configuration updates diff --git a/source/renderer/dialog/preferences.js b/source/renderer/dialog/preferences.js index 2b79803b45..81042f80a6 100644 --- a/source/renderer/dialog/preferences.js +++ b/source/renderer/dialog/preferences.js @@ -36,7 +36,7 @@ class PreferencesDialog extends ZettlrDialog { data.attachmentExtensions = data.attachmentExtensions.join(', ') // Determine the ability of the OS to switch to dark mode - data.hasOSDarkMode = (process.platform === 'darwin') + data.hasOSDarkMode = ['darwin', 'win32'].includes(process.platform) return data }