From 21cb452d62563a1779a2d30c7959c6bc802681dd Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Tue, 31 Dec 2019 23:20:07 +0100 Subject: [PATCH] fixed terminal not getting focus when switching windows (fixes #692) --- app/lib/window.ts | 4 ++++ terminus-core/src/services/app.service.ts | 4 ++++ terminus-core/src/services/hostApp.service.ts | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/app/lib/window.ts b/app/lib/window.ts index 55e26330..559ea0c4 100644 --- a/app/lib/window.ts +++ b/app/lib/window.ts @@ -202,6 +202,10 @@ export class Window { } }) + this.window.on('focus', () => { + this.send('host:window-focused') + }) + ipcMain.on('window-focus', event => { if (!this.window || event.sender !== this.window.webContents) { return diff --git a/terminus-core/src/services/app.service.ts b/terminus-core/src/services/app.service.ts index 3d05a045..d4bed1a0 100644 --- a/terminus-core/src/services/app.service.ts +++ b/terminus-core/src/services/app.service.ts @@ -83,6 +83,10 @@ export class AppService { this.startTabStorage() } } + + hostApp.windowFocused$.subscribe(() => { + this._activeTab?.emitFocused() + }) } startTabStorage () { diff --git a/terminus-core/src/services/hostApp.service.ts b/terminus-core/src/services/hostApp.service.ts index 218bc2af..7fd9269c 100644 --- a/terminus-core/src/services/hostApp.service.ts +++ b/terminus-core/src/services/hostApp.service.ts @@ -39,6 +39,7 @@ export class HostAppService { private configChangeBroadcast = new Subject() private windowCloseRequest = new Subject() private windowMoved = new Subject() + private windowFocused = new Subject() private displayMetricsChanged = new Subject() private logger: Logger private windowId: number @@ -85,6 +86,8 @@ export class HostAppService { get windowMoved$ (): Observable { return this.windowMoved } + get windowFocused$ (): Observable { return this.windowFocused } + get displayMetricsChanged$ (): Observable { return this.displayMetricsChanged } private constructor ( @@ -128,6 +131,10 @@ export class HostAppService { this.zone.run(() => this.windowMoved.next()) }) + electron.ipcRenderer.on('host:window-focused', () => { + this.zone.run(() => this.windowFocused.next()) + }) + electron.ipcRenderer.on('host:display-metrics-changed', () => { this.zone.run(() => this.displayMetricsChanged.next()) })