Skip to content

A full-featured download manager.

refactor: tray manager

Dr_rOotac75a055110b
diff --git a/src/main/Application.js b/src/main/Application.js
index c778af28..3990b68b 100644
--- a/src/main/Application.js
+++ b/src/main/Application.js
@@ -55,7 +55,9 @@ export default class Application extends EventEmitter {
this.autoSyncTracker()
- this.trayManager = new TrayManager()
+ this.trayManager = new TrayManager({
+ theme: this.configManager.getUserConfig('tray-theme')
+ })
this.dockManager = new DockManager({
runMode: this.configManager.getUserConfig('run-mode')
diff --git a/src/main/core/ConfigManager.js b/src/main/core/ConfigManager.js
index 2455215d..6cbe55fc 100644
--- a/src/main/core/ConfigManager.js
+++ b/src/main/core/ConfigManager.js
@@ -103,6 +103,7 @@ export default class ConfigManager {
NGOSANG_TRACKERS_BEST_IP_URL,
NGOSANG_TRACKERS_BEST_URL
],
+ 'tray-theme': APP_THEME.AUTO,
'update-channel': 'latest',
'use-proxy': false,
'window-state': {}
diff --git a/src/main/ui/TrayManager.js b/src/main/ui/TrayManager.js
index ec4008a3..2803fd50 100644
--- a/src/main/ui/TrayManager.js
+++ b/src/main/ui/TrayManager.js
@@ -16,8 +16,8 @@ export default class TrayManager extends EventEmitter {
constructor (options = {}) {
super()
+ this.theme = options.theme || APP_THEME.AUTO
this.i18n = getI18n()
-
this.menu = null
this.load()
@@ -28,15 +28,23 @@ export default class TrayManager extends EventEmitter {
load () {
this.template = require(`../menus/tray.json`)
- const theme = nativeTheme.shouldUseDarkColors ? APP_THEME.DARK : APP_THEME.LIGHT
-
- if (is.macOS()) {
- this.normalIcon = join(__static, `./mo-tray-${theme}-normal.png`)
- this.activeIcon = join(__static, `./mo-tray-${theme}-active.png`)
- } else {
- this.normalIcon = join(__static, './mo-tray-colorful-normal.png')
- this.activeIcon = join(__static, './mo-tray-colorful-active.png')
+
+ let theme = APP_THEME.LIGHT
+
+ if (is.windows()) {
+ theme = 'colorful'
+ } else if (is.macOS()) {
+ theme = nativeTheme.shouldUseDarkColors ? APP_THEME.DARK : APP_THEME.LIGHT
+ } else if (is.linux()) {
+ theme = (this.theme === APP_THEME.AUTO) ? APP_THEME.DARK : this.theme
}
+
+ this.setIcons(theme)
+ }
+
+ setIcons (theme) {
+ this.normalIcon = join(__static, `./mo-tray-${theme}-normal.png`)
+ this.activeIcon = join(__static, `./mo-tray-${theme}-active.png`)
}
build () {
@@ -97,12 +105,12 @@ export default class TrayManager extends EventEmitter {
global.application.handleFile(files[0])
}
- updateStatus (status) {
+ updateTrayByStatus (status) {
this.status = status
- this.updateIcon()
+ this.updateTray()
}
- updateIcon () {
+ updateTray () {
const icon = this.status ? this.activeIcon : this.normalIcon
tray.setImage(icon)
}
@@ -112,10 +120,9 @@ export default class TrayManager extends EventEmitter {
return
}
- this.normalIcon = join(__static, `./mo-tray-${theme}-normal.png`)
- this.activeIcon = join(__static, `./mo-tray-${theme}-active.png`)
+ this.setIcons(theme)
- this.updateIcon()
+ this.updateTray()
}
updateMenuStates (visibleStates, enabledStates, checkedStates) {