Skip to content

Commit

Permalink
api
Browse files Browse the repository at this point in the history
  • Loading branch information
Subash committed Oct 21, 2019
1 parent bcb4196 commit 750d987
Show file tree
Hide file tree
Showing 5 changed files with 4,823 additions and 21 deletions.
21 changes: 9 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,34 @@ async function getAvailableBrowsers() {
const list = [];
for(const browser of Object.keys(browsers)) {
const exec = await getExecutable(browser);
if(exec) list.push(browser);
if(exec) list.push({ browser, path: exec });
}
return list;
}

async function openBrowser(browser, address) {
async function launchBrowser(browser, address) {
const options = {
detached: true,
env: process.env
};

// Use open command to open browsers in macOS
// use open command to open browsers in macOS
if(process.platform === 'darwin') {
spawn('open', [ '-a', browser, address ], options);
spawn('open', [ '-a', browser.browser, address ], options);
return;
}

// Edge can not be started by running the executable
if(browser === 'Edge') {
// edge can not be started by running the executable
if(browser.browser === 'Edge') {
spawn(`start microsoft-edge:"${address}"`, { ...options, shell: true });
return;
}

//Spawn the executable
const exec = await getExecutable(browser);
if(exec) spawn(exec, [ address ], options);
// spawn the executable
spawn(browser.path, [ address ], options);
}

module.exports = {
getAvailableBrowsers,
getInstalledBrowsers: getAvailableBrowsers, // legacy api
getExecutable,
openBrowser
launchBrowser
};
Loading

0 comments on commit 750d987

Please sign in to comment.