diff options
author | 2020-04-10 12:41:22 +0530 | |
---|---|---|
committer | 2020-04-10 08:11:22 +0100 | |
commit | 212f29c5d7ce15cf205adcd17063258b0be306ff (patch) | |
tree | 9ef4406d57243675892f2bced4b4a87d229627e5 /src/lib/Tray.js | |
parent | Minor spelling fixes in README (#552) (diff) | |
download | ferdium-app-212f29c5d7ce15cf205adcd17063258b0be306ff.tar.gz ferdium-app-212f29c5d7ce15cf205adcd17063258b0be306ff.tar.zst ferdium-app-212f29c5d7ce15cf205adcd17063258b0be306ff.zip |
Add notification & audio toggle action in tray context menu (#542)
* feat: Add new tray menu item to enable / disable Notifications and Audio
- Use ipcMain to listen to iniital App Settings which determines the current isAppMuted state and display menu item text accordingly
- Use ipcMain to listen to updates to App Settings -> isAppMuted from the App Menu / Side Bar and display menu item text accordingly
- When the user clicks on the Enable / Disable Notifications & Audio menu item in the Tray, pass a message to the app via window.webContents.send with channel 'muteApp'
- In stores/AppStore.js, use an ipcRenderer to toggleMuteApp()
- To get the initial app state to the main process, pass a channel 'initialAppSettings' from SettingsStore which the tray class can listen to.
* feat - System Tray menu item for Muting App
- Fix lint errors
* feat: Provide a menu item in the tray bar icon to Mute/Unmute the application
- Revert package-lock.json to the previous commit.
Diffstat (limited to 'src/lib/Tray.js')
-rw-r--r-- | src/lib/Tray.js | 66 |
1 files changed, 46 insertions, 20 deletions
diff --git a/src/lib/Tray.js b/src/lib/Tray.js index 84ee8e3bb..3700cca27 100644 --- a/src/lib/Tray.js +++ b/src/lib/Tray.js | |||
@@ -1,5 +1,5 @@ | |||
1 | import { | 1 | import { |
2 | app, Menu, nativeImage, nativeTheme, systemPreferences, Tray, | 2 | app, Menu, nativeImage, nativeTheme, systemPreferences, Tray, ipcMain, |
3 | } from 'electron'; | 3 | } from 'electron'; |
4 | import path from 'path'; | 4 | import path from 'path'; |
5 | 5 | ||
@@ -14,29 +14,55 @@ export default class TrayIcon { | |||
14 | 14 | ||
15 | themeChangeSubscriberId = null; | 15 | themeChangeSubscriberId = null; |
16 | 16 | ||
17 | trayMenu = null; | ||
18 | |||
19 | trayMenuTemplate = [ | ||
20 | { | ||
21 | label: 'Show Ferdi', | ||
22 | click() { | ||
23 | if (app.mainWindow.isMinimized()) { | ||
24 | app.mainWindow.restore(); | ||
25 | } | ||
26 | app.mainWindow.show(); | ||
27 | app.mainWindow.focus(); | ||
28 | }, | ||
29 | }, | ||
30 | { | ||
31 | label: 'Disable Notifications & Audio', | ||
32 | click() { | ||
33 | app.mainWindow.webContents.send('muteApp'); | ||
34 | }, | ||
35 | }, | ||
36 | { | ||
37 | label: 'Quit Ferdi', | ||
38 | click() { | ||
39 | app.quit(); | ||
40 | }, | ||
41 | }, | ||
42 | ]; | ||
43 | |||
44 | _updateTrayMenu(appSettings) { | ||
45 | if (appSettings.type === 'app') { | ||
46 | const { isAppMuted } = appSettings.data; | ||
47 | this.trayMenuTemplate[1].label = isAppMuted ? 'Enable Notifications && Audio' : 'Disable Notifications && Audio'; | ||
48 | this.trayMenu = Menu.buildFromTemplate(this.trayMenuTemplate); | ||
49 | } | ||
50 | } | ||
51 | |||
17 | show() { | 52 | show() { |
18 | if (this.trayIcon) return; | 53 | if (this.trayIcon) return; |
19 | 54 | ||
20 | this.trayIcon = new Tray(this._getAsset('tray', INDICATOR_TRAY_PLAIN)); | 55 | this.trayIcon = new Tray(this._getAsset('tray', INDICATOR_TRAY_PLAIN)); |
21 | const trayMenuTemplate = [ | ||
22 | { | ||
23 | label: 'Show Ferdi', | ||
24 | click() { | ||
25 | if (app.mainWindow.isMinimized()) { | ||
26 | app.mainWindow.restore(); | ||
27 | } | ||
28 | app.mainWindow.show(); | ||
29 | app.mainWindow.focus(); | ||
30 | }, | ||
31 | }, { | ||
32 | label: 'Quit Ferdi', | ||
33 | click() { | ||
34 | app.quit(); | ||
35 | }, | ||
36 | }, | ||
37 | ]; | ||
38 | 56 | ||
39 | const trayMenu = Menu.buildFromTemplate(trayMenuTemplate); | 57 | this.trayMenu = Menu.buildFromTemplate(this.trayMenuTemplate); |
58 | |||
59 | ipcMain.on('initialAppSettings', (event, appSettings) => { | ||
60 | this._updateTrayMenu(appSettings); | ||
61 | }); | ||
62 | |||
63 | ipcMain.on('updateAppSettings', (event, appSettings) => { | ||
64 | this._updateTrayMenu(appSettings); | ||
65 | }); | ||
40 | 66 | ||
41 | this.trayIcon.on('click', () => { | 67 | this.trayIcon.on('click', () => { |
42 | if (app.mainWindow.isMinimized()) { | 68 | if (app.mainWindow.isMinimized()) { |
@@ -50,7 +76,7 @@ export default class TrayIcon { | |||
50 | }); | 76 | }); |
51 | 77 | ||
52 | this.trayIcon.on('right-click', () => { | 78 | this.trayIcon.on('right-click', () => { |
53 | this.trayIcon.popUpContextMenu(trayMenu); | 79 | this.trayIcon.popUpContextMenu(this.trayMenu); |
54 | }); | 80 | }); |
55 | 81 | ||
56 | if (process.platform === 'darwin') { | 82 | if (process.platform === 'darwin') { |