From 4ddf10a1089caa833ccfc32703a8445fe6879a7e Mon Sep 17 00:00:00 2001 From: Jia Hao Date: Mon, 6 Jul 2015 10:31:09 +0800 Subject: [PATCH] Updated to support setting of window dimensions using the cli, and updated documentation --- README.md | 13 +++++++++---- app/assets/js/index.js | 4 ++-- app/main.js | 16 +++++----------- cli.js | 2 +- tempDir.js | 9 +++++++-- usage.txt | 4 +++- 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index d8c97ef..17b6959 100644 --- a/README.md +++ b/README.md @@ -63,11 +63,17 @@ version-string should contain a hash of the application metadata to be embed - ProductName - InternalName badge if the target app should show badges in the OSX dock on receipt of desktop notifications +width window width (default=1280) +height window height (default=800) ``` See [electron-packager](https://github.com/maxogden/electron-packager) for more details. +### Icon +On OSX, the icon parameter should be a path to an `.icns` file. [iConvertIcons](https://iconverticons.com/online/) can be used to convert `.pngs`, though it can be quite cumbersome. -#### OSX Dock Badge +To retrieve the `.icns` file from the downloaded file, extract it first and press File > Get Info. Then select the icon in the top left corner of the info window and press `⌘-C`. Open Preview and press File > New from clipboard and save the `.icns` file. It took me a while to figure out how to do that and question why a `.icns` file was not simply provided in the downloaded archive. + +### OSX Dock Badge On OSX, it is desired for the App dock icon to show a badge on the receipt of a desktop notification. @@ -91,7 +97,6 @@ Creating an native wrapper for Facebook Messenger with the following arguments: $ nativefier Messenger http://messenger.com --platform=darwin --arch=x64 --version=0.29.1 --overwrite --badge ``` -## Todo +## Issues -- Set the app icon from a url in the CLI -- Set the app window dimensions from the CLI \ No newline at end of file +- Better workaround for desktop notifications and OSX dock badges \ No newline at end of file diff --git a/app/assets/js/index.js b/app/assets/js/index.js index b0d22a8..ba0b42a 100644 --- a/app/assets/js/index.js +++ b/app/assets/js/index.js @@ -15,8 +15,8 @@ ipc.on('params', function(message) { webView.setAttribute('id', 'webView'); webView.setAttribute('src', appArgs.targetUrl); webView.setAttribute('autosize', 'on'); - webView.setAttribute('minwidth', '600'); - webView.setAttribute('minheight', '800'); + webView.setAttribute('minwidth', '100'); + webView.setAttribute('minheight', '100'); webView.addEventListener('new-window', function(e) { require('shell').openExternal(e.url); diff --git a/app/main.js b/app/main.js index ac0dd5a..2548b19 100644 --- a/app/main.js +++ b/app/main.js @@ -12,6 +12,8 @@ require('crash-reporter').start(); var mainWindow = null; +var appArgs = JSON.parse(fs.readFileSync(APP_ARGS_FILE_PATH, 'utf8')); + app.on('window-all-closed', function() { if (process.platform != 'darwin') { app.quit(); @@ -21,8 +23,8 @@ app.on('window-all-closed', function() { app.on('ready', function() { mainWindow = new BrowserWindow( { - width: 1280, - height: 800, + width: appArgs.width || 1280, + height: appArgs.height || 800, 'web-preferences': { javascript: true, plugins: true, @@ -33,16 +35,8 @@ app.on('ready', function() { //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 app config file: ' + error); - } else { - console.log(data); - mainWindow.webContents.send('params', data); - } - - }) + mainWindow.webContents.send('params', JSON.stringify(appArgs)); }); // if the window is focused, clear the badge diff --git a/cli.js b/cli.js index 6b5190c..aec93ea 100755 --- a/cli.js +++ b/cli.js @@ -32,7 +32,7 @@ if (!validator.isURL(args.target)) { process.exit(1); } -tempDir(args.name, args.target, args.badge, function (error, appDir) { +tempDir(args.name, args.target, args.badge, args.width, args.height, function (error, appDir) { if (error) { console.error(error); diff --git a/tempDir.js b/tempDir.js index 4e22b5d..f0b5123 100644 --- a/tempDir.js +++ b/tempDir.js @@ -18,9 +18,12 @@ var ncp = require('ncp').ncp; * * @param {string} name * @param {string} targetURL + * @param {boolean} badge + * @param width + * @param height * @param {tempDirCallback} callback */ -module.exports = function (name, targetURL, badge, callback) { +module.exports = function (name, targetURL, badge, width, height, callback) { var tempDir = temp.path(); ncp(__dirname + '/app', tempDir, function (error) { @@ -33,7 +36,9 @@ module.exports = function (name, targetURL, badge, callback) { var appArgs = { name: name, targetUrl: targetURL, - badge: badge + badge: badge, + width: width, + height: height }; fs.writeFileSync(tempDir + '/targetUrl.txt', JSON.stringify(appArgs)); diff --git a/usage.txt b/usage.txt index 5e40e24..b5aebea 100644 --- a/usage.txt +++ b/usage.txt @@ -35,4 +35,6 @@ version-string should contain a hash of the application metadata to be embed - ProductVersion - ProductName - InternalName -badge if the target app should show badges in the OSX dock on receipt of desktop notifications \ No newline at end of file +badge if the target app should show badges in the OSX dock on receipt of desktop notifications +width window width (default=1280) +height window height (default=800) \ No newline at end of file