mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2025-02-02 11:48:25 +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));
|
mainWindow.webContents.send('params', JSON.stringify(appArgs));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (appArgs.badge || appArgs.counter) {
|
if (appArgs.counter) {
|
||||||
mainWindow.on('page-title-updated', function () {
|
mainWindow.on('page-title-updated', function () {
|
||||||
|
|
||||||
if (!isOSX() || mainWindow.isFocused()) {
|
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()) {
|
if (!isOSX() || mainWindow.isFocused()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ app.on('ready', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mainWindow.loadURL(appArgs.targetUrl);
|
mainWindow.loadURL(appArgs.targetUrl);
|
||||||
// if the window is focused, clear the badge
|
|
||||||
mainWindow.on('focus', function () {
|
mainWindow.on('focus', function () {
|
||||||
if (!isOSX()) {
|
if (!isOSX()) {
|
||||||
return;
|
return;
|
||||||
|
@ -4,13 +4,12 @@
|
|||||||
|
|
||||||
var ipc = require('electron').ipcRenderer;
|
var ipc = require('electron').ipcRenderer;
|
||||||
|
|
||||||
// monkeypatch window.Notification
|
setNotificationCallback(function (title, opt) {
|
||||||
hookNotify(function(title, opt){
|
ipc.send('notification', title, opt);
|
||||||
ipc.emit('notification', title, opt);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function(event) {
|
document.addEventListener("DOMContentLoaded", function (event) {
|
||||||
// do things
|
// do things
|
||||||
});
|
});
|
||||||
|
|
||||||
ipc.on('params', function (event, message) {
|
ipc.on('params', function (event, message) {
|
||||||
@ -18,18 +17,23 @@ ipc.on('params', function (event, message) {
|
|||||||
console.log('nativefier.json', appArgs);
|
console.log('nativefier.json', appArgs);
|
||||||
});
|
});
|
||||||
|
|
||||||
function hookNotify(cb){
|
/**
|
||||||
var oldNotify = window.Notification;
|
* Patches window.Notification to set a callback on a new Notification
|
||||||
var newNotify = function (title, opt) {
|
* @param callback
|
||||||
cb(title, opt);
|
*/
|
||||||
return new oldNotify(title, opt);
|
function setNotificationCallback(callback) {
|
||||||
};
|
|
||||||
newNotify.requestPermission = oldNotify.requestPermission.bind(oldNotify);
|
|
||||||
Object.defineProperty(newNotify, 'permission', {
|
|
||||||
get: function() {
|
|
||||||
return oldNotify.permission;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
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([
|
async.waterfall([
|
||||||
callback => {
|
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) => {
|
(tempDir, callback) => {
|
||||||
@ -60,14 +60,13 @@ function buildApp(options, callback) {
|
|||||||
* @param {string} tempDir
|
* @param {string} tempDir
|
||||||
* @param {string} name
|
* @param {string} name
|
||||||
* @param {string} targetURL
|
* @param {string} targetURL
|
||||||
* @param {boolean} badge
|
|
||||||
* @param {boolean} counter
|
* @param {boolean} counter
|
||||||
* @param {number} width
|
* @param {number} width
|
||||||
* @param {number} height
|
* @param {number} height
|
||||||
* @param {string} userAgent
|
* @param {string} userAgent
|
||||||
* @param {tempDirCallback} callback
|
* @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;
|
const loadedPackageJson = packageJson;
|
||||||
copy(srcAppDir, tempDir, function(error) {
|
copy(srcAppDir, tempDir, function(error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -79,7 +78,6 @@ function copyPlaceholderApp(srcAppDir, tempDir, name, targetURL, badge, counter,
|
|||||||
const appArgs = {
|
const appArgs = {
|
||||||
name: name,
|
name: name,
|
||||||
targetUrl: targetURL,
|
targetUrl: targetURL,
|
||||||
badge: badge,
|
|
||||||
counter: counter,
|
counter: counter,
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
|
@ -23,7 +23,6 @@ function main(program) {
|
|||||||
program.overwrite,
|
program.overwrite,
|
||||||
program.conceal,
|
program.conceal,
|
||||||
program.icon,
|
program.icon,
|
||||||
program.badge,
|
|
||||||
program.counter,
|
program.counter,
|
||||||
program.width,
|
program.width,
|
||||||
program.height,
|
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('-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('-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('-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('--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('-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)
|
.option('-w, --width <value>', 'set window width, defaults to 1280px', parseInt)
|
||||||
|
@ -19,7 +19,6 @@ function optionsFactory(name,
|
|||||||
overwrite = false,
|
overwrite = false,
|
||||||
conceal = false,
|
conceal = false,
|
||||||
icon,
|
icon,
|
||||||
badge = false,
|
|
||||||
counter = false,
|
counter = false,
|
||||||
width = 1280,
|
width = 1280,
|
||||||
height = 800,
|
height = 800,
|
||||||
@ -59,7 +58,6 @@ function optionsFactory(name,
|
|||||||
icon: icon,
|
icon: icon,
|
||||||
|
|
||||||
// app configuration
|
// app configuration
|
||||||
badge: badge,
|
|
||||||
counter: counter,
|
counter: counter,
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user