Implemented setting of badge configuration in the command line

This commit is contained in:
Jia Hao 2015-07-06 09:46:27 +08:00
parent 199b1423e5
commit 80f1863b8b
4 changed files with 12 additions and 9 deletions

View File

@ -7,7 +7,7 @@ var ipc = require('ipc');
ipc.on('params', function(message) {
var appArgs = JSON.parse(message);
console.log(appArgs);
document.title = appArgs.name;
var webView = document.createElement('webview');
@ -24,9 +24,11 @@ ipc.on('params', function(message) {
// We check for desktop notifications by listening to a title change in the webview
// Not elegant, but it will have to do
webView.addEventListener('page-title-set', function(event) {
ipc.send('notification-message', 'TITLE_CHANGED');
});
if (appArgs.badge) {
webView.addEventListener('page-title-set', function(event) {
ipc.send('notification-message', 'TITLE_CHANGED');
});
}
var webViewDiv = document.getElementById('webViewDiv');
webViewDiv.appendChild(webView);

View File

@ -31,11 +31,11 @@ app.on('ready', function() {
);
mainWindow.loadUrl('file://' + __dirname + '/index.html');
mainWindow.openDevTools();
//mainWindow.openDevTools();
mainWindow.webContents.on('did-finish-load', function() {
fs.readFile(APP_ARGS_FILE_PATH, 'utf8', function (error, data) {
if (error) {
console.error('Error reading file: ' + error);
console.error('Error reading app config file: ' + error);
} else {
console.log(data);
mainWindow.webContents.send('params', data);

2
cli.js
View File

@ -31,7 +31,7 @@ if (!validator.isURL(args.target)) {
process.exit(1);
}
tempDir(args.name, args.target, function (error, appDir) {
tempDir(args.name, args.target, args.badge, function (error, appDir) {
if (error) {
console.error(error);

View File

@ -20,7 +20,7 @@ var ncp = require('ncp').ncp;
* @param {string} targetURL
* @param {tempDirCallback} callback
*/
module.exports = function (name, targetURL, callback) {
module.exports = function (name, targetURL, badge, callback) {
var tempDir = temp.path();
ncp(__dirname + '/app', tempDir, function (error) {
@ -32,7 +32,8 @@ module.exports = function (name, targetURL, callback) {
var appArgs = {
name: name,
targetUrl: targetURL
targetUrl: targetURL,
badge: badge
};
fs.writeFileSync(tempDir + '/targetUrl.txt', JSON.stringify(appArgs));