From 58cda9cc7fb79ca9df6746de7f9662bc08dc156a Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 13 Oct 2017 12:29:40 +0200 Subject: initial commit --- src/lib/TouchBar.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/lib/TouchBar.js (limited to 'src/lib/TouchBar.js') 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 @@ +import { remote } from 'electron'; +import { autorun } from 'mobx'; + +import { isMac } from '../environment'; + +export default class FranzTouchBar { + constructor(stores, actions) { + this.stores = stores; + this.actions = actions; + + this._initializeReactions(); + } + + _initializeReactions() { + this.build = autorun(this._build.bind(this)); + } + + _build() { + const currentWindow = remote.getCurrentWindow(); + + if (isMac && this.stores.user.isLoggedIn) { + const { TouchBar } = remote; + const { TouchBarButton, TouchBarSpacer } = TouchBar; + + const buttons = []; + this.stores.services.enabled.forEach(((service) => { + buttons.push(new TouchBarButton({ + label: `${service.name}${service.unreadDirectMessageCount > 0 + ? ' 🔴' : ''} ${service.unreadDirectMessageCount === 0 + && service.unreadIndirectMessageCount > 0 + ? ' ⚪️' : ''}`, + backgroundColor: service.isActive ? '#3498DB' : null, + click: () => { + this.actions.service.setActive({ serviceId: service.id }); + }, + }), new TouchBarSpacer({ size: 'small' })); + })); + + const touchBar = new TouchBar(buttons); + currentWindow.setTouchBar(touchBar); + } else { + currentWindow.setTouchBar(null); + } + } +} -- cgit v1.2.3-70-g09d2