function _browserErrToFileError(err) {
if (err === brackets.fs.ERR_NOT_FOUND) {
return FileSystemError.NOT_FOUND;
}
// All other errors are mapped to the generic "unknown" error
return FileSystemError.UNKNOWN;
}
var liveBrowserOpenedPIDs = [];
closeAllLiveBrowsers Closes all the browsers that were tracked on open TODO: does not seem to work on Windows
function closeAllLiveBrowsers() {
//make a copy incase the array is edited as we iterate
var closeIDs = liveBrowserOpenedPIDs.concat();
return Async.doSequentially(closeIDs, closeLiveBrowser, false);
}
closeLiveBrowser
function closeLiveBrowser(pid) {
var result = new $.Deferred();
if (isNaN(pid)) {
pid = 0;
}
brackets.app.closeLiveBrowser(function (err) {
if (!err) {
var i = liveBrowserOpenedPIDs.indexOf(pid);
if (i !== -1) {
liveBrowserOpenedPIDs.splice(i, 1);
}
result.resolve();
} else {
result.reject(_browserErrToFileError(err));
}
}, pid);
return result.promise();
}
openLiveBrowser Open the given URL in the user's system browser, optionally enabling debugging.
function openLiveBrowser(url, enableRemoteDebugging) {
var result = new $.Deferred();
brackets.app.openLiveBrowser(url, !!enableRemoteDebugging, function onRun(err, pid) {
if (!err) {
// Undefined ids never get removed from list, so don't push them on
if (pid !== undefined) {
liveBrowserOpenedPIDs.push(pid);
}
result.resolve(pid);
} else {
result.reject(_browserErrToFileError(err));
}
});
return result.promise();
}
Opens a URL in the system default browser
function openURLInDefaultBrowser(url) {
brackets.app.openURLInDefaultBrowser(url);
}
// Define public API
exports.openLiveBrowser = openLiveBrowser;
exports.closeLiveBrowser = closeLiveBrowser;
exports.closeAllLiveBrowsers = closeAllLiveBrowsers;
exports.openURLInDefaultBrowser = openURLInDefaultBrowser;
});