-
Notifications
You must be signed in to change notification settings - Fork 5
/
globalShortcut.js
53 lines (40 loc) · 1.29 KB
/
globalShortcut.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const {clipboard, remote, globalShortcut, ipcRenderer} = require('electron');
const jquery = require('jquery');
const settings = require('electron-settings')
const input = document.querySelector('input');
const reset = document.querySelector("button[type='reset']");
const submit = document.querySelector("button[type='submit']");
remote.getCurrentWindow().on('show', async function() {
input.focus()
input.value = await settings.get('globalShortcut')
});
let keys = []
document.body.addEventListener('keyup', function(e) {
//focusable.push(input);
if (e.key === 'Enter') {
} else if (e.key === 'Escape') {
input.value = ''
remote.getCurrentWindow().close();
} else {
input.focus();
//input.value = ''
if (keys.indexOf(e.key) === -1) {
keys.push(e.key)
}
input.value = keys.join('+').replace("Control", "CmdOrCtrl").replace("Arrow","")
return true
}
});
reset.addEventListener('click', () => {
input.value = ''
keys = []
input.focus()
});
submit.addEventListener('click', async () => {
//input.value = ''
//console.log(input.value)
await settings.set('globalShortcut', input.value)
input.focus()
remote.getCurrentWindow().close()
ipcRenderer.send('app-exit')
});