2015-07-05 06:08:13 +00:00
|
|
|
/**
|
2016-01-22 11:57:39 +00:00
|
|
|
Preload file that will be executed in the renderer process
|
2015-07-05 06:08:13 +00:00
|
|
|
*/
|
2016-01-25 07:56:33 +00:00
|
|
|
import electron from 'electron';
|
2016-01-23 01:27:09 +00:00
|
|
|
var ipc = electron.ipcRenderer;
|
|
|
|
var webFrame = electron.webFrame;
|
2015-07-05 06:08:13 +00:00
|
|
|
|
2016-01-23 18:02:23 +00:00
|
|
|
setNotificationCallback(function(title, opt) {
|
2016-01-23 05:32:20 +00:00
|
|
|
ipc.send('notification', title, opt);
|
2016-01-22 18:44:42 +00:00
|
|
|
});
|
|
|
|
|
2016-01-23 18:02:23 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', function(event) {
|
2016-01-23 05:32:20 +00:00
|
|
|
// do things
|
2016-01-25 07:56:33 +00:00
|
|
|
|
|
|
|
window.addEventListener('contextmenu', function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
const targetElement = event.srcElement;
|
|
|
|
const targetHref = targetElement.href;
|
|
|
|
|
|
|
|
ipc.send('contextMenuOpened', targetHref);
|
|
|
|
}, false);
|
|
|
|
|
2016-01-21 17:32:21 +00:00
|
|
|
});
|
2016-01-19 12:26:19 +00:00
|
|
|
|
2016-01-23 18:02:23 +00:00
|
|
|
ipc.on('params', function(event, message) {
|
2015-07-05 06:08:13 +00:00
|
|
|
var appArgs = JSON.parse(message);
|
2016-01-22 11:57:39 +00:00
|
|
|
console.log('nativefier.json', appArgs);
|
2016-01-19 12:26:19 +00:00
|
|
|
});
|
2016-01-22 18:44:42 +00:00
|
|
|
|
2016-01-23 18:02:23 +00:00
|
|
|
ipc.on('change-zoom', function(event, message) {
|
2016-01-23 01:27:09 +00:00
|
|
|
webFrame.setZoomFactor(message);
|
|
|
|
});
|
|
|
|
|
2016-01-23 05:32:20 +00:00
|
|
|
/**
|
|
|
|
* Patches window.Notification to set a callback on a new Notification
|
|
|
|
* @param callback
|
|
|
|
*/
|
|
|
|
function setNotificationCallback(callback) {
|
|
|
|
|
2016-01-23 18:02:23 +00:00
|
|
|
var OldNotify = window.Notification;
|
|
|
|
var newNotify = function(title, opt) {
|
2016-01-23 05:32:20 +00:00
|
|
|
callback(title, opt);
|
2016-01-23 18:02:23 +00:00
|
|
|
return new OldNotify(title, opt);
|
2016-01-23 05:32:20 +00:00
|
|
|
};
|
2016-01-23 18:02:23 +00:00
|
|
|
newNotify.requestPermission = OldNotify.requestPermission.bind(OldNotify);
|
2016-01-23 05:32:20 +00:00
|
|
|
Object.defineProperty(newNotify, 'permission', {
|
2016-01-23 18:02:23 +00:00
|
|
|
get: function() {
|
|
|
|
return OldNotify.permission;
|
2016-01-23 05:32:20 +00:00
|
|
|
}
|
|
|
|
});
|
2016-01-22 18:44:42 +00:00
|
|
|
|
2016-01-23 05:32:20 +00:00
|
|
|
window.Notification = newNotify;
|
2016-01-22 18:44:42 +00:00
|
|
|
}
|
2016-01-25 07:56:33 +00:00
|
|
|
|
|
|
|
function clickSelector(element) {
|
|
|
|
const mouseEvent = new MouseEvent('click');
|
|
|
|
element.dispatchEvent(mouseEvent);
|
|
|
|
}
|