forked from nathanbirrell/overcast-macos
-
Notifications
You must be signed in to change notification settings - Fork 1
/
renderer.js
71 lines (59 loc) · 1.87 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.
const { setCurrentUri, getCurrentUri } = require('electron').remote.require('./main.js')
const path = require('path')
const contextMenu = require('electron-context-menu')
var { ipcRenderer } = require('electron');
const webview = document.getElementById('webview')
const loader = document.querySelector('.loader')
const isLoadingClass = 'is-loading'
let loadedCurrent = false;
onload = () => {
const loadstart = () => {
loader.classList.add(isLoadingClass)
if (!loadedCurrent) {
webview.loadURL(getCurrentUri())
}
loadedCurrent = true;
}
const loadstop = () => {
loader.classList.remove(isLoadingClass)
}
webview.addEventListener('dom-ready', () => {
contextMenu({window: webview})
})
webview.addEventListener('did-start-loading', loadstart)
webview.addEventListener('did-stop-loading', loadstop)
webview.addEventListener('did-navigate-in-page', function (event) {
setCurrentUri(webview.getURL());
})
}
// Listeners (for events from the main process)
ipcRenderer.on('navigate', function(event, direction){
switch (direction) {
case 'back':
webview.getWebContents().goBack()
break;
case 'forward':
webview.getWebContents().goForward()
break;
default:
break;
}
});
ipcRenderer.on('playback', function(event, action){
switch (action) {
case 'playpause':
webview.executeJavaScript("document.getElementById('playpausebutton').click()");
break;
case 'next':
webview.executeJavaScript("document.getElementById('seekforwardbutton').click()");
break;
case 'previous':
webview.executeJavaScript("document.getElementById('seekbackbutton').click()");
break;
default:
break;
}
});