fixed window toggling with multiple windows (fixes #619)

This commit is contained in:
Eugene Pankov
2020-04-19 11:47:31 +02:00
parent 11767f7d27
commit f58cab0820
8 changed files with 95 additions and 68 deletions

View File

@@ -1,4 +1,4 @@
import { app, ipcMain, Menu, Tray, shell } from 'electron'
import { app, ipcMain, Menu, Tray, shell, globalShortcut } from 'electron'
// eslint-disable-next-line no-duplicate-imports
import * as electron from 'electron'
import { loadConfig } from './config'
@@ -9,8 +9,17 @@ export class Application {
private windows: Window[] = []
constructor () {
ipcMain.on('app:config-change', () => {
this.broadcast('host:config-change')
ipcMain.on('app:config-change', (_event, config) => {
this.broadcast('host:config-change', config)
})
ipcMain.on('app:register-global-hotkey', (_event, specs) => {
globalShortcut.unregisterAll()
for (let spec of specs) {
globalShortcut.register(spec, () => {
this.onGlobalHotkey()
})
}
})
const configData = loadConfig()
@@ -45,6 +54,9 @@ export class Application {
this.enableTray()
}
})
window.closed$.subscribe(() => {
this.windows = this.windows.filter(x => x !== window)
})
if (process.platform === 'darwin') {
this.setupMenu()
}
@@ -52,6 +64,24 @@ export class Application {
return window
}
onGlobalHotkey () {
if (this.windows.some(x => x.isFocused())) {
for (let window of this.windows) {
window.hide()
}
} else {
for (let window of this.windows) {
window.present()
}
}
}
presentAllWindows() {
for (let window of this.windows) {
window.present()
}
}
broadcast (event: string, ...args): void {
for (const window of this.windows) {
window.send(event, ...args)