From 502f3d4a69fa5a61fd547820ef30341bec905b8f Mon Sep 17 00:00:00 2001 From: kPherox Date: Wed, 24 Apr 2019 20:59:30 +0900 Subject: [PATCH] Add listener for changed ui theme --- src/main/Application.ts | 16 ++++++++++++++++ src/views/App.vue | 17 ++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/Application.ts b/src/main/Application.ts index 07b3f89f..7c6848c3 100644 --- a/src/main/Application.ts +++ b/src/main/Application.ts @@ -1,6 +1,9 @@ import { app, + ipcMain, shell, + systemPreferences, + Event, Menu, } from 'electron' import { @@ -22,10 +25,21 @@ export default class Application { return this._instance || (this._instance = new this()) } + public isDarkMode: boolean + private constructor() { + this.isDarkMode = systemPreferences.isDarkMode() + app.on('window-all-closed', () => this.onWindowAllClosed()) app.on('ready', () => this.onReady()) app.on('activate', () => this.onActivated()) + + systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', () => { + this.isDarkMode = systemPreferences.isDarkMode() + Window.windowMap.forEach(win => { + win.webContents.send('change-color-theme') + }) + }) } public setApplicationMenu(menu: Menu) { @@ -52,6 +66,8 @@ export default class Application { Timeline.ready() Streaming.ready() + ipcMain.on('dark-theme', (e: Event) => e.returnValue = this.isDarkMode) + Window.Main() } diff --git a/src/views/App.vue b/src/views/App.vue index 10817458..ddc533df 100644 --- a/src/views/App.vue +++ b/src/views/App.vue @@ -5,7 +5,7 @@