Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Make LiveDevMultiBrowser's Launcher instance configurable via public set Launcher() method #10558

Merged
merged 2 commits into from Mar 12, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/LiveDevelopment/LiveDevMultiBrowser.js
Expand Up @@ -87,7 +87,7 @@ define(function (require, exports, module) {
LiveDevServerManager = require("LiveDevelopment/LiveDevServerManager"),
NodeSocketTransport = require("LiveDevelopment/MultiBrowserImpl/transports/NodeSocketTransport"),
LiveDevProtocol = require("LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol"),
Launcher = require("LiveDevelopment/MultiBrowserImpl/launchers/Launcher");
DefaultLauncher = require("LiveDevelopment/MultiBrowserImpl/launchers/Launcher");

// Documents
var LiveCSSDocument = require("LiveDevelopment/MultiBrowserImpl/documents/LiveCSSDocument"),
Expand All @@ -113,6 +113,12 @@ define(function (require, exports, module) {
* Protocol handler that provides the actual live development API on top of the current transport.
*/
var _protocol = LiveDevProtocol;

/**
* @private
* Current browser launcher for preview.
*/
var _launcher;

/**
* @private
Expand Down Expand Up @@ -525,7 +531,7 @@ define(function (require, exports, module) {
// open default browser
// TODO: fail?
//
Launcher.launch(url);
_launcher.launch(url);
}

/**
Expand Down Expand Up @@ -799,6 +805,23 @@ define(function (require, exports, module) {
_protocol.setTransport(transport);
}

/**
* Sets the current browser launcher mechanism to be used by live development
* (e.g., default browser, iframe-based browser, etc.)
* The launcher must provide the following method:
*
* - launch(url): Launch the given URL in the appropriate browser.
*
* @param {{launch: function(string)}} launcher
*/
function setLauncher(launcher) {
if (!(launcher && launcher.launch)) {
console.log("Invalid launcher object: ", launcher, new Error("LiveDevMultiBrowser.setLauncher()"));
return;
}
_launcher = launcher;
}

/**
* Initialize the LiveDevelopment module.
*/
Expand All @@ -814,6 +837,9 @@ define(function (require, exports, module) {
// Default transport for live connection messages - can be changed
setTransport(NodeSocketTransport);

// Default launcher for preview browser - can be changed
setLauncher(DefaultLauncher);

// Initialize exports.status
_setStatus(STATUS_INACTIVE);
}
Expand Down Expand Up @@ -918,4 +944,5 @@ define(function (require, exports, module) {
exports.getServerBaseUrl = getServerBaseUrl;
exports.getCurrentProjectServerConfig = getCurrentProjectServerConfig;
exports.setTransport = setTransport;
exports.setLauncher = setLauncher;
});