From f1448a3d98d434fce6434a19338c7bd3ca517050 Mon Sep 17 00:00:00 2001 From: Rocka Date: Sat, 21 Nov 2020 15:13:18 +0800 Subject: [PATCH] main: 'auto' theme variety leveraging electron's nativeTheme --- src/main/index.js | 8 ++++++-- src/main/settings.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 1503d4a3..551f74dc 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1,5 +1,5 @@ import { join } from 'path'; -import { app, BrowserWindow, ipcMain, Menu } from 'electron'; +import { app, BrowserWindow, ipcMain, Menu, nativeTheme } from 'electron'; import { IsDev, IsDarwin, MainURL, LoginURL } from './util/constants'; import * as Settings from './settings'; @@ -32,6 +32,10 @@ app.commandLine.appendSwitch('disable-features', 'HardwareMediaKeyHandling,Media * @returns {import('electron').BrowserWindow} */ function createMainWindow(settings, url = MainURL) { + const windowBackgroundType = settings.themeVariety === 'auto' + ? (nativeTheme.shouldUseDarkColors ? 'dark' : 'light') + : settings.themeVariety; + const win = new BrowserWindow({ height: 700, width: 1000, @@ -40,7 +44,7 @@ function createMainWindow(settings, url = MainURL) { minHeight: 640, frame: settings.windowBorder, titleBarStyle: settings.windowBorder ? 'default' : 'hidden', - backgroundColor: MainBkgColor[settings.themeVariety], + backgroundColor: MainBkgColor[windowBackgroundType], title: Settings.productName, webPreferences: { zoomFactor: settings.windowZoom || 1, diff --git a/src/main/settings.js b/src/main/settings.js index e11df786..44cd9e37 100644 --- a/src/main/settings.js +++ b/src/main/settings.js @@ -23,7 +23,7 @@ export const defaultSettings = { minimizeOnStartup: false, themePrimaryColor: '#7e57c2', themeSecondaryColor: '#ff4081', - themeVariety: 'light', + themeVariety: 'auto', autoReplacePlaylist: false };