Skip to content

Commit

Permalink
feat: avoid accidental press of the "reset preferences" button (#2093)
Browse files Browse the repository at this point in the history
closes #2093
  • Loading branch information
lwouis committed Nov 8, 2022
1 parent d4f1154 commit f6fcac5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions resources/l10n/Localizable.strings
Expand Up @@ -247,6 +247,9 @@
/* No comment provided by engineer. */
"Reset preferences and restart" = "Reset preferences and restart";

/* No comment provided by engineer. */
"Reset preferences and restart…" = "Reset preferences and restart…";

/* No comment provided by engineer. */
"Rows of thumbnails:" = "Rows of thumbnails:";

Expand Down Expand Up @@ -394,5 +397,8 @@
/* No comment provided by engineer. */
"Window title truncation:" = "Window title truncation:";

/* No comment provided by engineer. */
"You can’t undo this action." = "You can’t undo this action.";

/* No comment provided by engineer. */
"You didn’t write your email, thus can’t receive any response." = "You didn’t write your email, thus can’t receive any response.";
15 changes: 12 additions & 3 deletions src/ui/preferences-window/tabs/GeneralTab.swift
Expand Up @@ -4,7 +4,7 @@ class GeneralTab {
static func initTab() -> NSView {
let startAtLogin = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Start at login:", comment: ""), "startAtLogin", extraAction: startAtLoginCallback)
let menubarIcon = LabelAndControl.makeLabelWithDropdown(NSLocalizedString("Menubar icon:", comment: ""), "menubarIcon", MenubarIconPreference.allCases, extraAction: Menubar.menubarIconCallback)
let resetPreferences = Button(NSLocalizedString("Reset preferences and restart", comment: "")) { _ in GeneralTab.resetPreferences() }
let resetPreferences = Button(NSLocalizedString("Reset preferences and restart", comment: "")) { _ in GeneralTab.resetPreferences() }
if #available(OSX 11, *) { resetPreferences.hasDestructiveAction = true }
let menubarIconDropdown = menubarIcon[1] as! NSPopUpButton
for i in 0...2 {
Expand All @@ -31,8 +31,17 @@ class GeneralTab {
}

static func resetPreferences() {
Preferences.resetAll()
App.app.restart()
let alert = NSAlert()
alert.alertStyle = .critical
alert.messageText = ""
alert.informativeText = NSLocalizedString("You can’t undo this action.", comment: "")
alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
let resetButton = alert.addButton(withTitle: NSLocalizedString("Reset preferences and restart", comment: ""))
if #available(OSX 11, *) { resetButton.hasDestructiveAction = true }
if alert.runModal() == .alertSecondButtonReturn {
Preferences.resetAll()
App.app.restart()
}
}

/// add/remove plist file in ~/Library/LaunchAgents/ depending on the checkbox state
Expand Down

0 comments on commit f6fcac5

Please sign in to comment.