From bfe8847d72cd0893230f2e654242658214943e61 Mon Sep 17 00:00:00 2001 From: Markus Hatvan Date: Sat, 2 Oct 2021 09:24:32 +0200 Subject: chore: convert various files from JS to TS (#2010) --- src/lib/TouchBar.ts | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/lib/TouchBar.ts (limited to 'src/lib/TouchBar.ts') 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 @@ +import semver from 'semver'; +import { TouchBar, getCurrentWindow } from '@electron/remote'; +import { autorun } from 'mobx'; + +import { isMac, osRelease } from '../environment'; + +export default class FranzTouchBar { + stores: any; + + actions: any; + + build: any; + + constructor(stores: any, actions: any) { + this.stores = stores; + this.actions = actions; + + // Temporary fix for https://github.com/electron/electron/issues/10442 + // TODO: remove when we upgrade to electron 1.8.2 or later + try { + if (isMac && semver.gt(osRelease, '16.6.0')) { + this.build = autorun(this._build.bind(this)); + } + } catch (error) { + console.error(error); + } + } + + _build() { + const currentWindow = getCurrentWindow(); + + if (this.stores.user.isLoggedIn) { + const { TouchBarButton, TouchBarSpacer } = TouchBar; + + const buttons: any[] = []; + for (const service of this.stores.services.allDisplayed) { + buttons.push( + new TouchBarButton({ + label: `${service.name}${ + service.unreadDirectMessageCount > 0 ? ' 🔴' : '' + } ${ + service.unreadDirectMessageCount === 0 && + service.unreadIndirectMessageCount > 0 + ? ' ⚪️' + : '' + }`, + backgroundColor: service.isActive && '#3498DB', + click: () => { + this.actions.service.setActive({ serviceId: service.id }); + }, + }), + new TouchBarSpacer({ size: 'small' }), + ); + } + + const touchBar = new TouchBar({ items: buttons }); + currentWindow.setTouchBar(touchBar); + } else { + currentWindow.setTouchBar(null); + } + } +} -- cgit v1.2.3-54-g00ecf