Add support for launching http URL directly

This commit is contained in:
Kevin Sawicki 2016-02-04 10:26:11 -08:00
parent 2e96cab6aa
commit 69687c92e9
2 changed files with 23 additions and 11 deletions

View file

@ -9,13 +9,15 @@ app.on('window-all-closed', function() {
app.quit(); app.quit();
}); });
app.on('ready', function() { exports.load = function(appUrl) {
app.on('ready', function() {
mainWindow = new BrowserWindow({ mainWindow = new BrowserWindow({
width: 800, width: 800,
height: 600, height: 600,
autoHideMenuBar: true, autoHideMenuBar: true,
useContentSize: true, useContentSize: true,
}); });
mainWindow.loadURL('file://' + __dirname + '/index.html'); mainWindow.loadURL(appUrl);
mainWindow.focus(); mainWindow.focus();
}); });
};

View file

@ -6,6 +6,7 @@ const Menu = electron.Menu;
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const url = require('url');
// Quit when all windows are closed and no other one is listening to this. // Quit when all windows are closed and no other one is listening to this.
app.on('window-all-closed', function() { 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 specified app if there is one specified in command line, otherwise
// start the default app. // start the default app.
if (option.file && !option.webdriver) { if (option.file && !option.webdriver) {
var protocol = url.parse(option.file).protocol;
if (protocol === 'http:' || protocol === 'https:') {
loadApplicationByUrl(option.file);
} else {
loadPackagePath(option.file); loadPackagePath(option.file);
}
} else if (option.version) { } else if (option.version) {
console.log('v' + process.versions.electron); console.log('v' + process.versions.electron);
process.exit(0); process.exit(0);
@ -289,5 +299,5 @@ if (option.file && !option.webdriver) {
console.log(helpMessage); console.log(helpMessage);
process.exit(0); process.exit(0);
} else { } else {
require('./default_app'); loadApplicationByUrl('file://' + __dirname + '/index.html');
} }