From 8df3856c8f26ed3f1e9ece48850a26fc4466eced Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 4 Feb 2016 09:16:40 -0800 Subject: [PATCH 1/7] Use const for fs/path requires --- atom/browser/default_app/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atom/browser/default_app/main.js b/atom/browser/default_app/main.js index 895e3df636..c24fc12ac3 100644 --- a/atom/browser/default_app/main.js +++ b/atom/browser/default_app/main.js @@ -4,8 +4,8 @@ const dialog = electron.dialog; const shell = electron.shell; const Menu = electron.Menu; -var fs = require('fs'); -var path = require('path'); +const fs = require('fs'); +const path = require('path'); // Quit when all windows are closed and no other one is listening to this. app.on('window-all-closed', function() { From 2e96cab6aa82fd9e77778699a761f19112181463 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 4 Feb 2016 10:07:19 -0800 Subject: [PATCH 2/7] Extract helper function to load specified app --- atom/browser/default_app/main.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/atom/browser/default_app/main.js b/atom/browser/default_app/main.js index c24fc12ac3..c562824daf 100644 --- a/atom/browser/default_app/main.js +++ b/atom/browser/default_app/main.js @@ -234,12 +234,10 @@ if (option.modules.length > 0) { require('module')._preloadModules(option.modules); } -// Start the specified app if there is one specified in command line, otherwise -// start the default app. -if (option.file && !option.webdriver) { +function loadPackagePath(packagePath) { try { // Override app name and version. - var packagePath = path.resolve(option.file); + packagePath = path.resolve(packagePath); var packageJsonPath = path.join(packagePath, 'package.json'); if (fs.existsSync(packageJsonPath)) { var packageJson = JSON.parse(fs.readFileSync(packageJsonPath)); @@ -270,6 +268,12 @@ if (option.file && !option.webdriver) { throw e; } } +} + +// Start the specified app if there is one specified in command line, otherwise +// start the default app. +if (option.file && !option.webdriver) { + loadPackagePath(option.file); } else if (option.version) { console.log('v' + process.versions.electron); process.exit(0); From 69687c92e96cf59a5a66ff029cfd18d6ad62ad00 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 4 Feb 2016 10:26:11 -0800 Subject: [PATCH 3/7] Add support for launching http URL directly --- atom/browser/default_app/default_app.js | 20 +++++++++++--------- atom/browser/default_app/main.js | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/atom/browser/default_app/default_app.js b/atom/browser/default_app/default_app.js index 2ec765d0d6..ebcca2a5d9 100644 --- a/atom/browser/default_app/default_app.js +++ b/atom/browser/default_app/default_app.js @@ -9,13 +9,15 @@ app.on('window-all-closed', function() { app.quit(); }); -app.on('ready', function() { - mainWindow = new BrowserWindow({ - width: 800, - height: 600, - autoHideMenuBar: true, - useContentSize: true, +exports.load = function(appUrl) { + app.on('ready', function() { + mainWindow = new BrowserWindow({ + width: 800, + height: 600, + autoHideMenuBar: true, + useContentSize: true, + }); + mainWindow.loadURL(appUrl); + mainWindow.focus(); }); - mainWindow.loadURL('file://' + __dirname + '/index.html'); - mainWindow.focus(); -}); +}; diff --git a/atom/browser/default_app/main.js b/atom/browser/default_app/main.js index c562824daf..2b5c916749 100644 --- a/atom/browser/default_app/main.js +++ b/atom/browser/default_app/main.js @@ -6,6 +6,7 @@ const Menu = electron.Menu; const fs = require('fs'); const path = require('path'); +const url = require('url'); // Quit when all windows are closed and no other one is listening to this. app.on('window-all-closed', function() { @@ -270,10 +271,19 @@ function loadPackagePath(packagePath) { } } +function loadApplicationByUrl(appUrl) { + require('./default_app').load(appUrl); +} + // Start the specified app if there is one specified in command line, otherwise // start the default app. if (option.file && !option.webdriver) { - loadPackagePath(option.file); + var protocol = url.parse(option.file).protocol; + if (protocol === 'http:' || protocol === 'https:') { + loadApplicationByUrl(option.file); + } else { + loadPackagePath(option.file); + } } else if (option.version) { console.log('v' + process.versions.electron); process.exit(0); @@ -289,5 +299,5 @@ if (option.file && !option.webdriver) { console.log(helpMessage); process.exit(0); } else { - require('./default_app'); + loadApplicationByUrl('file://' + __dirname + '/index.html'); } From 312182e0bdd8d71cf7a26ffaa54daf825ad7fbb8 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 4 Feb 2016 10:33:22 -0800 Subject: [PATCH 4/7] Add support for launching HTML files directly --- atom/browser/default_app/main.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/atom/browser/default_app/main.js b/atom/browser/default_app/main.js index 2b5c916749..09082804b3 100644 --- a/atom/browser/default_app/main.js +++ b/atom/browser/default_app/main.js @@ -278,11 +278,15 @@ function loadApplicationByUrl(appUrl) { // Start the specified app if there is one specified in command line, otherwise // start the default app. if (option.file && !option.webdriver) { - var protocol = url.parse(option.file).protocol; + var file = option.file; + var protocol = url.parse(file).protocol; + var extension = path.extname(file); if (protocol === 'http:' || protocol === 'https:') { - loadApplicationByUrl(option.file); + loadApplicationByUrl(file); + } else if (extension === '.html' || extension === '.htm') { + loadApplicationByUrl('file://' + path.resolve(file)); } else { - loadPackagePath(option.file); + loadPackagePath(file); } } else if (option.version) { console.log('v' + process.versions.electron); From b74dd43ff564430a54b261688f9cd78dfb46b0b4 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 4 Feb 2016 10:34:36 -0800 Subject: [PATCH 5/7] Support opening file: URLs directly --- atom/browser/default_app/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/default_app/main.js b/atom/browser/default_app/main.js index 09082804b3..3ec80a6975 100644 --- a/atom/browser/default_app/main.js +++ b/atom/browser/default_app/main.js @@ -281,7 +281,7 @@ if (option.file && !option.webdriver) { var file = option.file; var protocol = url.parse(file).protocol; var extension = path.extname(file); - if (protocol === 'http:' || protocol === 'https:') { + if (protocol === 'http:' || protocol === 'https:' || protocol === 'file:') { loadApplicationByUrl(file); } else if (extension === '.html' || extension === '.htm') { loadApplicationByUrl('file://' + path.resolve(file)); From f482ea4902738e3135a732b24daa50ef2a494383 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 4 Feb 2016 10:35:17 -0800 Subject: [PATCH 6/7] loadPackagePath -> loadApplicationPackage --- atom/browser/default_app/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atom/browser/default_app/main.js b/atom/browser/default_app/main.js index 3ec80a6975..855d2463d2 100644 --- a/atom/browser/default_app/main.js +++ b/atom/browser/default_app/main.js @@ -235,7 +235,7 @@ if (option.modules.length > 0) { require('module')._preloadModules(option.modules); } -function loadPackagePath(packagePath) { +function loadApplicationPackage(packagePath) { try { // Override app name and version. packagePath = path.resolve(packagePath); @@ -286,7 +286,7 @@ if (option.file && !option.webdriver) { } else if (extension === '.html' || extension === '.htm') { loadApplicationByUrl('file://' + path.resolve(file)); } else { - loadPackagePath(file); + loadApplicationPackage(file); } } else if (option.version) { console.log('v' + process.versions.electron); From fa4ad9d95f6ad7243783a6e7de24ce0b0f9e819d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 4 Feb 2016 10:45:52 -0800 Subject: [PATCH 7/7] Tweak help message for new path options --- atom/browser/default_app/main.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/atom/browser/default_app/main.js b/atom/browser/default_app/main.js index 855d2463d2..6ff26e9ea6 100644 --- a/atom/browser/default_app/main.js +++ b/atom/browser/default_app/main.js @@ -294,9 +294,14 @@ if (option.file && !option.webdriver) { } else if (option.help) { var helpMessage = "Electron v" + process.versions.electron + " - Cross Platform Desktop Application Shell\n\n"; helpMessage += "Usage: electron [options] [path]\n\n"; - helpMessage += "A path to an Electron application may be specified. The path must be to \n"; - helpMessage += "an index.js file or to a folder containing a package.json or index.js file.\n\n"; - helpMessage += "Options:\n"; + helpMessage += "A path to an Electron application may be specified.\n"; + helpMessage += "The path must be one of the following:\n\n"; + helpMessage += " - index.js file.\n"; + helpMessage += " - Folder containing a package.json file.\n"; + helpMessage += " - Folder containing an index.js file.\n"; + helpMessage += " - .html/.htm file.\n"; + helpMessage += " - http://, https://, or file:// URL.\n"; + helpMessage += "\nOptions:\n"; helpMessage += " -r, --require Module to preload (option can be repeated)\n"; helpMessage += " -h, --help Print this usage message.\n"; helpMessage += " -v, --version Print the version.";