diff --git a/electron/electron.js b/electron/electron.js index aa37290b0..14c113adf 100644 --- a/electron/electron.js +++ b/electron/electron.js @@ -17,6 +17,7 @@ const { BrowserWindow } = require('electron') const {autoUpdater} = require("electron-updater") +const Store = require("electron-store"); const loger = require("electron-log"); const electronConf = require('electron-config') const userConf = new electronConf() @@ -29,6 +30,7 @@ const utils = require('./utils'); const config = require('./package.json'); const electronMenu = require("./electron-menu"); const spawn = require("child_process").spawn; +const store = new Store(); const isMac = process.platform === 'darwin' const isWin = process.platform === 'win32' @@ -133,6 +135,7 @@ function createMainWindow() { minHeight: 360, center: true, autoHideMenuBar: true, + backgroundColor: utils.getDefaultBackgroundColor(), webPreferences: { preload: path.join(__dirname, 'electron-preload.js'), webSecurity: true, @@ -276,6 +279,7 @@ function preCreateChildWindow() { show: false, parent: mainWindow, autoHideMenuBar: true, + backgroundColor: utils.getDefaultBackgroundColor(), webPreferences: { preload: path.join(__dirname, 'electron-preload.js'), webSecurity: true, @@ -328,6 +332,7 @@ function createChildWindow(args) { show: false, parent: mainWindow, autoHideMenuBar: true, + backgroundColor: utils.getDefaultBackgroundColor(), webPreferences: Object.assign({ preload: path.join(__dirname, 'electron-preload.js'), webSecurity: true, @@ -499,6 +504,7 @@ function createWebTabWindow(args) { autoHideMenuBar: true, titleBarStyle: 'hidden', titleBarOverlay, + backgroundColor: utils.getDefaultBackgroundColor(), webPreferences: Object.assign({ preload: path.join(__dirname, 'electron-preload.js'), webSecurity: true, @@ -1264,6 +1270,23 @@ ipcMain.on('openNotification', (event, args) => { event.returnValue = "ok" }) +/** + * 保存缓存 + */ +ipcMain.on('setStore', (event, args) => { + if (utils.isJson(args)) { + store.set(args.key, args.value) + } + event.returnValue = "ok" +}) + +/** + * 获取缓存 + */ +ipcMain.handle('getStore', (event, args) => { + return store.get(args) +}); + //================================================================ // Update //================================================================ diff --git a/electron/utils.js b/electron/utils.js index 8b376e6e8..d07adaa52 100644 --- a/electron/utils.js +++ b/electron/utils.js @@ -5,8 +5,10 @@ const dayjs = require("dayjs"); const http = require('http') const https = require('https') const crypto = require('crypto') -const {shell, dialog, session, Notification} = require("electron"); +const {shell, dialog, session, Notification, nativeTheme} = require("electron"); const loger = require("electron-log"); +const Store = require("electron-store"); +const store = new Store(); const utils = { /** @@ -659,6 +661,30 @@ const utils = { } browser.loadFile('./public/index.html', options).then(_ => { }).catch(_ => { }) } + }, + + /** + * 获取主题名称 + * @returns {string|*} + */ + getThemName() { + const themeConf = store.get("themeConf"); + if (["dark", "light"].includes(themeConf)) { + return themeConf; + } + return nativeTheme.shouldUseDarkColors ? "dark" : "light"; + }, + + /** + * 获取默认背景颜色 + * @returns {string} + */ + getDefaultBackgroundColor() { + if (utils.getThemName() === "dark") { + return "#0D0D0D"; + } else { + return "#FFFFFF"; + } } } diff --git a/resources/assets/js/App.vue b/resources/assets/js/App.vue index 17b341d94..5f7ec480c 100755 --- a/resources/assets/js/App.vue +++ b/resources/assets/js/App.vue @@ -1,7 +1,7 @@