This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
After extension is updated/removed, reload Brackets instead of quitting #6487
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7875aa7
After an extension is updated/removed, reload Brackets instead of qui…
lkcampbell 7d8ce45
Small cleanups. Move reload functions to DocumentCommandHandlers.
lkcampbell a4347e5
Small cleanups. Update string constant names.
lkcampbell f86246f
Roll back incorrect changes on translation strings
lkcampbell 5adb2ea
Small code clean up
lkcampbell a583cd4
Update ExtensionManager unit tests and small clean up
lkcampbell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,11 +23,13 @@ | |
|
|
||
|
|
||
| /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, regexp: true */ | ||
| /*global define, $, brackets, window */ | ||
| /*global define, $, brackets, window, WebSocket */ | ||
|
|
||
| define(function (require, exports, module) { | ||
| "use strict"; | ||
|
|
||
| var _ = require("thirdparty/lodash"); | ||
|
|
||
| // Load dependent modules | ||
| var AppInit = require("utils/AppInit"), | ||
| CommandManager = require("command/CommandManager"), | ||
|
|
@@ -50,7 +52,11 @@ define(function (require, exports, module) { | |
| DragAndDrop = require("utils/DragAndDrop"), | ||
| PerfUtils = require("utils/PerfUtils"), | ||
| KeyEvent = require("utils/KeyEvent"), | ||
| LanguageManager = require("language/LanguageManager"); | ||
| LanguageManager = require("language/LanguageManager"), | ||
| Inspector = require("LiveDevelopment/Inspector/Inspector"), | ||
| Menus = require("command/Menus"), | ||
| UrlParams = require("utils/UrlParams").UrlParams, | ||
| StatusBar = require("widgets/StatusBar"); | ||
|
|
||
| /** | ||
| * Handlers for commands related to document handling (opening, saving, etc.) | ||
|
|
@@ -1221,15 +1227,15 @@ define(function (require, exports, module) { | |
| * @private | ||
| * Implementation for abortQuit callback to reset quit sequence settings | ||
| */ | ||
| function _handleAbortQuit() { | ||
| function handleAbortQuit() { | ||
| _windowGoingAway = false; | ||
| } | ||
|
|
||
| /** | ||
| * @private | ||
| * Implementation for native APP_BEFORE_MENUPOPUP callback to trigger beforeMenuPopup event | ||
| */ | ||
| function _handleBeforeMenuPopup() { | ||
| function handleBeforeMenuPopup() { | ||
| $(PopUpManager).triggerHandler("beforeMenuPopup"); | ||
| } | ||
|
|
||
|
|
@@ -1372,13 +1378,143 @@ define(function (require, exports, module) { | |
| } | ||
| } | ||
|
|
||
| // Init DOM elements | ||
| /** | ||
| * Disables Brackets' cache via the remote debugging protocol. | ||
| * @return {$.Promise} A jQuery promise that will be resolved when the cache is disabled and be rejected in any other case | ||
| */ | ||
| function _disableCache() { | ||
| var result = new $.Deferred(); | ||
|
|
||
| if (brackets.inBrowser) { | ||
| result.resolve(); | ||
| } else { | ||
| var port = brackets.app.getRemoteDebuggingPort ? brackets.app.getRemoteDebuggingPort() : 9234; | ||
| Inspector.getDebuggableWindows("127.0.0.1", port) | ||
| .fail(result.reject) | ||
| .done(function (response) { | ||
| var page = response[0]; | ||
| if (!page || !page.webSocketDebuggerUrl) { | ||
| result.reject(); | ||
| return; | ||
| } | ||
| var _socket = new WebSocket(page.webSocketDebuggerUrl); | ||
| // Disable the cache | ||
| _socket.onopen = function _onConnect() { | ||
| _socket.send(JSON.stringify({ id: 1, method: "Network.setCacheDisabled", params: { "cacheDisabled": true } })); | ||
| }; | ||
| // The first message will be the confirmation => disconnected to allow remote debugging of Brackets | ||
| _socket.onmessage = function _onMessage(e) { | ||
| _socket.close(); | ||
| result.resolve(); | ||
| }; | ||
| // In case of an error | ||
| _socket.onerror = result.reject; | ||
| }); | ||
| } | ||
|
|
||
| return result.promise(); | ||
| } | ||
|
|
||
| /** | ||
| * Does a full reload of the browser window | ||
| * @param {string} href The url to reload into the window | ||
| */ | ||
| function browserReload(href) { | ||
| return CommandManager.execute(Commands.FILE_CLOSE_ALL, { promptOnly: true }).done(function () { | ||
| // Give everyone a chance to save their state - but don't let any problems block | ||
| // us from quitting | ||
| try { | ||
| $(ProjectManager).triggerHandler("beforeAppClose"); | ||
| } catch (ex) { | ||
| console.error(ex); | ||
| } | ||
|
|
||
| // Disable the cache to make reloads work | ||
| _disableCache().always(function () { | ||
| // Remove all menus to assure every part of Brackets is reloaded | ||
| _.forEach(Menus.getAllMenus(), function (value, key) { | ||
| Menus.removeMenu(key); | ||
| }); | ||
|
|
||
| window.location.href = href; | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| function handleReload() { | ||
| var href = window.location.href, | ||
| params = new UrlParams(); | ||
|
|
||
| // Make sure the Reload Without User Extensions parameter is removed | ||
| params.parse(); | ||
|
|
||
| if (params.get("reloadWithoutUserExts")) { | ||
| params.remove("reloadWithoutUserExts"); | ||
| } | ||
|
|
||
| if (href.indexOf("?") !== -1) { | ||
| href = href.substring(0, href.indexOf("?")); | ||
| } | ||
|
|
||
| if (!params.isEmpty()) { | ||
| href += "?" + params.toString(); | ||
| } | ||
|
|
||
| // Give Mac native menus extra time to update shortcut highlighting. | ||
| // Prevents the menu highlighting from getting messed up after reload. | ||
| window.setTimeout(function () { | ||
| browserReload(href); | ||
| }, 100); | ||
| } | ||
|
|
||
| function handleReloadWithoutExts() { | ||
| var href = window.location.href, | ||
| params = new UrlParams(); | ||
|
|
||
| params.parse(); | ||
|
|
||
| if (!params.get("reloadWithoutUserExts")) { | ||
| params.put("reloadWithoutUserExts", true); | ||
| } | ||
|
|
||
| if (href.indexOf("?") !== -1) { | ||
| href = href.substring(0, href.indexOf("?")); | ||
| } | ||
|
|
||
| href += "?" + params.toString(); | ||
|
|
||
| // Give Mac native menus extra time to update shortcut highlighting. | ||
| // Prevents the menu highlighting from getting messed up after reload. | ||
| window.setTimeout(function () { | ||
| browserReload(href); | ||
| }, 100); | ||
| } | ||
|
|
||
| AppInit.htmlReady(function () { | ||
| // If in Reload Without User Extensions mode, update UI and log console message | ||
| var USER_EXT_STATUS_ID = "status-user-exts"; | ||
|
Contributor
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. Doesn't seem like there's any benefit to putting "status-user-exts" in a local variable since it's only used once.
Contributor
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, I see it was already like this and you just moved it, so I'll leave it to your discretion.
Contributor
Author
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. No, that's all me, old file and new file. I wrote it like that out of force of habit, throwing hard-wired strings into a constant. I can change it. |
||
|
|
||
| var params = new UrlParams(), | ||
| $icon = $("#toolbar-extension-manager"), | ||
| $indicator = $("<div>" + Strings.STATUSBAR_USER_EXTENSIONS_DISABLED + "</div>"); | ||
|
|
||
| params.parse(); | ||
|
|
||
| if (params.get("reloadWithoutUserExts") === "true") { | ||
| CommandManager.get(Commands.FILE_EXTENSION_MANAGER).setEnabled(false); | ||
| $icon.css({display: "none"}); | ||
| StatusBar.addIndicator(USER_EXT_STATUS_ID, $indicator, true); | ||
| console.log("Brackets reloaded with extensions disabled"); | ||
| } else { | ||
| CommandManager.get(Commands.FILE_EXTENSION_MANAGER).setEnabled(true); | ||
| // Toolbar and status bar reload back to default states, no need to set | ||
| } | ||
|
|
||
| // Init DOM elements | ||
| _$titleContainerToolbar = $("#titlebar"); | ||
| _$titleWrapper = $(".title-wrapper", _$titleContainerToolbar); | ||
| _$title = $(".title", _$titleWrapper); | ||
| _$dirtydot = $(".dirty-dot", _$titleWrapper); | ||
|
|
||
| }); | ||
|
|
||
| // Exported for unit testing only | ||
|
|
@@ -1414,10 +1550,12 @@ define(function (require, exports, module) { | |
| CommandManager.register(Strings.CMD_SHOW_IN_TREE, Commands.NAVIGATE_SHOW_IN_FILE_TREE, handleShowInTree); | ||
| CommandManager.register(Strings.CMD_SHOW_IN_OS, Commands.NAVIGATE_SHOW_IN_OS, handleShowInOS); | ||
|
|
||
| // Those commands have no UI representation, and are only used internally | ||
| CommandManager.registerInternal(Commands.APP_ABORT_QUIT, _handleAbortQuit); | ||
| CommandManager.registerInternal(Commands.APP_BEFORE_MENUPOPUP, _handleBeforeMenuPopup); | ||
| CommandManager.registerInternal(Commands.FILE_CLOSE_WINDOW, handleFileCloseWindow); | ||
| // These commands have no UI representation and are only used internally | ||
| CommandManager.registerInternal(Commands.APP_ABORT_QUIT, handleAbortQuit); | ||
| CommandManager.registerInternal(Commands.APP_BEFORE_MENUPOPUP, handleBeforeMenuPopup); | ||
| CommandManager.registerInternal(Commands.FILE_CLOSE_WINDOW, handleFileCloseWindow); | ||
| CommandManager.registerInternal(Commands.APP_RELOAD, handleReload); | ||
| CommandManager.registerInternal(Commands.APP_RELOAD_WITHOUT_EXTS, handleReloadWithoutExts); | ||
|
|
||
| // Listen for changes that require updating the editor titlebar | ||
| $(DocumentManager).on("dirtyFlagChange", handleDirtyChange); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't think this and a few other changes to this file were not made by you, so it looks like a bad merge.
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.
Nevermind -- I see you had to also move the
disableCache()code.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.
You should remove
"Mustache""WebSocket" from the jslint global define list in DebugCommands/main.js.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.
I think you mean "WebSocket" since "Mustache" is still required in DebugCommands.
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.
You mean "WebSocket", correct?
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.
Yes, "WebSocket".