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-05-26 08:51:07 +00:00
|
|
|
import {ipcRenderer, webFrame} from 'electron';
|
2016-02-25 06:11:48 +00:00
|
|
|
import path from 'path';
|
|
|
|
import fs from 'fs';
|
2015-07-05 06:08:13 +00:00
|
|
|
|
2016-02-25 06:11:48 +00:00
|
|
|
const INJECT_JS_PATH = path.join(__dirname, '../../', 'inject/inject.js');
|
|
|
|
|
2016-01-29 14:04:41 +00:00
|
|
|
setNotificationCallback((title, opt) => {
|
|
|
|
ipcRenderer.send('notification', title, opt);
|
2016-01-22 18:44:42 +00:00
|
|
|
});
|
|
|
|
|
2016-02-27 16:49:54 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2016-01-23 05:32:20 +00:00
|
|
|
// do things
|
2016-01-25 07:56:33 +00:00
|
|
|
|
2016-01-29 14:04:41 +00:00
|
|
|
window.addEventListener('contextmenu', event => {
|
2016-01-25 07:56:33 +00:00
|
|
|
event.preventDefault();
|
|
|
|
const targetElement = event.srcElement;
|
|
|
|
const targetHref = targetElement.href;
|
|
|
|
|
2016-01-25 08:49:11 +00:00
|
|
|
if (!targetHref) {
|
2016-01-29 14:04:41 +00:00
|
|
|
ipcRenderer.once('contextMenuClosed', () => {
|
2016-01-25 08:49:11 +00:00
|
|
|
clickSelector(event.target);
|
2016-01-29 14:04:41 +00:00
|
|
|
ipcRenderer.send('cancelNewWindowOverride');
|
2016-01-25 08:49:11 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-01-29 14:04:41 +00:00
|
|
|
ipcRenderer.send('contextMenuOpened', targetHref);
|
2016-01-25 07:56:33 +00:00
|
|
|
}, false);
|
|
|
|
|
2016-02-25 06:11:48 +00:00
|
|
|
injectScripts();
|
2016-01-21 17:32:21 +00:00
|
|
|
});
|
2016-01-19 12:26:19 +00:00
|
|
|
|
2016-01-29 14:04:41 +00:00
|
|
|
ipcRenderer.on('params', (event, message) => {
|
|
|
|
const 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-29 14:04:41 +00:00
|
|
|
ipcRenderer.on('change-zoom', (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-29 14:04:41 +00:00
|
|
|
const OldNotify = window.Notification;
|
|
|
|
const newNotify = (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-29 14:04:41 +00:00
|
|
|
get: () => {
|
2016-01-23 18:02:23 +00:00
|
|
|
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);
|
|
|
|
}
|
2016-02-25 06:11:48 +00:00
|
|
|
|
|
|
|
function injectScripts() {
|
|
|
|
const needToInject = fs.existsSync(INJECT_JS_PATH);
|
|
|
|
if (!needToInject) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
require(INJECT_JS_PATH);
|
|
|
|
}
|