diff options
author | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
---|---|---|
committer | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
commit | 58cda9cc7fb79ca9df6746de7f9662bc08dc156a (patch) | |
tree | 1211600c2a5d3b5f81c435c6896618111a611720 /src/lib/TouchBar.js | |
download | ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.gz ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.zst ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.zip |
initial commit
Diffstat (limited to 'src/lib/TouchBar.js')
-rw-r--r-- | src/lib/TouchBar.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/lib/TouchBar.js b/src/lib/TouchBar.js new file mode 100644 index 000000000..ad7849b8e --- /dev/null +++ b/src/lib/TouchBar.js | |||
@@ -0,0 +1,45 @@ | |||
1 | import { remote } from 'electron'; | ||
2 | import { autorun } from 'mobx'; | ||
3 | |||
4 | import { isMac } from '../environment'; | ||
5 | |||
6 | export default class FranzTouchBar { | ||
7 | constructor(stores, actions) { | ||
8 | this.stores = stores; | ||
9 | this.actions = actions; | ||
10 | |||
11 | this._initializeReactions(); | ||
12 | } | ||
13 | |||
14 | _initializeReactions() { | ||
15 | this.build = autorun(this._build.bind(this)); | ||
16 | } | ||
17 | |||
18 | _build() { | ||
19 | const currentWindow = remote.getCurrentWindow(); | ||
20 | |||
21 | if (isMac && this.stores.user.isLoggedIn) { | ||
22 | const { TouchBar } = remote; | ||
23 | const { TouchBarButton, TouchBarSpacer } = TouchBar; | ||
24 | |||
25 | const buttons = []; | ||
26 | this.stores.services.enabled.forEach(((service) => { | ||
27 | buttons.push(new TouchBarButton({ | ||
28 | label: `${service.name}${service.unreadDirectMessageCount > 0 | ||
29 | ? ' 🔴' : ''} ${service.unreadDirectMessageCount === 0 | ||
30 | && service.unreadIndirectMessageCount > 0 | ||
31 | ? ' ⚪️' : ''}`, | ||
32 | backgroundColor: service.isActive ? '#3498DB' : null, | ||
33 | click: () => { | ||
34 | this.actions.service.setActive({ serviceId: service.id }); | ||
35 | }, | ||
36 | }), new TouchBarSpacer({ size: 'small' })); | ||
37 | })); | ||
38 | |||
39 | const touchBar = new TouchBar(buttons); | ||
40 | currentWindow.setTouchBar(touchBar); | ||
41 | } else { | ||
42 | currentWindow.setTouchBar(null); | ||
43 | } | ||
44 | } | ||
45 | } | ||