diff options
author | 2017-10-25 09:52:33 +0200 | |
---|---|---|
committer | 2017-10-25 09:52:33 +0200 | |
commit | eaf3c8f5d1deee878b0da87df8a083143115994f (patch) | |
tree | 4ce5f5dff3791a41463e711f683fe5b7129550e8 /src/lib | |
parent | Merge pull request #58 from Blizzke/nl-BE (diff) | |
parent | Bump version to 5.0.0-beta.11 (diff) | |
download | ferdium-app-eaf3c8f5d1deee878b0da87df8a083143115994f.tar.gz ferdium-app-eaf3c8f5d1deee878b0da87df8a083143115994f.tar.zst ferdium-app-eaf3c8f5d1deee878b0da87df8a083143115994f.zip |
Merge pull request #108 from meetfranz/develop
Franz 5.0.0-beta.11
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Menu.js | 1 | ||||
-rw-r--r-- | src/lib/Tray.js | 73 |
2 files changed, 74 insertions, 0 deletions
diff --git a/src/lib/Menu.js b/src/lib/Menu.js index 9f23c4d70..a6cde4d36 100644 --- a/src/lib/Menu.js +++ b/src/lib/Menu.js | |||
@@ -49,6 +49,7 @@ const template = [ | |||
49 | }, | 49 | }, |
50 | { | 50 | { |
51 | role: 'zoomin', | 51 | role: 'zoomin', |
52 | accelerator: 'CommandOrControl+=', | ||
52 | }, | 53 | }, |
53 | { | 54 | { |
54 | role: 'zoomout', | 55 | role: 'zoomout', |
diff --git a/src/lib/Tray.js b/src/lib/Tray.js new file mode 100644 index 000000000..67150971e --- /dev/null +++ b/src/lib/Tray.js | |||
@@ -0,0 +1,73 @@ | |||
1 | import { app, Tray, Menu, systemPreferences } 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 | export default class TrayIcon { | ||
9 | mainWindow = null; | ||
10 | trayIcon = null; | ||
11 | |||
12 | constructor(mainWindow) { | ||
13 | this.mainWindow = mainWindow; | ||
14 | } | ||
15 | |||
16 | show() { | ||
17 | if (this.trayIcon) return; | ||
18 | |||
19 | this.trayIcon = new Tray(this._getAsset('tray', INDICATOR_TRAY_PLAIN)); | ||
20 | const trayMenuTemplate = [ | ||
21 | { | ||
22 | label: 'Show Franz', | ||
23 | click() { | ||
24 | this.mainWindow.show(); | ||
25 | }, | ||
26 | }, { | ||
27 | label: 'Quit Franz', | ||
28 | click() { | ||
29 | app.quit(); | ||
30 | }, | ||
31 | }, | ||
32 | ]; | ||
33 | |||
34 | const trayMenu = Menu.buildFromTemplate(trayMenuTemplate); | ||
35 | this.trayIcon.setContextMenu(trayMenu); | ||
36 | |||
37 | this.trayIcon.on('click', () => { | ||
38 | this.mainWindow.show(); | ||
39 | }); | ||
40 | } | ||
41 | |||
42 | hide() { | ||
43 | if (this.trayIcon) { | ||
44 | this.trayIcon.destroy(); | ||
45 | this.trayIcon = null; | ||
46 | } | ||
47 | } | ||
48 | |||
49 | setIndicator(indicator) { | ||
50 | if (!this.trayIcon) return; | ||
51 | |||
52 | this.trayIcon.setImage(this._getAsset('tray', indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN)); | ||
53 | |||
54 | if (process.platform === 'darwin') { | ||
55 | this.trayIcon.setPressedImage( | ||
56 | this._getAsset('tray', `${indicator !== 0 ? INDICATOR_TRAY_UNREAD : INDICATOR_TRAY_PLAIN}-active`), | ||
57 | ); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | |||
62 | _getAsset(type, asset) { | ||
63 | let platform = process.platform; | ||
64 | |||
65 | if (platform === 'darwin' && systemPreferences.isDarkMode()) { | ||
66 | platform = `${platform}-dark`; | ||
67 | } | ||
68 | |||
69 | return path.join( | ||
70 | __dirname, '..', 'assets', 'images', type, platform, `${asset}.${FILE_EXTENSION}`, | ||
71 | ); | ||
72 | } | ||
73 | } | ||