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

Commit

Permalink
Merge pull request #10558 from humphd/configurable-launcher
Browse files Browse the repository at this point in the history
Make LiveDevMultiBrowser's Launcher instance configurable via public set Launcher() method
  • Loading branch information
busykai committed Mar 12, 2015
2 parents f9d7d41 + 7bc69e4 commit ddc760b
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/LiveDevelopment/LiveDevMultiBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,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 @@ -114,6 +114,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 @@ -515,7 +521,7 @@ define(function (require, exports, module) {
// open default browser
// TODO: fail?
//
Launcher.launch(url);
_launcher.launch(url);
}

/**
Expand Down Expand Up @@ -789,6 +795,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 @@ -804,6 +827,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 @@ -908,4 +934,5 @@ define(function (require, exports, module) {
exports.getServerBaseUrl = getServerBaseUrl;
exports.getCurrentProjectServerConfig = getCurrentProjectServerConfig;
exports.setTransport = setTransport;
exports.setLauncher = setLauncher;
});

0 comments on commit ddc760b

Please sign in to comment.