diff options
Diffstat (limited to 'src/lib/TouchBar.ts')
-rw-r--r-- | src/lib/TouchBar.ts | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/lib/TouchBar.ts b/src/lib/TouchBar.ts new file mode 100644 index 000000000..417e20411 --- /dev/null +++ b/src/lib/TouchBar.ts | |||
@@ -0,0 +1,62 @@ | |||
1 | import semver from 'semver'; | ||
2 | import { TouchBar, getCurrentWindow } from '@electron/remote'; | ||
3 | import { autorun } from 'mobx'; | ||
4 | |||
5 | import { isMac, osRelease } from '../environment'; | ||
6 | |||
7 | export default class FranzTouchBar { | ||
8 | stores: any; | ||
9 | |||
10 | actions: any; | ||
11 | |||
12 | build: any; | ||
13 | |||
14 | constructor(stores: any, actions: any) { | ||
15 | this.stores = stores; | ||
16 | this.actions = actions; | ||
17 | |||
18 | // Temporary fix for https://github.com/electron/electron/issues/10442 | ||
19 | // TODO: remove when we upgrade to electron 1.8.2 or later | ||
20 | try { | ||
21 | if (isMac && semver.gt(osRelease, '16.6.0')) { | ||
22 | this.build = autorun(this._build.bind(this)); | ||
23 | } | ||
24 | } catch (error) { | ||
25 | console.error(error); | ||
26 | } | ||
27 | } | ||
28 | |||
29 | _build() { | ||
30 | const currentWindow = getCurrentWindow(); | ||
31 | |||
32 | if (this.stores.user.isLoggedIn) { | ||
33 | const { TouchBarButton, TouchBarSpacer } = TouchBar; | ||
34 | |||
35 | const buttons: any[] = []; | ||
36 | for (const service of this.stores.services.allDisplayed) { | ||
37 | buttons.push( | ||
38 | new TouchBarButton({ | ||
39 | label: `${service.name}${ | ||
40 | service.unreadDirectMessageCount > 0 ? ' 🔴' : '' | ||
41 | } ${ | ||
42 | service.unreadDirectMessageCount === 0 && | ||
43 | service.unreadIndirectMessageCount > 0 | ||
44 | ? ' ⚪️' | ||
45 | : '' | ||
46 | }`, | ||
47 | backgroundColor: service.isActive && '#3498DB', | ||
48 | click: () => { | ||
49 | this.actions.service.setActive({ serviceId: service.id }); | ||
50 | }, | ||
51 | }), | ||
52 | new TouchBarSpacer({ size: 'small' }), | ||
53 | ); | ||
54 | } | ||
55 | |||
56 | const touchBar = new TouchBar({ items: buttons }); | ||
57 | currentWindow.setTouchBar(touchBar); | ||
58 | } else { | ||
59 | currentWindow.setTouchBar(null); | ||
60 | } | ||
61 | } | ||
62 | } | ||