Skip to content

Commit

Permalink
fix: tray icon adapts to the dark mode agalwood#206 agalwood#207
Browse files Browse the repository at this point in the history
  • Loading branch information
agalwood committed Apr 21, 2019
1 parent 7a903e1 commit d5b3ad5
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export default class Application extends EventEmitter {
initThemeManager () {
this.themeManager = new ThemeManager()
this.themeManager.on('system-theme-changed', (theme) => {
this.trayManager.changeIconTheme(theme)
this.sendCommandToAll('application:theme', theme)
})
}
Expand Down
26 changes: 22 additions & 4 deletions src/main/ui/TrayManager.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { EventEmitter } from 'events'
import { join } from 'path'
import { Tray, Menu } from 'electron'
import { Tray, Menu, systemPreferences } from 'electron'
import is from 'electron-is'
import { translateTemplate } from '../utils/menu'
import { getI18n } from '@/ui/Locale'
import { LIGHT_THEME, DARK_THEME } from '@shared/constants'

let tray = null

Expand All @@ -23,10 +24,11 @@ export default class TrayManager extends EventEmitter {

load () {
this.template = require(`../menus/tray.json`)
const theme = systemPreferences.isDarkMode() ? DARK_THEME : LIGHT_THEME

if (is.macOS()) {
this.normalIcon = join(__static, './mo-tray-normal.png')
this.activeIcon = join(__static, './mo-tray-active.png')
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')
Expand Down Expand Up @@ -91,7 +93,23 @@ export default class TrayManager extends EventEmitter {
}

updateStatus (status) {
const icon = status ? this.activeIcon : this.normalIcon
this.status = status
this.updateIcon()
}

updateIcon () {
const icon = this.status ? this.activeIcon : this.normalIcon
tray.setImage(icon)
}

changeIconTheme (theme = LIGHT_THEME) {
if (!is.macOS()) {
return
}

this.normalIcon = join(__static, `./mo-tray-${theme}-normal.png`)
this.activeIcon = join(__static, `./mo-tray-${theme}-active.png`)

this.updateIcon()
}
}
Binary file removed static/mo-tray-active.png
Binary file not shown.
Binary file removed static/[email protected]
Binary file not shown.
Binary file added static/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed static/mo-tray-normal.png
Binary file not shown.
Binary file removed static/[email protected]
Binary file not shown.

0 comments on commit d5b3ad5

Please sign in to comment.