Skip to content

Commit

Permalink
create touchbar only if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jun 3, 2020
1 parent d172cce commit 3913b4f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
6 changes: 3 additions & 3 deletions lib/tool-bar-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class ToolBarManager {
addItem (options) {
const item = new ToolBarItem(options, this.group);
this.toolBarView.addItem(item);
// this.touchBarManager.addItem(item); // TODO
// this.touchBarManager?.addItem(item); // TODO
return item;
}

Expand All @@ -38,7 +38,7 @@ export class ToolBarManager {
addButton (options) {
const button = new ToolBarButtonView(options, this.group);
this.toolBarView.addItem(button);
this.touchBarManager.addButton(button);
this.touchBarManager?.addButton(button);
return button;
}

Expand All @@ -61,7 +61,7 @@ export class ToolBarManager {
this.toolBarView.items
.filter(item => item.group === this.group)
.forEach(item => this.toolBarView.removeItem(item));
this.touchBarManager.removeGroup(this.group);
this.touchBarManager?.removeGroup(this.group);
}
}

Expand Down
14 changes: 10 additions & 4 deletions lib/tool-bar.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import {ToolBarManager} from './tool-bar-manager';
import {ToolBarView} from './tool-bar-view';
import {TouchBarManager} from './touch-bar-manager';

let toolBarView = null;
let touchBarManager = null;

export let useGutter = false;

export function activate() {
export async function activate() {
toolBarView = new ToolBarView();
touchBarManager = new TouchBarManager();
useGutter = atom.config.get('tool-bar.useGutter')
await useTouchBar();
useGutter = atom.config.get('tool-bar.useGutter');
}

async function useTouchBar() {
if (atom.config.get('tool-bar.useTouchBar') && process.platform === 'darwin') {
let TouchBarManager = await import('./touch-bar-manager');
touchBarManager = new TouchBarManager();
}
}

export function deactivate() {
Expand Down
9 changes: 1 addition & 8 deletions lib/touch-bar-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export class TouchBarManager {
}

addButton (button) {
if (!this._useTouchBar()) return;
if (this.buttons.length >= 7) return;

this._renderButton(button).then(icon => {
Expand All @@ -33,8 +32,6 @@ export class TouchBarManager {
}

update () {
if (!this._useTouchBar()) return;

if (this._updateDebounce) clearTimeout(this._updateDebounce);
this._updateDebounce = setTimeout(() => this._setTouchBar(), 100);
}
Expand All @@ -43,11 +40,7 @@ export class TouchBarManager {
this.buttons = this.buttons.filter(button => button.group !== group);
this.update();
}

_useTouchBar () {
return process.platform === 'darwin' && atom.config.get('tool-bar.useTouchBar');
}


_renderButton (button) {
return document.fonts.ready.then(() => {
if (!(button.element instanceof HTMLElement)) return;
Expand Down

0 comments on commit 3913b4f

Please sign in to comment.