diff options
author | 2020-05-17 15:17:07 +0200 | |
---|---|---|
committer | 2020-05-17 13:17:07 +0000 | |
commit | 4576a5080c51918907c89629cefe389945179d71 (patch) | |
tree | 614e278ac7a4b9f55ce393eba4d40b37bd3724f1 | |
parent | Replace change server input with a dropdown menu (#717) (diff) | |
download | ferdium-app-4576a5080c51918907c89629cefe389945179d71.tar.gz ferdium-app-4576a5080c51918907c89629cefe389945179d71.tar.zst ferdium-app-4576a5080c51918907c89629cefe389945179d71.zip |
Make Tray icons more robust on Linux (#748)
-rw-r--r-- | package-lock.json | 109 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | src/index.js | 8 | ||||
-rw-r--r-- | src/lib/DBus.js | 49 | ||||
-rw-r--r-- | src/lib/Tray.js | 43 |
5 files changed, 202 insertions, 8 deletions
diff --git a/package-lock.json b/package-lock.json index 0e43558a5..c3d3e2474 100644 --- a/package-lock.json +++ b/package-lock.json | |||
@@ -4403,6 +4403,11 @@ | |||
4403 | "integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==", | 4403 | "integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==", |
4404 | "dev": true | 4404 | "dev": true |
4405 | }, | 4405 | }, |
4406 | "@nornagon/put": { | ||
4407 | "version": "0.0.8", | ||
4408 | "resolved": "https://registry.npmjs.org/@nornagon/put/-/put-0.0.8.tgz", | ||
4409 | "integrity": "sha512-ugvXJjwF5ldtUpa7D95kruNJ41yFQDEKyF5CW4TgKJnh+W/zmlBzXXeKTyqIgwMFrkePN2JqOBqcF0M0oOunow==" | ||
4410 | }, | ||
4406 | "@octokit/endpoint": { | 4411 | "@octokit/endpoint": { |
4407 | "version": "5.5.1", | 4412 | "version": "5.5.1", |
4408 | "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-5.5.1.tgz", | 4413 | "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-5.5.1.tgz", |
@@ -5140,6 +5145,16 @@ | |||
5140 | "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", | 5145 | "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", |
5141 | "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" | 5146 | "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" |
5142 | }, | 5147 | }, |
5148 | "abstract-socket": { | ||
5149 | "version": "2.1.1", | ||
5150 | "resolved": "https://registry.npmjs.org/abstract-socket/-/abstract-socket-2.1.1.tgz", | ||
5151 | "integrity": "sha512-YZJizsvS1aBua5Gd01woe4zuyYBGgSMeqDOB6/ChwdTI904KP6QGtJswXl4hcqWxbz86hQBe++HWV0hF1aGUtA==", | ||
5152 | "optional": true, | ||
5153 | "requires": { | ||
5154 | "bindings": "^1.2.1", | ||
5155 | "nan": "^2.12.1" | ||
5156 | } | ||
5157 | }, | ||
5143 | "accepts": { | 5158 | "accepts": { |
5144 | "version": "1.0.7", | 5159 | "version": "1.0.7", |
5145 | "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.0.7.tgz", | 5160 | "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.0.7.tgz", |
@@ -9134,6 +9149,21 @@ | |||
9134 | "integrity": "sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==", | 9149 | "integrity": "sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==", |
9135 | "dev": true | 9150 | "dev": true |
9136 | }, | 9151 | }, |
9152 | "dbus-next": { | ||
9153 | "version": "0.8.2", | ||
9154 | "resolved": "https://registry.npmjs.org/dbus-next/-/dbus-next-0.8.2.tgz", | ||
9155 | "integrity": "sha512-E2wkbhZzzsgmY+jxIdeuhA1nVT697I5koRIRJTk3doTeukwtzqSFG89RC5XK8OsLG/eHDZ8PVNptUuEPkhdPbA==", | ||
9156 | "requires": { | ||
9157 | "@nornagon/put": "0.0.8", | ||
9158 | "abstract-socket": "^2.0.0", | ||
9159 | "event-stream": "3.3.4", | ||
9160 | "hexy": "^0.2.10", | ||
9161 | "jsbi": "^2.0.5", | ||
9162 | "long": "^4.0.0", | ||
9163 | "safe-buffer": "^5.1.1", | ||
9164 | "xml2js": "^0.4.17" | ||
9165 | } | ||
9166 | }, | ||
9137 | "debug": { | 9167 | "debug": { |
9138 | "version": "4.1.1", | 9168 | "version": "4.1.1", |
9139 | "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", | 9169 | "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", |
@@ -11452,6 +11482,30 @@ | |||
11452 | "resolved": "https://registry.npmjs.org/event-kit/-/event-kit-2.5.3.tgz", | 11482 | "resolved": "https://registry.npmjs.org/event-kit/-/event-kit-2.5.3.tgz", |
11453 | "integrity": "sha512-b7Qi1JNzY4BfAYfnIRanLk0DOD1gdkWHT4GISIn8Q2tAf3LpU8SP2CMwWaq40imYoKWbtN4ZhbSRxvsnikooZQ==" | 11483 | "integrity": "sha512-b7Qi1JNzY4BfAYfnIRanLk0DOD1gdkWHT4GISIn8Q2tAf3LpU8SP2CMwWaq40imYoKWbtN4ZhbSRxvsnikooZQ==" |
11454 | }, | 11484 | }, |
11485 | "event-stream": { | ||
11486 | "version": "3.3.4", | ||
11487 | "resolved": "https://registry.npmjs.org/event-stream/-/event-stream-3.3.4.tgz", | ||
11488 | "integrity": "sha1-SrTJoPWlTbkzi0w02Gv86PSzVXE=", | ||
11489 | "requires": { | ||
11490 | "duplexer": "~0.1.1", | ||
11491 | "from": "~0", | ||
11492 | "map-stream": "~0.1.0", | ||
11493 | "pause-stream": "0.0.11", | ||
11494 | "split": "0.3", | ||
11495 | "stream-combiner": "~0.0.4", | ||
11496 | "through": "~2.3.1" | ||
11497 | }, | ||
11498 | "dependencies": { | ||
11499 | "split": { | ||
11500 | "version": "0.3.3", | ||
11501 | "resolved": "https://registry.npmjs.org/split/-/split-0.3.3.tgz", | ||
11502 | "integrity": "sha1-zQ7qXmOiEd//frDwkcQTPi0N0o8=", | ||
11503 | "requires": { | ||
11504 | "through": "2" | ||
11505 | } | ||
11506 | } | ||
11507 | } | ||
11508 | }, | ||
11455 | "eventemitter2": { | 11509 | "eventemitter2": { |
11456 | "version": "5.0.1", | 11510 | "version": "5.0.1", |
11457 | "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-5.0.1.tgz", | 11511 | "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-5.0.1.tgz", |
@@ -12426,6 +12480,11 @@ | |||
12426 | "integrity": "sha1-lzHc9WeMf660T7kDxPct9VGH+nc=", | 12480 | "integrity": "sha1-lzHc9WeMf660T7kDxPct9VGH+nc=", |
12427 | "dev": true | 12481 | "dev": true |
12428 | }, | 12482 | }, |
12483 | "from": { | ||
12484 | "version": "0.1.7", | ||
12485 | "resolved": "https://registry.npmjs.org/from/-/from-0.1.7.tgz", | ||
12486 | "integrity": "sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4=" | ||
12487 | }, | ||
12429 | "from2": { | 12488 | "from2": { |
12430 | "version": "2.3.0", | 12489 | "version": "2.3.0", |
12431 | "resolved": "https://registry.npmjs.org/from2/-/from2-2.3.0.tgz", | 12490 | "resolved": "https://registry.npmjs.org/from2/-/from2-2.3.0.tgz", |
@@ -15628,6 +15687,11 @@ | |||
15628 | "resolved": "https://registry.npmjs.org/hex-to-rgba/-/hex-to-rgba-1.0.2.tgz", | 15687 | "resolved": "https://registry.npmjs.org/hex-to-rgba/-/hex-to-rgba-1.0.2.tgz", |
15629 | "integrity": "sha512-fL+4NFccs86iOuDnFl1Mhyn471qTPAkpE7k39+JYGPMB3+S9LoUnauQI2nz6BUb3DpYQCx8RqENbaf8IFdKYOg==" | 15688 | "integrity": "sha512-fL+4NFccs86iOuDnFl1Mhyn471qTPAkpE7k39+JYGPMB3+S9LoUnauQI2nz6BUb3DpYQCx8RqENbaf8IFdKYOg==" |
15630 | }, | 15689 | }, |
15690 | "hexy": { | ||
15691 | "version": "0.2.11", | ||
15692 | "resolved": "https://registry.npmjs.org/hexy/-/hexy-0.2.11.tgz", | ||
15693 | "integrity": "sha512-ciq6hFsSG/Bpt2DmrZJtv+56zpPdnq+NQ4ijEFrveKN0ZG1mhl/LdT1NQZ9se6ty1fACcI4d4vYqC9v8EYpH2A==" | ||
15694 | }, | ||
15631 | "history": { | 15695 | "history": { |
15632 | "version": "3.3.0", | 15696 | "version": "3.3.0", |
15633 | "resolved": "https://registry.npmjs.org/history/-/history-3.3.0.tgz", | 15697 | "resolved": "https://registry.npmjs.org/history/-/history-3.3.0.tgz", |
@@ -17490,6 +17554,11 @@ | |||
17490 | "esprima": "^4.0.0" | 17554 | "esprima": "^4.0.0" |
17491 | } | 17555 | } |
17492 | }, | 17556 | }, |
17557 | "jsbi": { | ||
17558 | "version": "2.0.5", | ||
17559 | "resolved": "https://registry.npmjs.org/jsbi/-/jsbi-2.0.5.tgz", | ||
17560 | "integrity": "sha512-TzO/62Hxeb26QMb4IGlI/5X+QLr9Uqp1FPkwp2+KOICW+Q+vSuFj61c8pkT6wAns4WcK56X7CmSHhJeDGWOqxQ==" | ||
17561 | }, | ||
17493 | "jsbn": { | 17562 | "jsbn": { |
17494 | "version": "0.1.1", | 17563 | "version": "0.1.1", |
17495 | "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", | 17564 | "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", |
@@ -18507,6 +18576,11 @@ | |||
18507 | "integrity": "sha512-Sgr5lbboAUBo3eXCSPL4/KoVz3ROKquOjcctxmHIt+vol2DrqTQe3SwkKKuYhEiWB5kYa13YyopJ69deJ1irzQ==", | 18576 | "integrity": "sha512-Sgr5lbboAUBo3eXCSPL4/KoVz3ROKquOjcctxmHIt+vol2DrqTQe3SwkKKuYhEiWB5kYa13YyopJ69deJ1irzQ==", |
18508 | "dev": true | 18577 | "dev": true |
18509 | }, | 18578 | }, |
18579 | "long": { | ||
18580 | "version": "4.0.0", | ||
18581 | "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", | ||
18582 | "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==" | ||
18583 | }, | ||
18510 | "longest": { | 18584 | "longest": { |
18511 | "version": "1.0.1", | 18585 | "version": "1.0.1", |
18512 | "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", | 18586 | "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", |
@@ -18826,6 +18900,11 @@ | |||
18826 | "integrity": "sha1-plzSkIepJZi4eRJXpSPgISIqwfk=", | 18900 | "integrity": "sha1-plzSkIepJZi4eRJXpSPgISIqwfk=", |
18827 | "dev": true | 18901 | "dev": true |
18828 | }, | 18902 | }, |
18903 | "map-stream": { | ||
18904 | "version": "0.1.0", | ||
18905 | "resolved": "https://registry.npmjs.org/map-stream/-/map-stream-0.1.0.tgz", | ||
18906 | "integrity": "sha1-5WqpTEyAVaFkBKBnS3jyFffI4ZQ=" | ||
18907 | }, | ||
18829 | "map-visit": { | 18908 | "map-visit": { |
18830 | "version": "1.0.0", | 18909 | "version": "1.0.0", |
18831 | "resolved": "https://registry.npmjs.org/map-visit/-/map-visit-1.0.0.tgz", | 18910 | "resolved": "https://registry.npmjs.org/map-visit/-/map-visit-1.0.0.tgz", |
@@ -21352,6 +21431,14 @@ | |||
21352 | "pify": "^3.0.0" | 21431 | "pify": "^3.0.0" |
21353 | } | 21432 | } |
21354 | }, | 21433 | }, |
21434 | "pause-stream": { | ||
21435 | "version": "0.0.11", | ||
21436 | "resolved": "https://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz", | ||
21437 | "integrity": "sha1-/lo0sMvOErWqaitAPuLnO2AvFEU=", | ||
21438 | "requires": { | ||
21439 | "through": "~2.3" | ||
21440 | } | ||
21441 | }, | ||
21355 | "pbkdf2": { | 21442 | "pbkdf2": { |
21356 | "version": "3.0.17", | 21443 | "version": "3.0.17", |
21357 | "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.0.17.tgz", | 21444 | "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.0.17.tgz", |
@@ -24975,6 +25062,14 @@ | |||
24975 | } | 25062 | } |
24976 | } | 25063 | } |
24977 | }, | 25064 | }, |
25065 | "stream-combiner": { | ||
25066 | "version": "0.0.4", | ||
25067 | "resolved": "https://registry.npmjs.org/stream-combiner/-/stream-combiner-0.0.4.tgz", | ||
25068 | "integrity": "sha1-TV5DPBhSYd3mI8o/RMWGvPXErRQ=", | ||
25069 | "requires": { | ||
25070 | "duplexer": "~0.1.1" | ||
25071 | } | ||
25072 | }, | ||
24978 | "stream-each": { | 25073 | "stream-each": { |
24979 | "version": "1.2.3", | 25074 | "version": "1.2.3", |
24980 | "resolved": "https://registry.npmjs.org/stream-each/-/stream-each-1.2.3.tgz", | 25075 | "resolved": "https://registry.npmjs.org/stream-each/-/stream-each-1.2.3.tgz", |
@@ -27873,6 +27968,20 @@ | |||
27873 | "integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==", | 27968 | "integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==", |
27874 | "dev": true | 27969 | "dev": true |
27875 | }, | 27970 | }, |
27971 | "xml2js": { | ||
27972 | "version": "0.4.23", | ||
27973 | "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", | ||
27974 | "integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==", | ||
27975 | "requires": { | ||
27976 | "sax": ">=0.6.0", | ||
27977 | "xmlbuilder": "~11.0.0" | ||
27978 | } | ||
27979 | }, | ||
27980 | "xmlbuilder": { | ||
27981 | "version": "11.0.1", | ||
27982 | "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", | ||
27983 | "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==" | ||
27984 | }, | ||
27876 | "xmlhttprequest": { | 27985 | "xmlhttprequest": { |
27877 | "version": "1.8.0", | 27986 | "version": "1.8.0", |
27878 | "resolved": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz", | 27987 | "resolved": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz", |
diff --git a/package.json b/package.json index 281eb0712..47cd15f05 100644 --- a/package.json +++ b/package.json | |||
@@ -68,6 +68,7 @@ | |||
68 | "cld3-asm": "1.0.1", | 68 | "cld3-asm": "1.0.1", |
69 | "css": "2.2.4", | 69 | "css": "2.2.4", |
70 | "darkreader": "4.7.15", | 70 | "darkreader": "4.7.15", |
71 | "dbus-next": "0.8.2", | ||
71 | "du": "^0.1.0", | 72 | "du": "^0.1.0", |
72 | "electron-dl": "1.14.0", | 73 | "electron-dl": "1.14.0", |
73 | "electron-fetch": "1.4.0", | 74 | "electron-fetch": "1.4.0", |
diff --git a/src/index.js b/src/index.js index 484191f2e..9dfbb4d8f 100644 --- a/src/index.js +++ b/src/index.js | |||
@@ -35,6 +35,7 @@ import { | |||
35 | import { mainIpcHandler as basicAuthHandler } from './features/basicAuth'; | 35 | import { mainIpcHandler as basicAuthHandler } from './features/basicAuth'; |
36 | import ipcApi from './electron/ipc-api'; | 36 | import ipcApi from './electron/ipc-api'; |
37 | import Tray from './lib/Tray'; | 37 | import Tray from './lib/Tray'; |
38 | import DBus from './lib/DBus'; | ||
38 | import Settings from './electron/Settings'; | 39 | import Settings from './electron/Settings'; |
39 | import handleDeepLink from './electron/deepLinking'; | 40 | import handleDeepLink from './electron/deepLinking'; |
40 | import { isPositionValid } from './electron/windowUtils'; | 41 | import { isPositionValid } from './electron/windowUtils'; |
@@ -213,6 +214,9 @@ const createWindow = () => { | |||
213 | // Initialize System Tray | 214 | // Initialize System Tray |
214 | const trayIcon = new Tray(); | 215 | const trayIcon = new Tray(); |
215 | 216 | ||
217 | // Initialize DBus interface | ||
218 | const dbus = new DBus(trayIcon); | ||
219 | |||
216 | // Initialize ipcApi | 220 | // Initialize ipcApi |
217 | ipcApi({ | 221 | ipcApi({ |
218 | mainWindow, | 222 | mainWindow, |
@@ -223,6 +227,9 @@ const createWindow = () => { | |||
223 | trayIcon, | 227 | trayIcon, |
224 | }); | 228 | }); |
225 | 229 | ||
230 | // Connect to the DBus after ipcApi took care of the System Tray | ||
231 | dbus.start(); | ||
232 | |||
226 | // Manage Window State | 233 | // Manage Window State |
227 | mainWindowState.manage(mainWindow); | 234 | mainWindowState.manage(mainWindow); |
228 | 235 | ||
@@ -265,6 +272,7 @@ const createWindow = () => { | |||
265 | mainWindow.hide(); | 272 | mainWindow.hide(); |
266 | } | 273 | } |
267 | } else { | 274 | } else { |
275 | dbus.stop(); | ||
268 | app.quit(); | 276 | app.quit(); |
269 | } | 277 | } |
270 | }); | 278 | }); |
diff --git a/src/lib/DBus.js b/src/lib/DBus.js new file mode 100644 index 000000000..957912efa --- /dev/null +++ b/src/lib/DBus.js | |||
@@ -0,0 +1,49 @@ | |||
1 | import { | ||
2 | sessionBus, | ||
3 | } from 'dbus-next'; | ||
4 | import { | ||
5 | isLinux, | ||
6 | } from '../environment'; | ||
7 | |||
8 | export default class DBus { | ||
9 | bus = null; | ||
10 | |||
11 | constructor(trayIcon) { | ||
12 | this.trayIcon = trayIcon; | ||
13 | } | ||
14 | |||
15 | start() { | ||
16 | if (!isLinux || this.bus) return; | ||
17 | |||
18 | try { | ||
19 | this.bus = sessionBus(); | ||
20 | } catch { | ||
21 | // Error connecting to the bus. | ||
22 | return; | ||
23 | } | ||
24 | |||
25 | // HACK Hook onto the MessageBus to track StatusNotifierWatchers | ||
26 | this.bus._addMatch("type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',path='/org/freedesktop/DBus',member='NameOwnerChanged'"); | ||
27 | const mangled = JSON.stringify({ | ||
28 | path: '/org/freedesktop/DBus', | ||
29 | interface: 'org.freedesktop.DBus', | ||
30 | member: 'NameOwnerChanged', | ||
31 | }); | ||
32 | this.bus._signals.on(mangled, (msg) => { | ||
33 | const [name, oldOwner, newOwner] = msg.body; | ||
34 | if (name === 'org.kde.StatusNotifierWatcher' && oldOwner !== newOwner && newOwner !== '') { | ||
35 | // Leave ample time for the StatusNotifierWatcher to be initialized | ||
36 | setTimeout(() => { | ||
37 | this.trayIcon.recreateIfVisible(); | ||
38 | }, 400); | ||
39 | } | ||
40 | }); | ||
41 | } | ||
42 | |||
43 | stop() { | ||
44 | if (!this.bus) return; | ||
45 | |||
46 | this.bus.disconnect(); | ||
47 | this.bus = null; | ||
48 | } | ||
49 | } | ||
diff --git a/src/lib/Tray.js b/src/lib/Tray.js index 0afb6289b..c6d9db004 100644 --- a/src/lib/Tray.js +++ b/src/lib/Tray.js | |||
@@ -22,6 +22,8 @@ export default class TrayIcon { | |||
22 | 22 | ||
23 | trayMenu = null; | 23 | trayMenu = null; |
24 | 24 | ||
25 | visible = false; | ||
26 | |||
25 | trayMenuTemplate = [ | 27 | trayMenuTemplate = [ |
26 | { | 28 | { |
27 | label: 'Show Ferdi', | 29 | label: 'Show Ferdi', |
@@ -50,7 +52,19 @@ export default class TrayIcon { | |||
50 | }, | 52 | }, |
51 | ]; | 53 | ]; |
52 | 54 | ||
55 | constructor() { | ||
56 | ipcMain.on('initialAppSettings', (event, appSettings) => { | ||
57 | this._updateTrayMenu(appSettings); | ||
58 | }); | ||
59 | |||
60 | ipcMain.on('updateAppSettings', (event, appSettings) => { | ||
61 | this._updateTrayMenu(appSettings); | ||
62 | }); | ||
63 | } | ||
64 | |||
53 | _updateTrayMenu(appSettings) { | 65 | _updateTrayMenu(appSettings) { |
66 | if (!this.trayIcon) return; | ||
67 | |||
54 | if (appSettings.type === 'app') { | 68 | if (appSettings.type === 'app') { |
55 | const { isAppMuted } = appSettings.data; | 69 | const { isAppMuted } = appSettings.data; |
56 | this.trayMenuTemplate[1].label = isAppMuted ? 'Enable Notifications && Audio' : 'Disable Notifications && Audio'; | 70 | this.trayMenuTemplate[1].label = isAppMuted ? 'Enable Notifications && Audio' : 'Disable Notifications && Audio'; |
@@ -62,6 +76,11 @@ export default class TrayIcon { | |||
62 | } | 76 | } |
63 | 77 | ||
64 | show() { | 78 | show() { |
79 | this.visible = true; | ||
80 | this._show(); | ||
81 | } | ||
82 | |||
83 | _show() { | ||
65 | if (this.trayIcon) return; | 84 | if (this.trayIcon) return; |
66 | 85 | ||
67 | this.trayIcon = new Tray(this._getAsset('tray', INDICATOR_TRAY_PLAIN)); | 86 | this.trayIcon = new Tray(this._getAsset('tray', INDICATOR_TRAY_PLAIN)); |
@@ -73,14 +92,6 @@ export default class TrayIcon { | |||
73 | this.trayIcon.setContextMenu(this.trayMenu); | 92 | this.trayIcon.setContextMenu(this.trayMenu); |
74 | } | 93 | } |
75 | 94 | ||
76 | ipcMain.on('initialAppSettings', (event, appSettings) => { | ||
77 | this._updateTrayMenu(appSettings); | ||
78 | }); | ||
79 | |||
80 | ipcMain.on('updateAppSettings', (event, appSettings) => { | ||
81 | this._updateTrayMenu(appSettings); | ||
82 | }); | ||
83 | |||
84 | this.trayIcon.on('click', () => { | 95 | this.trayIcon.on('click', () => { |
85 | if (app.mainWindow.isMinimized()) { | 96 | if (app.mainWindow.isMinimized()) { |
86 | app.mainWindow.restore(); | 97 | app.mainWindow.restore(); |
@@ -106,6 +117,11 @@ export default class TrayIcon { | |||
106 | } | 117 | } |
107 | 118 | ||
108 | hide() { | 119 | hide() { |
120 | this.visible = false; | ||
121 | this._hide(); | ||
122 | } | ||
123 | |||
124 | _hide() { | ||
109 | if (!this.trayIcon) return; | 125 | if (!this.trayIcon) return; |
110 | 126 | ||
111 | this.trayIcon.destroy(); | 127 | this.trayIcon.destroy(); |
@@ -117,6 +133,17 @@ export default class TrayIcon { | |||
117 | } | 133 | } |
118 | } | 134 | } |
119 | 135 | ||
136 | recreateIfVisible() { | ||
137 | if (this.visible) { | ||
138 | this._hide(); | ||
139 | setTimeout(() => { | ||
140 | if (this.visible) { | ||
141 | this._show(); | ||
142 | } | ||
143 | }, 100); | ||
144 | } | ||
145 | } | ||
146 | |||
120 | setIndicator(indicator) { | 147 | setIndicator(indicator) { |
121 | this.indicator = indicator; | 148 | this.indicator = indicator; |
122 | this._refreshIcon(); | 149 | this._refreshIcon(); |