-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.js
35 lines (30 loc) · 1.11 KB
/
window.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
const ipcRenderer = require('electron').ipcRenderer
const webview = document.getElementById('sp-webview');
function sendPlayPause() {
webview.executeJavaScript('document.querySelector(\'.player-controls__buttons button[data-testid=\"control-button-play\"]\').click()').catch(() => {
webview.executeJavaScript('document.querySelector(\'.player-controls__buttons button[data-testid=\"control-button-pause\"]\').click()')
})
}
function sendNextTrack() {
webview.executeJavaScript('document.querySelector(\'.player-controls__buttons button[data-testid=\"control-button-skip-forward\"]\').click()')
}
function sendPreviousTrack() {
webview.executeJavaScript('document.querySelectorAll(\'.player-controls__buttons button\')[1].click()')
}
ipcRenderer.on('shortcut', (event, arg) => {
let cmd = arg[0];
switch (cmd) {
case 'MediaPlayPause': {
sendPlayPause();
break;
}
case 'MediaNextTrack': {
sendNextTrack();
break;
}
case 'MediaPreviousTrack': {
sendPreviousTrack();
break;
}
}
});