diff options
author | Stefan Malzner <stefan@adlk.io> | 2017-10-22 21:40:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-22 21:40:43 +0200 |
commit | a714bb5cc95c5908fbba89f9d91afca4f11aa8b5 (patch) | |
tree | eea6d8e440d7f323163f5fe6f4ea8f06ef3a5748 /src/lib | |
parent | Added polish translation (diff) | |
parent | feature(Shortcuts): Add tab cycling with ctrl[+shift]+tab or ctrl+[pageup|pag... (diff) | |
download | ferdium-app-a714bb5cc95c5908fbba89f9d91afca4f11aa8b5.tar.gz ferdium-app-a714bb5cc95c5908fbba89f9d91afca4f11aa8b5.tar.zst ferdium-app-a714bb5cc95c5908fbba89f9d91afca4f11aa8b5.zip |
Merge branch 'develop' into master
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Tray.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/lib/Tray.js b/src/lib/Tray.js new file mode 100644 index 000000000..631342b24 --- /dev/null +++ b/src/lib/Tray.js | |||
@@ -0,0 +1,64 @@ | |||
1 | import { app, Tray, Menu } from 'electron'; | ||
2 | import path from 'path'; | ||
3 | |||
4 | const FILE_EXTENSION = process.platform === 'win32' ? 'ico' : 'png'; | ||
5 | const INDICATOR_TRAY_PLAIN = 'tray'; | ||
6 | const INDICATOR_TRAY_UNREAD = 'tray-unread'; | ||
7 | |||
8 | function getAsset(type, asset) { | ||
9 | return path.join( | ||
10 | __dirname, '..', 'assets', 'images', type, process.platform, `${asset}.${FILE_EXTENSION}`, | ||
11 | ); | ||
12 | } | ||
13 | |||
14 | export default class TrayIcon { | ||
15 | mainWindow = null; | ||
16 | trayIcon = null; | ||
17 | |||
18 | constructor(mainWindow) { | ||
19 | this.mainWindow = mainWindow; | ||
20 | } | ||
21 | |||
22 | show() { | ||
23 | this.trayIcon = new Tray(getAsset('tray', INDICATOR_TRAY_PLAIN)); | ||
24 | const trayMenuTemplate = [ | ||
25 | { | ||
26 | label: 'Show Franz', | ||
27 | click() { | ||
28 | this.mainWindow.show(); | ||
29 | }, | ||
30 | }, { | ||
31 | label: 'Quit Franz', | ||
32 | click() { | ||
33 | app.quit(); | ||
34 | }, | ||
35 | }, | ||
36 | ]; | ||
37 | |||
38 | const trayMenu = Menu.buildFromTemplate(trayMenuTemplate); | ||
39 | this.trayIcon.setContextMenu(trayMenu); | ||
40 | |||
41 | this.trayIcon.on('click', () => { | ||
42 | this.mainWindow.show(); | ||
43 | }); | ||
44 | } | ||
45 | |||
46 | hide() { | ||
47 | if (this.trayIcon) { | ||
48 | this.trayIcon.destroy(); | ||
49 | this.trayIcon = null; | ||
50 | } | ||
51 | } | ||
52 | |||
53 | setIndicator(indicator) { | ||
54 | if (!this.trayIcon) return; | ||
55 | |||
56 | this.trayIcon.setImage(getAsset('tray', indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN)); | ||
57 | |||
58 | if (process.platform === 'darwin') { | ||
59 | this.trayIcon.setPressedImage( | ||
60 | getAsset('tray', `${indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN}-active`), | ||
61 | ); | ||
62 | } | ||
63 | } | ||
64 | } | ||