From 1f31d06a85bec9408d5f61d282d8deb06470a552 Mon Sep 17 00:00:00 2001 From: Jia Hao Date: Tue, 19 Jan 2016 11:42:52 +0800 Subject: [PATCH] Implement command line flag to show developer tools --- README.md | 7 +++++++ app/main.js | 7 +++++-- src/buildApp.js | 8 +++++--- src/cli.js | 2 ++ src/options.js | 4 +++- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 34f7e02..8f68df8 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,13 @@ Height of the packaged application, defaults to `800px`. Set the user agent to run the created app with. +#### [show-dev-tools] + +``` +'-d, --show-dev-tools' +``` + +Show developer tools when running the app. ## How It Works diff --git a/app/main.js b/app/main.js index 811072f..1027321 100644 --- a/app/main.js +++ b/app/main.js @@ -34,9 +34,12 @@ app.on('ready', function() { } ); - mainWindow.loadUrl('file://' + __dirname + '/index.html', { userAgent: appArgs.userAgent}); - //mainWindow.openDevTools(); + if (appArgs.showDevTools) { + mainWindow.openDevTools(); + } + + mainWindow.loadUrl('file://' + __dirname + '/index.html', { userAgent: appArgs.userAgent}); mainWindow.webContents.on('did-finish-load', function() { mainWindow.webContents.send('params', JSON.stringify(appArgs)); diff --git a/src/buildApp.js b/src/buildApp.js index 04cf828..d0d874c 100644 --- a/src/buildApp.js +++ b/src/buildApp.js @@ -27,7 +27,7 @@ function buildApp(options, callback) { async.waterfall([ callback => { - copyPlaceholderApp(options.dir, tmpPath, options.name, options.targetUrl, options.badge, options.width, options.height, options.userAgent, callback); + copyPlaceholderApp(options.dir, tmpPath, options.name, options.targetUrl, options.badge, options.width, options.height, options.userAgent, options.showDevTools, callback); }, (tempDir, callback) => { @@ -61,9 +61,10 @@ function buildApp(options, callback) { * @param {number} width * @param {number} height * @param {string} userAgent + * @param {boolean} showDevTools * @param {tempDirCallback} callback */ -function copyPlaceholderApp(srcAppDir, tempDir, name, targetURL, badge, width, height, userAgent, callback) { +function copyPlaceholderApp(srcAppDir, tempDir, name, targetURL, badge, width, height, userAgent, showDevTools, callback) { copy(srcAppDir, tempDir, error => { if (error) { @@ -78,7 +79,8 @@ function copyPlaceholderApp(srcAppDir, tempDir, name, targetURL, badge, width, h badge: badge, width: width, height: height, - userAgent: userAgent + userAgent: userAgent, + showDevTools: showDevTools }; fs.writeFileSync(path.join(tempDir, '/targetUrl.txt'), JSON.stringify(appArgs)); diff --git a/src/cli.js b/src/cli.js index 10d286d..03d45a7 100755 --- a/src/cli.js +++ b/src/cli.js @@ -27,6 +27,7 @@ function main(program) { program.width, program.height, program.userAgent, + program.showDevTools, callback); }, @@ -62,6 +63,7 @@ if (require.main === module) { .option('-w, --width ', 'set window width, defaults to 1280px', parseInt) .option('-h, --height ', 'set window height, defaults to 800px', parseInt) .option('-u, --user-agent ', 'set the user agent string for the app') + .option('-d, --show-dev-tools', 'show developer tools when running the app') .parse(process.argv); if (!process.argv.slice(2).length) { diff --git a/src/options.js b/src/options.js index 06efb24..c565b8f 100644 --- a/src/options.js +++ b/src/options.js @@ -22,6 +22,7 @@ function optionsFactory(name, width = 1280, height = 800, userAgent, + showDevTools, callback) { if (!validator.isURL(targetUrl, {require_protocol: true})) { @@ -57,7 +58,8 @@ function optionsFactory(name, badge: badge, width: width, height: height, - userAgent: userAgent + userAgent: userAgent, + showDevTools: showDevTools }; if (name && name.length > 0) {