From e3e01558b21946115bbb12f8d697e9e195ccbbf3 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Sat, 25 Sep 2021 18:11:35 +0200 Subject: [PATCH] less sync ipc --- app/lib/window.ts | 12 ++++++++++++ tabby-electron/src/index.ts | 14 +++++++------- tabby-electron/src/services/hostWindow.service.ts | 12 ++++++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/app/lib/window.ts b/app/lib/window.ts index 71da851d..2cc3c9c4 100644 --- a/app/lib/window.ts +++ b/app/lib/window.ts @@ -398,6 +398,18 @@ export class Window { } this.window.on('move', onBoundsChange) this.window.on('resize', onBoundsChange) + + ipcMain.on('window-set-traffic-light-position', (_event, x, y) => { + this.window.setTrafficLightPosition({ x, y }) + }) + + ipcMain.on('window-set-opacity', (_event, opacity) => { + this.window.setOpacity(opacity) + }) + + ipcMain.on('window-set-progress-bar', (_event, value) => { + this.window.setProgressBar(value, { mode: value < 0 ? 'none' : 'normal' }) + }) } private destroy () { diff --git a/tabby-electron/src/index.ts b/tabby-electron/src/index.ts index e13704f0..fc0d0a2c 100644 --- a/tabby-electron/src/index.ts +++ b/tabby-electron/src/index.ts @@ -59,10 +59,10 @@ export default class ElectronModule { themeService.themeChanged$.subscribe(theme => { if (hostApp.platform === Platform.macOS) { - hostWindow.getWindow().setTrafficLightPosition({ - x: theme.macOSWindowButtonsInsetX ?? 14, - y: theme.macOSWindowButtonsInsetY ?? 11, - }) + hostWindow.setTrafficLightPosition( + theme.macOSWindowButtonsInsetX ?? 14, + theme.macOSWindowButtonsInsetY ?? 11, + ) } }) @@ -73,9 +73,9 @@ export default class ElectronModule { return } if (progress !== null) { - hostWindow.getWindow().setProgressBar(progress / 100.0, { mode: 'normal' }) + hostWindow.setProgressBar(progress / 100.0) } else { - hostWindow.getWindow().setProgressBar(-1, { mode: 'none' }) + hostWindow.setProgressBar(-1) } lastProgress = progress }) @@ -116,7 +116,7 @@ export default class ElectronModule { document.body.classList.toggle('vibrant', this.config.store.appearance.vibrancy) this.electron.ipcRenderer.send('window-set-vibrancy', this.config.store.appearance.vibrancy, vibrancyType) - this.hostWindow.getWindow().setOpacity(this.config.store.appearance.opacity) + this.hostWindow.setOpacity(this.config.store.appearance.opacity) } } diff --git a/tabby-electron/src/services/hostWindow.service.ts b/tabby-electron/src/services/hostWindow.service.ts index 8c830990..cf23b37f 100644 --- a/tabby-electron/src/services/hostWindow.service.ts +++ b/tabby-electron/src/services/hostWindow.service.ts @@ -97,6 +97,18 @@ export class ElectronHostWindow extends HostWindowService { this.getWindow().setTouchBar(touchBar) } + setTrafficLightPosition (x: number, y: number): void { + this.electron.ipcRenderer.send('window-set-traffic-light-position', x, y) + } + + setOpacity (opacity: number): void { + this.electron.ipcRenderer.send('window-set-opacity', opacity) + } + + setProgressBar (value: number): void { + this.electron.ipcRenderer.send('window-set-progress-bar', value) + } + bringToFront (): void { this.electron.ipcRenderer.send('window-bring-to-front') } -- GitLab