From 6bc2d18f3c2be25949a3809cabe507023d87d138 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Thu, 20 Sep 2018 12:46:50 +0200 Subject: [PATCH] faster tab creation --- app/lib/window.ts | 6 +++++- terminus-core/src/services/hostApp.service.ts | 8 ++++++++ terminus-core/src/services/touchbar.service.ts | 2 +- terminus-terminal/src/components/terminalTab.component.ts | 8 +++----- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/lib/window.ts b/app/lib/window.ts index c0a3f1c6..9f1a0185 100644 --- a/app/lib/window.ts +++ b/app/lib/window.ts @@ -1,5 +1,5 @@ import { Subject, Observable } from 'rxjs' -import { BrowserWindow, app, ipcMain, Rectangle } from 'electron' +import { BrowserWindow, app, ipcMain, Rectangle, Menu } from 'electron' import ElectronConfig = require('electron-config') import * as yaml from 'js-yaml' import * as fs from 'fs' @@ -188,6 +188,10 @@ export class Window { ipcMain.on('window-set-title', (_event, title) => { this.window.setTitle(title) }) + + ipcMain.on('window-popup-context-menu', (_event, menuDefinition) => { + Menu.buildFromTemplate(menuDefinition).popup({ window: this.window }) + }) } private destroy () { diff --git a/terminus-core/src/services/hostApp.service.ts b/terminus-core/src/services/hostApp.service.ts index e3c77845..d59f3aa2 100644 --- a/terminus-core/src/services/hostApp.service.ts +++ b/terminus-core/src/services/hostApp.service.ts @@ -155,6 +155,14 @@ export class HostAppService { this.electron.ipcRenderer.send('window-set-title', title) } + setTouchBar (touchBar: Electron.TouchBar) { + this.getWindow().setTouchBar(touchBar) + } + + popupContextMenu (menuDefinition: Electron.MenuItemConstructorOptions[]) { + this.electron.ipcRenderer.send('window-popup-context-menu', menuDefinition) + } + broadcastConfigChange () { this.electron.ipcRenderer.send('app:config-change') } diff --git a/terminus-core/src/services/touchbar.service.ts b/terminus-core/src/services/touchbar.service.ts index ad16b5b6..b7bde349 100644 --- a/terminus-core/src/services/touchbar.service.ts +++ b/terminus-core/src/services/touchbar.service.ts @@ -54,7 +54,7 @@ export class TouchbarService { ...buttons.map(button => this.getButton(button)) ] }) - this.hostApp.getWindow().setTouchBar(touchBar) + this.hostApp.setTouchBar(touchBar) } private getButton (button: IToolbarButton): Electron.TouchBarButton { diff --git a/terminus-terminal/src/components/terminalTab.component.ts b/terminus-terminal/src/components/terminalTab.component.ts index be7051e4..f30762c8 100644 --- a/terminus-terminal/src/components/terminalTab.component.ts +++ b/terminus-terminal/src/components/terminalTab.component.ts @@ -199,7 +199,7 @@ export class TerminalTabComponent extends BaseTabComponent { } }) - this.contextMenu = this.electron.remote.Menu.buildFromTemplate([ + this.contextMenu = [ { label: 'New terminal', click: () => { @@ -227,7 +227,7 @@ export class TerminalTabComponent extends BaseTabComponent { }) } }, - ]) + ] } detachTermContainerHandlers () { @@ -249,9 +249,7 @@ export class TerminalTabComponent extends BaseTabComponent { if (event.type === 'mousedown') { if (event.which === 3) { if (this.config.store.terminal.rightClick === 'menu') { - this.contextMenu.popup({ - async: true, - }) + this.hostApp.popupContextMenu(this.contextMenu) } else if (this.config.store.terminal.rightClick === 'paste') { this.paste() }