Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow browsers to start multiple times even if they are already running. #33

Merged
merged 1 commit into from
Nov 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/local/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ Instance.prototype.getPid = function (callback) {

Instance.prototype.stop = function (callback) {
var self = this;

if(self.running) {
return callback(null, {});
}

if (callback) {
this.once('stop', function (data) {
callback(null, data);
Expand Down Expand Up @@ -98,10 +103,18 @@ exports.start = function (cmd, args, settings, options, callback) {
// can only launch once
if (options.process && !options.multi) {
getProcessId(options.process, function (err, pid) {
if (!err) {
if (!err && !options.opensTab) {
return callback(new Error(options.process + ' seems already running with process id ' + pid));
}
return callback(null, getInstance());

var instance = getInstance();

// Add a `running` flag if the browser is already running but can open a new tab
if(!err && options.opensTab) {
instance.running = true;
}

return callback(null, instance);
});
} else {
callback(null, getInstance());
Expand Down
15 changes: 10 additions & 5 deletions lib/local/platform/macos.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = {
process: 'Google Chrome',
versionKey: 'KSVersion',
defaultLocation: '/Applications/Google Chrome.app',
args: ['--args']
args: ['--args'],
opensTab: true
},
canary: {
pathQuery: 'mdfind \'kMDItemDisplayName == "Google Chrome Canary" && kMDItemKind == Application\'',
Expand All @@ -17,7 +18,8 @@ module.exports = {
process: 'Google Chrome Canary',
versionKey: 'KSVersion',
defaultLocation: '/Applications/Google Chrome Canary.app',
args: ['--args']
args: ['--args'],
opensTab: true
},
firefox: {
pathQuery: 'mdfind \'kMDItemDisplayName == "Firefox" && kMDItemKind == Application\'',
Expand All @@ -26,7 +28,8 @@ module.exports = {
process: 'firefox',
versionKey: 'CFBundleGetInfoString',
defaultLocation: '/Applications/Firefox.app',
args: ['--args']
args: ['--args'],
opensTab: true
},
aurora: {
pathQuery: 'mdfind \'kMDItemDisplayName == "FirefoxAurora" && kMDItemKind == Application\'',
Expand All @@ -35,7 +38,8 @@ module.exports = {
process: 'firefox',
versionKey: 'CFBundleGetInfoString',
defaultLocation: '/Applications/FirefoxAurora.app',
args: ['--args']
args: ['--args'],
opensTab: true
},
opera: {
pathQuery: 'mdfind \'kMDItemDisplayName == "Opera" && kMDItemKind == Application\'',
Expand All @@ -52,7 +56,8 @@ module.exports = {
command: 'open',
process: 'Safari',
versionKey: 'CFBundleShortVersionString',
defaultLocation: '/Applications/Safari.app'
defaultLocation: '/Applications/Safari.app',
opensTab: true
},
phantom: {
pathQuery: 'which phantomjs',
Expand Down
6 changes: 4 additions & 2 deletions lib/local/platform/unix.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ var path = require('path');
module.exports = {
chrome: {
pathQuery: 'which google-chrome',
process: 'chrome'
process: 'chrome',
opensTab: true
},
firefox: {
pathQuery: 'which firefox',
process: 'firefox'
process: 'firefox',
opensTab: true
},
opera: {
pathQuery: 'which opera',
Expand Down
9 changes: 6 additions & 3 deletions lib/local/platform/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ module.exports = {
chrome: {
defaultLocation: path.join(appData, 'Google', 'Chrome', 'Application', 'chrome.exe') ,
pathQuery: 'dir /s /b chrome.exe',
cwd: cwd
cwd: cwd,
opensTab: true
},
canary: {
defaultLocation: path.join(appData, 'Google', 'Chrome SxS', 'Application', 'chrome.exe')
},
firefox: {
defaultLocation: path.join(programFiles, 'Mozilla Firefox', 'firefox.exe'),
pathQuery: 'dir /s /b firefox.exe',
cwd: cwd
cwd: cwd,
opensTab: true
},
aurora: {
defaultLocation: path.join(programFiles, 'Aurora', 'firefox.exe')
defaultLocation: path.join(programFiles, 'Aurora', 'firefox.exe'),
opensTab: true
},
opera: {
defaultLocation: path.join(programFiles, 'Opera', 'launcher.exe'),
Expand Down