2015-07-05 08:08:13 +02:00
|
|
|
/**
|
2016-01-22 12:57:39 +01:00
|
|
|
Preload file that will be executed in the renderer process
|
2015-07-05 08:08:13 +02:00
|
|
|
*/
|
2018-04-22 21:54:29 +02:00
|
|
|
import { ipcRenderer } from 'electron';
|
2016-02-25 07:11:48 +01:00
|
|
|
import path from 'path';
|
|
|
|
import fs from 'fs';
|
2015-07-05 08:08:13 +02:00
|
|
|
|
2016-02-25 07:11:48 +01:00
|
|
|
const INJECT_JS_PATH = path.join(__dirname, '../../', 'inject/inject.js');
|
2017-12-19 14:42:06 +01:00
|
|
|
const log = require('loglevel');
|
2017-04-29 16:52:12 +02:00
|
|
|
/**
|
|
|
|
* Patches window.Notification to set a callback on a new Notification
|
|
|
|
* @param callback
|
|
|
|
*/
|
|
|
|
function setNotificationCallback(callback) {
|
|
|
|
const OldNotify = window.Notification;
|
|
|
|
const newNotify = (title, opt) => {
|
|
|
|
callback(title, opt);
|
|
|
|
return new OldNotify(title, opt);
|
|
|
|
};
|
|
|
|
newNotify.requestPermission = OldNotify.requestPermission.bind(OldNotify);
|
|
|
|
Object.defineProperty(newNotify, 'permission', {
|
|
|
|
get: () => OldNotify.permission,
|
|
|
|
});
|
|
|
|
|
|
|
|
window.Notification = newNotify;
|
|
|
|
}
|
|
|
|
|
|
|
|
function injectScripts() {
|
|
|
|
const needToInject = fs.existsSync(INJECT_JS_PATH);
|
|
|
|
if (!needToInject) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Dynamically require scripts
|
|
|
|
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
|
|
require(INJECT_JS_PATH);
|
|
|
|
}
|
|
|
|
|
2016-01-29 15:04:41 +01:00
|
|
|
setNotificationCallback((title, opt) => {
|
2017-04-29 16:52:12 +02:00
|
|
|
ipcRenderer.send('notification', title, opt);
|
2016-01-22 19:44:42 +01:00
|
|
|
});
|
|
|
|
|
2016-02-27 17:49:54 +01:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2017-04-29 16:52:12 +02:00
|
|
|
injectScripts();
|
2016-01-21 18:32:21 +01:00
|
|
|
});
|
2016-01-19 13:26:19 +01:00
|
|
|
|
2016-01-29 15:04:41 +01:00
|
|
|
ipcRenderer.on('params', (event, message) => {
|
2017-04-29 16:52:12 +02:00
|
|
|
const appArgs = JSON.parse(message);
|
2017-12-19 14:42:06 +01:00
|
|
|
log.info('nativefier.json', appArgs);
|
2016-01-19 13:26:19 +01:00
|
|
|
});
|
2016-01-22 19:44:42 +01:00
|
|
|
|
2016-06-16 09:28:36 +02:00
|
|
|
ipcRenderer.on('debug', (event, message) => {
|
2017-04-29 16:52:12 +02:00
|
|
|
// eslint-disable-next-line no-console
|
2017-12-19 14:42:06 +01:00
|
|
|
log.info('debug:', message);
|
2016-06-16 09:28:36 +02:00
|
|
|
});
|