mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-11-17 02:15:10 +00:00
58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
/**
|
|
* Created by JiaHao on 5/7/15.
|
|
*/
|
|
|
|
var ipc = require('electron').ipcRenderer;
|
|
|
|
var webView;
|
|
|
|
ipc.on('params', function (event, message) {
|
|
var appArgs = JSON.parse(message);
|
|
document.title = appArgs.name;
|
|
|
|
webView = document.createElement('webview');
|
|
|
|
webView.setAttribute('id', 'webView');
|
|
webView.setAttribute('src', appArgs.targetUrl);
|
|
webView.setAttribute('autosize', 'on');
|
|
webView.setAttribute('minwidth', '100');
|
|
webView.setAttribute('minheight', '100');
|
|
|
|
webView.addEventListener('dom-ready', function () {
|
|
if (appArgs.userAgent) {
|
|
webView.setUserAgent(appArgs.userAgent);
|
|
}
|
|
});
|
|
webView.addEventListener('new-window', function (e) {
|
|
require('shell').openExternal(e.url);
|
|
});
|
|
|
|
webView.addEventListener('did-finish-load', function (e) {
|
|
var loadingContainer = document.getElementById('loading-container');
|
|
loadingContainer.parentNode.removeChild(loadingContainer);
|
|
|
|
// We check for desktop notifications by listening to a title change in the webview
|
|
// Not elegant, but it will have to do
|
|
if (appArgs.badge) {
|
|
webView.addEventListener('page-title-set', function (event) {
|
|
ipc.send('notification-message', 'TITLE_CHANGED');
|
|
});
|
|
}
|
|
});
|
|
|
|
|
|
var webViewDiv = document.getElementById('webViewDiv');
|
|
webViewDiv.appendChild(webView);
|
|
});
|
|
|
|
ipc.on('toggle-dev-tools', function (event, message) {
|
|
if (!message) {
|
|
return;
|
|
}
|
|
if (webView.isDevToolsOpened()) {
|
|
webView.closeDevTools();
|
|
} else {
|
|
webView.openDevTools();
|
|
}
|
|
});
|