2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-09-29 04:39:04 +00:00
nativefier/app/src/preload.js

36 lines
848 B
JavaScript
Raw Normal View History

2015-07-05 06:08:13 +00:00
/**
Preload file that will be executed in the renderer process
2015-07-05 06:08:13 +00:00
*/
var ipc = require('electron').ipcRenderer;
2015-07-05 06:08:13 +00:00
// monkeypatch window.Notification
hookNotify(function(title, opt){
ipc.emit('notification', title, opt);
});
document.addEventListener("DOMContentLoaded", function(event) {
2016-01-22 18:48:04 +00:00
// do things
});
ipc.on('params', function (event, message) {
2015-07-05 06:08:13 +00:00
var appArgs = JSON.parse(message);
console.log('nativefier.json', appArgs);
});
function hookNotify(cb){
var oldNotify = window.Notification;
var newNotify = function (title, opt) {
cb(title, opt);
return new oldNotify(title, opt);
};
newNotify.requestPermission = oldNotify.requestPermission.bind(oldNotify);
Object.defineProperty(newNotify, 'permission', {
get: function() {
return oldNotify.permission;
}
});
window.Notification = newNotify;
}