fixed global shortcut behaviour (fixes #823)

This commit is contained in:
Eugene Pankov
2019-06-08 22:10:39 +02:00
parent 596d75adc1
commit cf83bd3798
2 changed files with 12 additions and 9 deletions

View File

@@ -104,7 +104,11 @@ export class HotkeysService {
item = (typeof item === 'string') ? [item] : item item = (typeof item === 'string') ? [item] : item
try { try {
this.electron.globalShortcut.register(item[0].replace(/-/g, '+'), () => { let electronKeySpec = item[0]
electronKeySpec = electronKeySpec.replace('⌘', 'Command')
electronKeySpec = electronKeySpec.replace('⌥', 'Alt')
electronKeySpec = electronKeySpec.replace(/-/g, '+')
this.electron.globalShortcut.register(electronKeySpec, () => {
this.globalHotkey.emit() this.globalHotkey.emit()
}) })
} catch (err) { } catch (err) {
@@ -131,7 +135,7 @@ export class HotkeysService {
value = [value] value = [value]
} }
if (value) { if (value) {
value = value.map((item) => (typeof item === 'string') ? [item] : item) value = value.map(item => (typeof item === 'string') ? [item] : item)
keys[key] = value keys[key] = value
} }
} }

View File

@@ -45,13 +45,12 @@ export function stringifyKeySequence (events: NativeKeyEvent[]): string[] {
// TODO make this optional? // TODO make this optional?
continue continue
} }
if (event.key === ' ') {
itemKeys.push('Space') let key = (event as any).code
} else if (event.key.length === 1) { key = key.replace('Key', '')
itemKeys.push(event.key.toUpperCase()) key = key.replace('Arrow', '')
} else { key = key.replace('Digit', '')
itemKeys.push(event.key) itemKeys.push(key)
}
items.push(itemKeys.join('-')) items.push(itemKeys.join('-'))
} }
} }