Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: corrupt preferences auto reset #1818

Merged
merged 2 commits into from
Aug 29, 2024
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
37 changes: 11 additions & 26 deletions src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ define(function (require, exports, module) {
require("NodeConnector");
require("command/KeyboardOverlayMode");
require("editor/EditorManager");
require("project/FileViewController");

// Load dependent modules
const AppInit = require("utils/AppInit"),
LanguageManager = require("language/LanguageManager"),
ProjectManager = require("project/ProjectManager"),
FileViewController = require("project/FileViewController"),
FileSyncManager = require("project/FileSyncManager"),
Commands = require("command/Commands"),
CommandManager = require("command/CommandManager"),
Expand All @@ -95,8 +95,8 @@ define(function (require, exports, module) {
DeprecationWarning = require("utils/DeprecationWarning"),
ViewCommandHandlers = require("view/ViewCommandHandlers"),
NotificationUI = require("widgets/NotificationUI"),
MainViewManager = require("view/MainViewManager"),
Metrics = require("utils/Metrics");
require("view/MainViewManager");

window.EventManager = EventManager; // Main event intermediary between brackets and other web pages.
/**
Expand Down Expand Up @@ -361,34 +361,19 @@ define(function (require, exports, module) {
if (PreferencesManager._isUserScopeCorrupt()) {
const userPrefFullPath = PreferencesManager.getUserPrefFile();
// user scope can get corrupt only if the file exists, is readable,
// but malformed. no need to check for its existance.
const info = MainViewManager.findInAllWorkingSets(userPrefFullPath);
let paneId;
if (info.length) {
paneId = info[0].paneId;
}
// but malformed. no need to check for its existence.
Metrics.countEvent(Metrics.EVENT_TYPE.STORAGE, "prefs.corrupt", "startup");
FileViewController.openFileAndAddToWorkingSet(userPrefFullPath, paneId)
.done(function () {
Dialogs.showModalDialog(
DefaultDialogs.DIALOG_ID_ERROR,
Strings.ERROR_PREFS_CORRUPT_TITLE,
Strings.ERROR_PREFS_CORRUPT
).done(function () {
// give the focus back to the editor with the pref file
MainViewManager.focusActivePane();
});
});
let file = FileSystem.getFileForPath(userPrefFullPath);
file.unlinkAsync().finally(function () {
Dialogs.showModalDialog(
DefaultDialogs.DIALOG_ID_ERROR,
Strings.ERROR_PREFS_RESET_TITLE,
Strings.ERROR_PREFS_CORRUPT_RESET
);
});
}
});
});

// See if any startup files were passed to the application
if (brackets.app.getPendingFilesToOpen) {
brackets.app.getPendingFilesToOpen(function (err, paths) {
DragAndDrop.openDroppedFiles(paths);
});
}
});
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ define({

// Application preferences corrupt error strings
"ERROR_PREFS_CORRUPT_TITLE": "Error Reading Preferences",
"ERROR_PREFS_RESET_TITLE": "Settings Reset - Restart Required",
"ERROR_PREFS_PROJECT_LINT": "Project Preferences",
"ERROR_PREFS_PROJECT_LINT_MESSAGE": "Error: The project contains both `.brackets.json` and `.phcode.json` files, causing a conflict. Please delete either `.brackets.json` or `.phcode.json` and then reload the project.",
"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.",
"ERROR_PREFS_CORRUPT_RESET": "Your {APP_NAME} settings were damaged and have been reset. Please restart {APP_NAME} for the changes to take effect.",
"ERROR_PROJ_PREFS_CORRUPT": "Your project preferences file is not valid JSON. The file will be opened so that you can correct the format. You will need to reload the project for the changes to take effect.",

// Application error strings
Expand Down
Loading