From f6fcac585682d1ba6ee8f1b23cc1476b963453ea Mon Sep 17 00:00:00 2001 From: Louis Pontoise Date: Tue, 8 Nov 2022 14:31:26 +0100 Subject: [PATCH] feat: avoid accidental press of the "reset preferences" button (#2093) closes #2093 --- resources/l10n/Localizable.strings | 6 ++++++ src/ui/preferences-window/tabs/GeneralTab.swift | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/resources/l10n/Localizable.strings b/resources/l10n/Localizable.strings index d6d48e71..9244c9c9 100644 --- a/resources/l10n/Localizable.strings +++ b/resources/l10n/Localizable.strings @@ -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:"; @@ -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."; diff --git a/src/ui/preferences-window/tabs/GeneralTab.swift b/src/ui/preferences-window/tabs/GeneralTab.swift index 993b034a..fccfeb3d 100644 --- a/src/ui/preferences-window/tabs/GeneralTab.swift +++ b/src/ui/preferences-window/tabs/GeneralTab.swift @@ -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 { @@ -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