throttle global hotkey - fixes #4371

This commit is contained in:
Eugene Pankov
2021-08-07 10:25:49 +02:00
parent c91707e94f
commit 25fdba7104

View File

@@ -3,6 +3,7 @@ import * as promiseIpc from 'electron-promise-ipc'
import * as remote from '@electron/remote/main'
import * as path from 'path'
import * as fs from 'fs'
import { Subject, throttleTime } from 'rxjs'
import { loadConfig } from './config'
import { Window, WindowOptions } from './window'
@@ -19,6 +20,7 @@ export class Application {
private tray?: Tray
private ptyManager = new PTYManager()
private windows: Window[] = []
private globalHotkey$ = new Subject<void>()
userPluginsPath: string
constructor () {
@@ -33,12 +35,14 @@ export class Application {
ipcMain.on('app:register-global-hotkey', (_event, specs) => {
globalShortcut.unregisterAll()
for (const spec of specs) {
globalShortcut.register(spec, () => {
this.onGlobalHotkey()
})
globalShortcut.register(spec, () => this.globalHotkey$.next())
}
})
this.globalHotkey$.pipe(throttleTime(100)).subscribe(() => {
this.onGlobalHotkey()
})
;(promiseIpc as any).on('plugin-manager:install', (name, version) => {
return pluginManager.install(this.userPluginsPath, name, version)
})