2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-11-11 07:41:04 +00:00

Implement command line flag to show developer tools

This commit is contained in:
Jia Hao 2016-01-19 11:42:52 +08:00
parent 48345eceb5
commit 1f31d06a85
5 changed files with 22 additions and 6 deletions

View File

@ -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

View File

@ -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));

View File

@ -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));

View File

@ -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 <value>', 'set window width, defaults to 1280px', parseInt)
.option('-h, --height <value>', 'set window height, defaults to 800px', parseInt)
.option('-u, --user-agent <value>', '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) {

View File

@ -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) {