From 69687c92e96cf59a5a66ff029cfd18d6ad62ad00 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 4 Feb 2016 10:26:11 -0800 Subject: [PATCH] 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 2ec765d..ebcca2a 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 c562824..2b5c916 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'); } -- 2.7.4