From 80f1863b8b636938db0dd7aa51e0cb6e1125ab39 Mon Sep 17 00:00:00 2001 From: Jia Hao Date: Mon, 6 Jul 2015 09:46:27 +0800 Subject: [PATCH] Implemented setting of badge configuration in the command line --- app/assets/js/index.js | 10 ++++++---- app/main.js | 4 ++-- cli.js | 2 +- tempDir.js | 5 +++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/assets/js/index.js b/app/assets/js/index.js index d4e797f..b0d22a8 100644 --- a/app/assets/js/index.js +++ b/app/assets/js/index.js @@ -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); diff --git a/app/main.js b/app/main.js index 215aae5..ac0dd5a 100644 --- a/app/main.js +++ b/app/main.js @@ -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); diff --git a/cli.js b/cli.js index 053b01e..1ed44db 100755 --- a/cli.js +++ b/cli.js @@ -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); diff --git a/tempDir.js b/tempDir.js index bd0e83c..4e22b5d 100644 --- a/tempDir.js +++ b/tempDir.js @@ -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));