forked from nathanbirrell/overcast-macos
-
Notifications
You must be signed in to change notification settings - Fork 1
/
global_shortcuts.js
39 lines (35 loc) · 1.13 KB
/
global_shortcuts.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
const { globalShortcut } = require('electron')
const Config = require('electron-config')
const config = new Config()
toggleMediaKeySettings = (window) => {
let currentlyOn = config.get('mediaKeysOn')
if (currentlyOn) {
config.set('mediaKeysOn', false)
unregisterGlobalShortcuts()
} else {
config.set('mediaKeysOn', true)
registerGlobalShortcuts(window)
}
}
registerGlobalShortcuts = (mainWindow) => {
if (!config.get('mediaKeysOn')) {
return false;
}
// Global keyboard shortcuts
globalShortcut.register('MediaPlayPause', () => {
mainWindow.webContents.send('playback', 'playpause')
})
globalShortcut.register('MediaNextTrack', () => {
mainWindow.webContents.send('playback', 'next')
})
globalShortcut.register('MediaPreviousTrack', () => {
mainWindow.webContents.send('playback', 'previous')
})
}
unregisterGlobalShortcuts = () => {
globalShortcut.unregister('MediaPlayPause')
globalShortcut.unregister('MediaNextTrack')
globalShortcut.unregister('MediaPreviousTrack')
}
exports.toggleMediaKeySettings = toggleMediaKeySettings
exports.registerGlobalShortcuts = registerGlobalShortcuts