Nativefier/app/src/static/preload.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2015-07-05 08:08:13 +02:00
/**
Preload file that will be executed in the renderer process
2015-07-05 08:08:13 +02:00
*/
var electron = require('electron');
var ipc = electron.ipcRenderer;
var webFrame = electron.webFrame;
2015-07-05 08:08:13 +02:00
2016-01-23 19:02:23 +01:00
setNotificationCallback(function(title, opt) {
2016-01-23 06:32:20 +01:00
ipc.send('notification', title, opt);
});
2016-01-23 19:02:23 +01:00
document.addEventListener('DOMContentLoaded', function(event) {
2016-01-23 06:32:20 +01:00
// do things
});
2016-01-23 19:02:23 +01:00
ipc.on('params', function(event, message) {
2015-07-05 08:08:13 +02:00
var appArgs = JSON.parse(message);
console.log('nativefier.json', appArgs);
});
2016-01-23 19:02:23 +01:00
ipc.on('change-zoom', function(event, message) {
webFrame.setZoomFactor(message);
});
2016-01-23 06:32:20 +01:00
/**
* Patches window.Notification to set a callback on a new Notification
* @param callback
*/
function setNotificationCallback(callback) {
2016-01-23 19:02:23 +01:00
var OldNotify = window.Notification;
var newNotify = function(title, opt) {
2016-01-23 06:32:20 +01:00
callback(title, opt);
2016-01-23 19:02:23 +01:00
return new OldNotify(title, opt);
2016-01-23 06:32:20 +01:00
};
2016-01-23 19:02:23 +01:00
newNotify.requestPermission = OldNotify.requestPermission.bind(OldNotify);
2016-01-23 06:32:20 +01:00
Object.defineProperty(newNotify, 'permission', {
2016-01-23 19:02:23 +01:00
get: function() {
return OldNotify.permission;
2016-01-23 06:32:20 +01:00
}
});
2016-01-23 06:32:20 +01:00
window.Notification = newNotify;
}