mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2025-01-22 22:58:33 +00:00
Cleanup notification integration #360
This commit is contained in:
parent
bed4260f55
commit
07acbced3e
@ -73,7 +73,7 @@ app.on('ready', function () {
|
||||
mainWindow.webContents.send('params', JSON.stringify(appArgs));
|
||||
});
|
||||
|
||||
if (appArgs.badge || appArgs.counter) {
|
||||
if (appArgs.counter) {
|
||||
mainWindow.on('page-title-updated', function () {
|
||||
|
||||
if (!isOSX() || mainWindow.isFocused()) {
|
||||
@ -94,7 +94,7 @@ app.on('ready', function () {
|
||||
});
|
||||
}
|
||||
|
||||
mainWindow.on('notification', function (title) {
|
||||
ipcMain.on('notification', function(event, title, opts) {
|
||||
if (!isOSX() || mainWindow.isFocused()) {
|
||||
return;
|
||||
}
|
||||
@ -111,7 +111,7 @@ app.on('ready', function () {
|
||||
});
|
||||
|
||||
mainWindow.loadURL(appArgs.targetUrl);
|
||||
// if the window is focused, clear the badge
|
||||
|
||||
mainWindow.on('focus', function () {
|
||||
if (!isOSX()) {
|
||||
return;
|
||||
|
@ -4,13 +4,12 @@
|
||||
|
||||
var ipc = require('electron').ipcRenderer;
|
||||
|
||||
// monkeypatch window.Notification
|
||||
hookNotify(function(title, opt){
|
||||
ipc.emit('notification', title, opt);
|
||||
setNotificationCallback(function (title, opt) {
|
||||
ipc.send('notification', title, opt);
|
||||
});
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
// do things
|
||||
document.addEventListener("DOMContentLoaded", function (event) {
|
||||
// do things
|
||||
});
|
||||
|
||||
ipc.on('params', function (event, message) {
|
||||
@ -18,18 +17,23 @@ ipc.on('params', function (event, 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;
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Patches window.Notification to set a callback on a new Notification
|
||||
* @param callback
|
||||
*/
|
||||
function setNotificationCallback(callback) {
|
||||
|
||||
window.Notification = newNotify;
|
||||
var oldNotify = window.Notification;
|
||||
var newNotify = function (title, opt) {
|
||||
callback(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;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ function buildApp(options, callback) {
|
||||
|
||||
async.waterfall([
|
||||
callback => {
|
||||
copyPlaceholderApp(options.dir, tmpPath, options.name, options.targetUrl, options.badge, options.counter, options.width, options.height, options.userAgent, callback);
|
||||
copyPlaceholderApp(options.dir, tmpPath, options.name, options.targetUrl, options.counter, options.width, options.height, options.userAgent, callback);
|
||||
},
|
||||
|
||||
(tempDir, callback) => {
|
||||
@ -60,14 +60,13 @@ function buildApp(options, callback) {
|
||||
* @param {string} tempDir
|
||||
* @param {string} name
|
||||
* @param {string} targetURL
|
||||
* @param {boolean} badge
|
||||
* @param {boolean} counter
|
||||
* @param {number} width
|
||||
* @param {number} height
|
||||
* @param {string} userAgent
|
||||
* @param {tempDirCallback} callback
|
||||
*/
|
||||
function copyPlaceholderApp(srcAppDir, tempDir, name, targetURL, badge, counter, width, height, userAgent, callback) {
|
||||
function copyPlaceholderApp(srcAppDir, tempDir, name, targetURL, counter, width, height, userAgent, callback) {
|
||||
const loadedPackageJson = packageJson;
|
||||
copy(srcAppDir, tempDir, function(error) {
|
||||
if (error) {
|
||||
@ -79,7 +78,6 @@ function copyPlaceholderApp(srcAppDir, tempDir, name, targetURL, badge, counter,
|
||||
const appArgs = {
|
||||
name: name,
|
||||
targetUrl: targetURL,
|
||||
badge: badge,
|
||||
counter: counter,
|
||||
width: width,
|
||||
height: height,
|
||||
|
@ -23,7 +23,6 @@ function main(program) {
|
||||
program.overwrite,
|
||||
program.conceal,
|
||||
program.icon,
|
||||
program.badge,
|
||||
program.counter,
|
||||
program.width,
|
||||
program.height,
|
||||
@ -59,7 +58,6 @@ if (require.main === module) {
|
||||
.option('-e, --electron-version <value>', 'electron version to package, without the \'v\', see https://github.com/atom/electron/releases')
|
||||
.option('-o, --overwrite', 'if output directory for a platform already exists, replaces it rather than skipping it, defaults to false')
|
||||
.option('-c, --conceal', 'packages the source code within your app into an archive, defaults to false, see http://electron.atom.io/docs/v0.36.0/tutorial/application-packaging/')
|
||||
.option('-b, --badge', 'if the target app should show badges in the dock on receipt of desktop notifications (OSX only), defaults to false')
|
||||
.option('--counter', 'if the target app should use a persistant counter badge in the dock (OSX only), defaults to false')
|
||||
.option('-i, --icon <value>', 'the icon file to use as the icon for the app (should be a .icns file on OSX)')
|
||||
.option('-w, --width <value>', 'set window width, defaults to 1280px', parseInt)
|
||||
|
@ -19,7 +19,6 @@ function optionsFactory(name,
|
||||
overwrite = false,
|
||||
conceal = false,
|
||||
icon,
|
||||
badge = false,
|
||||
counter = false,
|
||||
width = 1280,
|
||||
height = 800,
|
||||
@ -59,7 +58,6 @@ function optionsFactory(name,
|
||||
icon: icon,
|
||||
|
||||
// app configuration
|
||||
badge: badge,
|
||||
counter: counter,
|
||||
width: width,
|
||||
height: height,
|
||||
|
Loading…
x
Reference in New Issue
Block a user