aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/TouchBar.ts
diff options
context:
space:
mode:
authorLibravatar Markus Hatvan <markus_hatvan@aon.at>2021-10-02 09:24:32 +0200
committerLibravatar GitHub <noreply@github.com>2021-10-02 09:24:32 +0200
commitbfe8847d72cd0893230f2e654242658214943e61 (patch)
tree3384b02ebad7a74cbb106ddd95546e0e24ff0bb8 /src/lib/TouchBar.ts
parentfix: Fix navigation shortcut accelerator for non-macos (fixes #1172) (#2012) (diff)
downloadferdium-app-bfe8847d72cd0893230f2e654242658214943e61.tar.gz
ferdium-app-bfe8847d72cd0893230f2e654242658214943e61.tar.zst
ferdium-app-bfe8847d72cd0893230f2e654242658214943e61.zip
chore: convert various files from JS to TS (#2010)
Diffstat (limited to 'src/lib/TouchBar.ts')
-rw-r--r--src/lib/TouchBar.ts62
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 @@
1import semver from 'semver';
2import { TouchBar, getCurrentWindow } from '@electron/remote';
3import { autorun } from 'mobx';
4
5import { isMac, osRelease } from '../environment';
6
7export 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}