Skip to content

A full-featured download manager.

refactor: nativeTheme.shouldUseDarkColors

Dr_rOot95ed300d1bf1
diff --git a/src/main/ui/ThemeManager.js b/src/main/ui/ThemeManager.js
index 280a7155..c8ca3f52 100644
--- a/src/main/ui/ThemeManager.js
+++ b/src/main/ui/ThemeManager.js
@@ -1,5 +1,5 @@
import { EventEmitter } from 'events'
-import { systemPreferences } from 'electron'
+import { nativeTheme, systemPreferences } from 'electron'
import is from 'electron-is'
import { LIGHT_THEME, DARK_THEME } from '@shared/constants'
@@ -19,7 +19,7 @@ export default class ThemeManager extends EventEmitter {
if (!is.macOS()) {
return result
}
- result = systemPreferences.isDarkMode() ? DARK_THEME : LIGHT_THEME
+ result = nativeTheme.shouldUseDarkColors ? DARK_THEME : LIGHT_THEME
return result
}
@@ -27,14 +27,12 @@ export default class ThemeManager extends EventEmitter {
if (!is.macOS()) {
return
}
- systemPreferences.subscribeNotification(
- 'AppleInterfaceThemeChangedNotification',
- () => {
- const theme = this.getSystemTheme()
- this.updateAppAppearance(theme)
- this.emit('system-theme-changed', theme)
- }
- )
+ nativeTheme.on('updated', () => {
+ const theme = this.getSystemTheme()
+ console.log('theme updated===>', theme)
+ this.updateAppAppearance(theme)
+ this.emit('system-theme-changed', theme)
+ })
}
updateAppAppearance (theme) {
diff --git a/src/main/ui/TrayManager.js b/src/main/ui/TrayManager.js
index 185810c5..a5ee3917 100644
--- a/src/main/ui/TrayManager.js
+++ b/src/main/ui/TrayManager.js
@@ -1,6 +1,6 @@
import { EventEmitter } from 'events'
import { join } from 'path'
-import { Tray, Menu, systemPreferences } from 'electron'
+import { Tray, Menu, nativeTheme } from 'electron'
import is from 'electron-is'
import {
translateTemplate,
@@ -28,7 +28,7 @@ export default class TrayManager extends EventEmitter {
load () {
this.template = require(`../menus/tray.json`)
- const theme = systemPreferences.isDarkMode() ? DARK_THEME : LIGHT_THEME
+ const theme = nativeTheme.shouldUseDarkColors ? DARK_THEME : LIGHT_THEME
if (is.macOS()) {
this.normalIcon = join(__static, `./mo-tray-${theme}-normal.png`)
diff --git a/src/renderer/components/Native/utils.js b/src/renderer/components/Native/utils.js
index e0b2ff97..54693ef1 100644
--- a/src/renderer/components/Native/utils.js
+++ b/src/renderer/components/Native/utils.js
@@ -133,6 +133,6 @@ export function getSystemTheme () {
if (!is.macOS()) {
return result
}
- result = remote.systemPreferences.isDarkMode() ? DARK_THEME : LIGHT_THEME
+ result = remote.nativeTheme.shouldUseDarkColors ? DARK_THEME : LIGHT_THEME
return result
}