-
Notifications
You must be signed in to change notification settings - Fork 7
/
renderer.js
44 lines (38 loc) · 1.34 KB
/
renderer.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
'use strict';
const {globalShortcut, dialog} = require('electron').remote;
const currentWindow = require('electron').remote.getCurrentWindow();
const currentWebContents = currentWindow.webContents;
const init = () => {
if (window.location.host !== 'music.yandex.ru') {
return;
}
var ret;
ret = globalShortcut.register('MediaPlayPause', () => {
externalAPI.togglePause();
});
if (!ret) {
dialog.showErrorBox('Cant bind global shortcut', 'Cant bind MediaPlayPause. Closing tab.\nPossible second opened tab?');
currentWindow.close();
return;
}
ret = globalShortcut.register('MediaNextTrack', () => {
externalAPI.next();
});
if (!ret) {
dialog.showErrorBox('Cant bind global shortcut', 'Cant bind MediaNextTrack. Closing tab. \nPossible second opened tab?');
currentWindow.close();
return;
}
ret = globalShortcut.register('MediaPreviousTrack', () => {
if (externalAPI.getProgress().position >= 5) {
externalAPI.setPosition(0);
} else {
externalAPI.prev();
}
});
if (!ret) {
dialog.showErrorBox('Cant bind global shortcut', 'Cant bind MediaPreviousTrack. Closing tab. \nPossible second opened tab?');
currentWindow.close();
}
};
currentWebContents.on('did-finish-load', init);