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

Show reason why live preview was cancelled #2178

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 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
2 changes: 2 additions & 0 deletions src/LiveDevelopment/Inspector/Inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ define(function Inspector(require, exports, module) {
* -> Inspector.domain.command()
*/
function init(theConfig) {
var result = new $.Deferred();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is never used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, overlooked this when refactoring


exports.config = theConfig;

var InspectorText = require("text!LiveDevelopment/Inspector/Inspector.json"),
Expand Down
14 changes: 3 additions & 11 deletions src/LiveDevelopment/LiveDevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ define(function LiveDevelopment(require, exports, module) {
var _liveDocument; // the document open for live editing.
var _relatedDocuments; // CSS and JS documents that are used by the live HTML document
var _serverProvider; // current LiveDevServerProvider

function _isHtmlFileExt(ext) {
return (FileUtils.isStaticHtmlFileExt(ext) ||
(ProjectManager.getBaseUrl() && FileUtils.isServerHtmlFileExt(ext)));
Expand Down Expand Up @@ -454,13 +454,6 @@ define(function LiveDevelopment(require, exports, module) {
});
}

/** Triggered by Inspector.detached */
function _onDetached(event, res) {
// res.reason, e.g. "replaced_with_devtools", "target_closed", "canceled_by_user"
// Sample list taken from https://chromiumcodereview.appspot.com/10947037/patch/12001/13004
// However, the link refers to the Chrome Extension API, it may not apply 100% to the Inspector API
}

// WebInspector Event: Page.frameNavigated
function _onFrameNavigated(event, res) {
// res = {frame}
Expand Down Expand Up @@ -496,7 +489,6 @@ define(function LiveDevelopment(require, exports, module) {

/** Triggered by Inspector.disconnect */
function _onDisconnect(event) {
$(Inspector.Inspector).off("detached", _onDetached);
$(Inspector.Page).off("frameNavigated.DOMAgent", _onFrameNavigated);

unloadAgents();
Expand All @@ -506,8 +498,9 @@ define(function LiveDevelopment(require, exports, module) {

function reconnect() {
unloadAgents();
var promises = loadAgents();

_setStatus(STATUS_LOADING_AGENTS);
var promises = loadAgents();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but is there a reason you wanted to move this? It looks harmless, but so much of Live Development startup is fragile that I'm always a little hesitant to move things around :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In onInterstitialPageLoad we do it in the same order, and that made sense to me, so I did this for consistency. I'll be daring and leave it in :)

$.when.apply(undefined, promises).done(_onLoad).fail(_onError);
}

Expand Down Expand Up @@ -802,7 +795,6 @@ define(function LiveDevelopment(require, exports, module) {
}
}

$(Inspector.Inspector).on("detached", _onDetached);
$(Inspector.Page).on("frameNavigated.DOMAgent", _onFrameNavigated);

waitForInterstitialPageLoad()
Expand Down
34 changes: 34 additions & 0 deletions src/LiveDevelopment/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ define(function main(require, exports, module) {
Dialogs = require("widgets/Dialogs"),
UrlParams = require("utils/UrlParams").UrlParams,
Strings = require("strings"),
StringUtils = require("utils/StringUtils"),
ExtensionUtils = require("utils/ExtensionUtils");

var prefs;
Expand Down Expand Up @@ -113,6 +114,9 @@ define(function main(require, exports, module) {

/** Toggles LiveDevelopment and synchronizes the state of UI elements that reports LiveDevelopment status */
function _handleGoLiveCommand() {
// Hide the tooltip that shows the reason why live preview was cancelled
_$btnGoLive.twipsy("hide");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also consider removing the data here as you do in _onDetached(), just to clean it up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed things now so that this happens anyway


if (LiveDevelopment.status >= LiveDevelopment.STATUS_CONNECTING) {
LiveDevelopment.close();
} else {
Expand All @@ -131,6 +135,32 @@ define(function main(require, exports, module) {
}
}

/** Triggered by Inspector.detached */
function _onDetached(event, res) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this gets called whenever the connection is closed--in particular, it also gets called if the user manually switches off Live Development in Brackets. In that case, we shouldn't show the disconnection tooltip. If there's some state that we already set before starting to close the connection, we could just check that and not show the error when we actually get the detach message. If not, we might have to add a flag somewhere for this (and clear the flag when we get the detach message).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decoupled the two tings a bit now: LiveDevelopment.js manages a _closeReason that is influenced by the detach events and gets passed along when the status changes to inactive. In main.js, this is then passed to _showStatusChangeReason (formerly _onDetached).
I added "navigated_away" as a new reason that we generate ourselves.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and the reason when clicking the button is "explicit" and for that no twipsy is shown.

// Get the explanation using res.reason, e.g. "replaced_with_devtools", "target_closed", "canceled_by_user"
// Examples taken from https://chromiumcodereview.appspot.com/10947037/patch/12001/13004
// However, the link refers to the Chrome Extension API, it may not apply 100% to the Inspector API
var reason = Strings["LIVE_DEV_" + res.reason.toUpperCase()];
if (!reason) {
reason = StringUtils.format(Strings.LIVE_DEV_DETACHED_UNKNOWN_REASON, res.reason);
}

// Tooltip options
var options = {
placement: "below",
trigger: "manual",
autoHideDelay: 5000,
title: function () {
return reason;
}
};

// Destroy the previous twipsy (options are not updated otherwise)
_$btnGoLive.twipsy("hide").removeData("twipsy");
// Show a tooltip explaning why live preview was cancelled
_$btnGoLive.twipsy(options).twipsy("show");
}

/** Create the menu item "Go Live" */
function _setupGoLiveButton() {
_$btnGoLive = $("#toolbar-go-live");
Expand Down Expand Up @@ -183,11 +213,15 @@ define(function main(require, exports, module) {
window.report = function report(params) { window.params = params; console.info(params); };
}

function _onInspectorDone() {
}

/** Initialize LiveDevelopment */
AppInit.appReady(function () {
params.parse();

Inspector.init(config);
$(Inspector.Inspector).on("detached", _onDetached);
LiveDevelopment.init(config);
_loadStyles();
_setupGoLiveButton();
Expand Down
1 change: 1 addition & 0 deletions src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ define(function (require, exports, module) {
// Load dependent non-module scripts
require("widgets/bootstrap-dropdown");
require("widgets/bootstrap-modal");
require("widgets/bootstrap-twipsy-mod");
require("thirdparty/path-utils/path-utils.min");
require("thirdparty/smart-auto-complete/jquery.smart_autocomplete");

Expand Down
3 changes: 3 additions & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ define({
"LIVE_DEV_STATUS_TIP_PROGRESS2" : "Live Preview: Initializing\u2026",
"LIVE_DEV_STATUS_TIP_CONNECTED" : "Disconnect Live Preview",
"LIVE_DEV_STATUS_TIP_OUT_OF_SYNC" : "Live Preview: Click to disconnect (Save file to update)",
"LIVE_DEV_REPLACED_WITH_DEVTOOLS" : "Live Preview was cancelled by opening Chrome's Developer Tools",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some wording suggestions for this and the following:

Live Preview was cancelled because the browser's developer tools were opened
Live Preview was cancelled because the page was closed in the browser

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I used those!

"LIVE_DEV_TARGET_CLOSED" : "Live Preview was cancelled by closing the page",
"LIVE_DEV_DETACHED_UNKNOWN_REASON" : "Live Preview was cancelled for an unknown reason ({0})",

"SAVE_CLOSE_TITLE" : "Save Changes",
"SAVE_CLOSE_MESSAGE" : "Do you want to save the changes you made in the document <span class='dialog-filename'>{0}</span>?",
Expand Down
6 changes: 6 additions & 0 deletions src/styles/brackets_patterns_override.less
Original file line number Diff line number Diff line change
Expand Up @@ -490,4 +490,10 @@
-o-user-select: text;
user-select: text;
}
}

/* Twipsy tooltips */
.twipsy-inner {
max-width: none;
white-space: nowrap;
}
Loading