forked from Iketaki/MMM-WebView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-WebView.js
49 lines (47 loc) · 1.46 KB
/
MMM-WebView.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
/* Magic Mirror
* Module: MMM-WebView
*
* By Shunta Iketaki https://twitter.com/Iketaki
* MIT Licensed.
*/
const WEBVIEW_ID = 'mmm-webview';
Module.register('MMM-WebView', {
defaults: {
url: 'https://www.google.com/',
height: '640px',
width: '480px',
autoRefresh: false,
autoRefreshInterval: 10 * 60 * 1000,
loadedJS: undefined,
},
start: function () {
if (this.config.autoRefresh) {
setInterval(() => {
//Electron.session.defaultSession.clearCache(() => {});
//this.updateDom();
const webview = document.getElementById(WEBVIEW_ID);
webview.reloadIgnoringCache();
}, this.config.autoRefreshInterval);
}
},
getDom: function () {
let wrapper = document.createElement('div');
wrapper.id = 'mmm-webview-wrapper';
wrapper.innerHTML = `<webview id="${WEBVIEW_ID}" style="opacity: 0.7; width: ${this.config.width}; height: ${this.config.height};" src="${this.config.url}"></webview>`;
return wrapper;
},
notificationReceived: function (notification, payload, sender) {
if (notification == 'MODULE_DOM_CREATED') {
if (this.config.loadedJS && this.config.loadedJS.length > 0) {
const webview = document.getElementById(WEBVIEW_ID);
if (webview) {
webview.addEventListener('did-finish-load', () => {
webview.executeJavaScript(this.config.loadedJS);
});
} else {
// TODO: Show Error
}
}
}
},
});