Add support for launching http URL directly
authorKevin Sawicki <kevinsawicki@gmail.com>
Thu, 4 Feb 2016 18:26:11 +0000 (10:26 -0800)
committerKevin Sawicki <kevinsawicki@gmail.com>
Thu, 4 Feb 2016 18:26:11 +0000 (10:26 -0800)
atom/browser/default_app/default_app.js
atom/browser/default_app/main.js

index 2ec765d..ebcca2a 100644 (file)
@@ -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();
-});
+};
index c562824..2b5c916 100644 (file)
@@ -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');
 }