-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Show reason why live preview was cancelled #2178
Changes from 8 commits
44e5857
ae70684
c8d0d9f
a6e1508
b2983b4
e3621a2
8a60c7a
559b923
b47baf5
c672e0b
60e6a36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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))); | ||
|
@@ -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} | ||
|
@@ -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(); | ||
|
@@ -506,8 +498,9 @@ define(function LiveDevelopment(require, exports, module) { | |
|
||
function reconnect() { | ||
unloadAgents(); | ||
var promises = loadAgents(); | ||
|
||
_setStatus(STATUS_LOADING_AGENTS); | ||
var promises = loadAgents(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
||
|
@@ -802,7 +795,6 @@ define(function LiveDevelopment(require, exports, module) { | |
} | ||
} | ||
|
||
$(Inspector.Inspector).on("detached", _onDetached); | ||
$(Inspector.Page).on("frameNavigated.DOMAgent", _onFrameNavigated); | ||
|
||
waitForInterstitialPageLoad() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also consider removing the data here as you do in There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
@@ -131,6 +135,32 @@ define(function main(require, exports, module) { | |
} | ||
} | ||
|
||
/** Triggered by Inspector.detached */ | ||
function _onDetached(event, res) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
|
@@ -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(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some wording suggestions for this and the following:
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>?", | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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