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

After extension is updated/removed, reload Brackets instead of quitting #6487

Merged
merged 6 commits into from
Jan 14, 2014
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions src/command/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ define(function (require, exports, module) {
exports.HELP_ABOUT = "help.about"; // HelpCommandHandlers.js _handleAboutDialog()

// APP
exports.APP_RELOAD = "app.reload"; // DocumentCommandHandlers.js handleReload()
exports.APP_RELOAD_WITHOUT_EXTS = "app.reload_without_exts"; // DocumentCommandHandlers.js handleReloadWithoutExts()

// File shell callbacks - string must MATCH string in native code (appshell/command_callbacks.h)
exports.APP_ABORT_QUIT = "app.abort_quit"; // DocumentCommandHandlers.js _handleAbortQuit()
exports.APP_BEFORE_MENUPOPUP = "app.before_menupopup"; // DocumentCommandHandlers.js _handleBeforeMenuPopup()
exports.APP_ABORT_QUIT = "app.abort_quit"; // DocumentCommandHandlers.js handleAbortQuit()
exports.APP_BEFORE_MENUPOPUP = "app.before_menupopup"; // DocumentCommandHandlers.js handleBeforeMenuPopup()
});

153 changes: 143 additions & 10 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean "WebSocket", correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, "WebSocket".


define(function (require, exports, module) {
"use strict";

var _ = require("thirdparty/lodash");

// Load dependent modules
var AppInit = require("utils/AppInit"),
CommandManager = require("command/CommandManager"),
Expand All @@ -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.)
Expand Down Expand Up @@ -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");
}

Expand Down Expand Up @@ -1372,13 +1378,138 @@ 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 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("status-user-exts", $indicator, true);
console.log("Brackets reloaded with extensions disabled");
}

// Init DOM elements
_$titleContainerToolbar = $("#titlebar");
_$titleWrapper = $(".title-wrapper", _$titleContainerToolbar);
_$title = $(".title", _$titleWrapper);
_$dirtydot = $(".dirty-dot", _$titleWrapper);

});

// Exported for unit testing only
Expand Down Expand Up @@ -1414,10 +1545,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);
Expand Down
20 changes: 10 additions & 10 deletions src/extensibility/ExtensionManagerDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ define(function (require, exports, module) {
return;
}

var buttonLabel = Strings.CHANGE_AND_QUIT;
var buttonLabel = Strings.CHANGE_AND_RELOAD;
if (hasRemovedExtensions && !hasUpdatedExtensions) {
buttonLabel = Strings.REMOVE_AND_QUIT;
buttonLabel = Strings.REMOVE_AND_RELOAD;
} else if (hasUpdatedExtensions && !hasRemovedExtensions) {
buttonLabel = Strings.UPDATE_AND_QUIT;
buttonLabel = Strings.UPDATE_AND_RELOAD;
}

var dlg = Dialogs.showModalDialog(
DefaultDialogs.DIALOG_ID_CHANGE_EXTENSIONS,
Strings.CHANGE_AND_QUIT_TITLE,
Strings.CHANGE_AND_QUIT_MESSAGE,
Strings.CHANGE_AND_RELOAD_TITLE,
Strings.CHANGE_AND_RELOAD_MESSAGE,
[
{
className : Dialogs.DIALOG_BTN_CLASS_NORMAL,
Expand Down Expand Up @@ -103,7 +103,7 @@ define(function (require, exports, module) {
ExtensionManager.updateExtensions()
.done(function () {
dlg.close();
CommandManager.execute(Commands.FILE_QUIT);
CommandManager.execute(Commands.APP_RELOAD);
})
.fail(function (errorArray) {
dlg.close();
Expand All @@ -126,8 +126,8 @@ define(function (require, exports, module) {
Strings.EXTENSION_MANAGER_UPDATE,
StringUtils.format(Strings.EXTENSION_MANAGER_UPDATE_ERROR, ids.join(", "))
).done(function () {
// We still have to quit even if some of the removals failed.
CommandManager.execute(Commands.FILE_QUIT);
// We still have to reload even if some of the removals failed.
CommandManager.execute(Commands.APP_RELOAD);
});
});
})
Expand All @@ -144,8 +144,8 @@ define(function (require, exports, module) {
Strings.EXTENSION_MANAGER_REMOVE,
StringUtils.format(Strings.EXTENSION_MANAGER_REMOVE_ERROR, ids.join(", "))
).done(function () {
// We still have to quit even if some of the removals failed.
CommandManager.execute(Commands.FILE_QUIT);
// We still have to reload even if some of the removals failed.
CommandManager.execute(Commands.APP_RELOAD);
});
});
} else {
Expand Down
Loading