diff options
author | 2017-10-19 11:15:25 +0200 | |
---|---|---|
committer | 2017-10-19 11:19:50 +0200 | |
commit | ef503a1e29a540c7318efb5f2018efbf00706198 (patch) | |
tree | 05930a5d43f45c0e769c9ba256ba82f00d85b6ac /src/electron | |
parent | remove unnecessary platform check (diff) | |
download | ferdium-app-ef503a1e29a540c7318efb5f2018efbf00706198.tar.gz ferdium-app-ef503a1e29a540c7318efb5f2018efbf00706198.tar.zst ferdium-app-ef503a1e29a540c7318efb5f2018efbf00706198.zip |
Add option to disable system tray icon
Diffstat (limited to 'src/electron')
-rw-r--r-- | src/electron/Settings.js | 14 | ||||
-rw-r--r-- | src/electron/ipc-api/appIndicator.js | 45 |
2 files changed, 26 insertions, 33 deletions
diff --git a/src/electron/Settings.js b/src/electron/Settings.js index 049a08296..824b4c20c 100644 --- a/src/electron/Settings.js +++ b/src/electron/Settings.js | |||
@@ -1,5 +1,17 @@ | |||
1 | import { observable } from 'mobx'; | ||
2 | |||
3 | import { DEFAULT_APP_SETTINGS } from '../config'; | ||
4 | |||
1 | export default class Settings { | 5 | export default class Settings { |
2 | store = {}; | 6 | @observable store = { |
7 | autoLaunchOnStart: DEFAULT_APP_SETTINGS.autoLaunchOnStart, | ||
8 | autoLaunchInBackground: DEFAULT_APP_SETTINGS.autoLaunchInBackground, | ||
9 | runInBackground: DEFAULT_APP_SETTINGS.runInBackground, | ||
10 | enableSystemTray: DEFAULT_APP_SETTINGS.enableSystemTray, | ||
11 | minimizeToSystemTray: DEFAULT_APP_SETTINGS.minimizeToSystemTray, | ||
12 | locale: DEFAULT_APP_SETTINGS.locale, | ||
13 | beta: DEFAULT_APP_SETTINGS.beta, | ||
14 | }; | ||
3 | 15 | ||
4 | set(settings) { | 16 | set(settings) { |
5 | this.store = Object.assign(this.store, settings); | 17 | this.store = Object.assign(this.store, settings); |
diff --git a/src/electron/ipc-api/appIndicator.js b/src/electron/ipc-api/appIndicator.js index 576234d25..d31819068 100644 --- a/src/electron/ipc-api/appIndicator.js +++ b/src/electron/ipc-api/appIndicator.js | |||
@@ -1,12 +1,11 @@ | |||
1 | import { app, ipcMain, Tray, Menu } from 'electron'; | 1 | import { app, ipcMain } from 'electron'; |
2 | import path from 'path'; | 2 | import path from 'path'; |
3 | import { autorun } from 'mobx'; | ||
3 | 4 | ||
4 | const INDICATOR_TRAY_PLAIN = 'tray'; | ||
5 | const INDICATOR_TRAY_UNREAD = 'tray-unread'; | ||
6 | const INDICATOR_TASKBAR = 'taskbar'; | 5 | const INDICATOR_TASKBAR = 'taskbar'; |
7 | |||
8 | const FILE_EXTENSION = process.platform === 'win32' ? 'ico' : 'png'; | 6 | const FILE_EXTENSION = process.platform === 'win32' ? 'ico' : 'png'; |
9 | let trayIcon; | 7 | |
8 | let isTrayIconEnabled; | ||
10 | 9 | ||
11 | function getAsset(type, asset) { | 10 | function getAsset(type, asset) { |
12 | return path.join( | 11 | return path.join( |
@@ -15,26 +14,14 @@ function getAsset(type, asset) { | |||
15 | } | 14 | } |
16 | 15 | ||
17 | export default (params) => { | 16 | export default (params) => { |
18 | trayIcon = new Tray(getAsset('tray', INDICATOR_TRAY_PLAIN)); | 17 | autorun(() => { |
19 | const trayMenuTemplate = [ | 18 | isTrayIconEnabled = params.settings.get('enableSystemTray'); |
20 | { | ||
21 | label: 'Show Franz', | ||
22 | click() { | ||
23 | params.mainWindow.show(); | ||
24 | }, | ||
25 | }, { | ||
26 | label: 'Quit Franz', | ||
27 | click() { | ||
28 | app.quit(); | ||
29 | }, | ||
30 | }, | ||
31 | ]; | ||
32 | |||
33 | const trayMenu = Menu.buildFromTemplate(trayMenuTemplate); | ||
34 | trayIcon.setContextMenu(trayMenu); | ||
35 | 19 | ||
36 | trayIcon.on('click', () => { | 20 | if (!isTrayIconEnabled) { |
37 | params.mainWindow.show(); | 21 | params.trayIcon.hide(); |
22 | } else if (isTrayIconEnabled) { | ||
23 | params.trayIcon.show(); | ||
24 | } | ||
38 | }); | 25 | }); |
39 | 26 | ||
40 | ipcMain.on('updateAppIndicator', (event, args) => { | 27 | ipcMain.on('updateAppIndicator', (event, args) => { |
@@ -68,13 +55,7 @@ export default (params) => { | |||
68 | } | 55 | } |
69 | } | 56 | } |
70 | 57 | ||
71 | // Update system tray | 58 | // Update Tray |
72 | trayIcon.setImage(getAsset('tray', args.indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN)); | 59 | params.trayIcon.setIndicator(args.indicator); |
73 | |||
74 | if (process.platform === 'darwin') { | ||
75 | trayIcon.setPressedImage( | ||
76 | getAsset('tray', `${args.indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN}-active`), | ||
77 | ); | ||
78 | } | ||
79 | }); | 60 | }); |
80 | }; | 61 | }; |