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

Stabilize preferences initialization #6719

Merged
merged 12 commits into from
Feb 26, 2014
16 changes: 14 additions & 2 deletions src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ define(function (require, exports, module) {
$testDiv.remove();
}

// Load default languages
LanguageManager.ready.always(function () {
// Load default languages and preferences
Async.waitForAll([LanguageManager.ready, PreferencesManager.ready]).always(function () {
// Load all extensions. This promise will complete even if one or more
// extensions fail to load.
var extensionPathOverride = params.get("extensions"); // used by unit tests
Expand Down Expand Up @@ -239,6 +239,18 @@ define(function (require, exports, module) {
AppInit._dispatchReady(AppInit.APP_READY);

PerfUtils.addMeasurement("Application Startup");

if (PreferencesManager._isUserScopeCorrupt()) {
Dialogs.showModalDialog(
DefaultDialogs.DIALOG_ID_ERROR,
Strings.ERROR_PREFS_CORRUPT_TITLE,
Strings.ERROR_PREFS_CORRUPT
)
.done(function () {
CommandManager.execute(Commands.FILE_OPEN_PREFERENCES);
});
}

});

// See if any startup files were passed to the application
Expand Down
1 change: 1 addition & 0 deletions src/command/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ define(function (require, exports, module) {
exports.FILE_DELETE = "file.delete"; // DocumentCommandHandlers.js handleFileDelete()
exports.FILE_EXTENSION_MANAGER = "file.extensionManager"; // ExtensionManagerDialog.js _showDialog()
exports.FILE_REFRESH = "file.refresh"; // ProjectManager.js refreshFileTree()
exports.FILE_OPEN_PREFERENCES = "file.openPreferences"; // PreferencesManager.js _handleOpenPreferences()

// File shell callbacks - string must MATCH string in native code (appshell/command_callbacks.h)
exports.FILE_CLOSE_WINDOW = "file.close_window"; // DocumentCommandHandlers.js handleFileCloseWindow()
Expand Down
23 changes: 2 additions & 21 deletions src/extensions/default/DebugCommands/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ define(function (require, exports, module) {
DEBUG_SWITCH_LANGUAGE = "debug.switchLanguage",
DEBUG_ENABLE_NODE_DEBUGGER = "debug.enableNodeDebugger",
DEBUG_LOG_NODE_STATE = "debug.logNodeState",
DEBUG_RESTART_NODE = "debug.restartNode",
DEBUG_OPEN_PREFERENCES = "debug.openPreferences";
DEBUG_RESTART_NODE = "debug.restartNode";

function handleShowDeveloperTools() {
brackets.app.showDeveloperTools();
Expand Down Expand Up @@ -230,23 +229,6 @@ define(function (require, exports, module) {
});
}


function handleOpenPreferences() {
var fullPath = PreferencesManager.getUserPrefFile(),
file = FileSystem.getFileForPath(fullPath);
file.exists(function (err, doesExist) {
if (doesExist) {
CommandManager.execute(Commands.FILE_OPEN, { fullPath: fullPath });
} else {
FileUtils.writeText(file, "", true)
.done(function () {
CommandManager.execute(Commands.FILE_OPEN, { fullPath: fullPath });
});
}
});

}

/* Register all the command handlers */

// Show Developer Tools (optionally enabled)
Expand All @@ -267,7 +249,6 @@ define(function (require, exports, module) {
CommandManager.register(Strings.CMD_ENABLE_NODE_DEBUGGER, DEBUG_ENABLE_NODE_DEBUGGER, NodeDebugUtils.enableDebugger);
CommandManager.register(Strings.CMD_LOG_NODE_STATE, DEBUG_LOG_NODE_STATE, NodeDebugUtils.logNodeState);
CommandManager.register(Strings.CMD_RESTART_NODE, DEBUG_RESTART_NODE, NodeDebugUtils.restartNode);
CommandManager.register(Strings.CMD_OPEN_PREFERENCES, DEBUG_OPEN_PREFERENCES, handleOpenPreferences);

enableRunTestsMenuItem();

Expand All @@ -288,7 +269,7 @@ define(function (require, exports, module) {
menu.addMenuItem(DEBUG_ENABLE_NODE_DEBUGGER);
menu.addMenuItem(DEBUG_LOG_NODE_STATE);
menu.addMenuItem(DEBUG_RESTART_NODE);
menu.addMenuItem(DEBUG_OPEN_PREFERENCES);
menu.addMenuItem(Commands.FILE_OPEN_PREFERENCES); // this command is defined in core, but exposed only in Debug menu for now

// exposed for convenience, but not official API
exports._runUnitTests = _runUnitTests;
Expand Down
5 changes: 5 additions & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ define({
"ERROR_CREATING_FILE_TITLE" : "Error creating {0}",
"ERROR_CREATING_FILE" : "An error occurred when trying to create the {0} <span class='dialog-filename'>{1}</span>. {2}",

// Application preferences corrupt error strings
"ERROR_PREFS_CORRUPT_TITLE" : "Preferences file is corrupt",
"ERROR_PREFS_CORRUPT" : "{APP_NAME} preferences file is not a valid JSON and cannot be parsed. It will now be opened so that you could fix it. You will need to restart or reload {APP_NAME} for the changes to take effect.",
Copy link
Contributor

Choose a reason for hiding this comment

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

How about something like:

"ERROR_PREFS_CORRUPT_TITLE"         : "Error reading preferences",
"ERROR_PREFS_CORRUPT"               : "Your preferences file is not valid JSON. The file will be opened so that you can correct the format. You will need to restart {APP_NAME} for the changes to take effect.",



// Application error strings
"ERROR_IN_BROWSER_TITLE" : "Oops! {APP_NAME} doesn't run in browsers yet.",
"ERROR_IN_BROWSER" : "{APP_NAME} is built in HTML, but right now it runs as a desktop app so you can use it to edit local files. Please use the application shell in the <b>github.com/adobe/brackets-shell</b> repo to run {APP_NAME}.",
Expand Down
Loading