From 0a29cbbea4d9af164f35d9a05a35759263f948ad Mon Sep 17 00:00:00 2001 From: Tomas Strba Date: Fri, 12 Apr 2024 16:23:32 +0200 Subject: [PATCH] Quit without clearing --- DuckDuckGo/Application/AutoClearHandler.swift | 17 +++++++++++++---- .../Common/Extensions/NSAlertExtension.swift | 4 +--- DuckDuckGo/Common/Localizables/UserText.swift | 3 ++- DuckDuckGo/Localizable.xcstrings | 14 +++++++++++++- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/DuckDuckGo/Application/AutoClearHandler.swift b/DuckDuckGo/Application/AutoClearHandler.swift index 1ed2bf4837..2d247cb21f 100644 --- a/DuckDuckGo/Application/AutoClearHandler.swift +++ b/DuckDuckGo/Application/AutoClearHandler.swift @@ -35,8 +35,17 @@ final class AutoClearHandler { func handleAppTermination() -> NSApplication.TerminateReply? { guard preferences.isAutoClearEnabled else { return nil } - if preferences.isWarnBeforeClearingEnabled, !confirmAutoClear() { - return .terminateCancel + if preferences.isWarnBeforeClearingEnabled { + switch confirmAutoClear() { + case .alertFirstButtonReturn: + performAutoClear() + return .terminateLater + case .alertSecondButtonReturn: + appTerminationHandledCorrectly = true + return .terminateNow + default: + return .terminateCancel + } } performAutoClear() @@ -49,10 +58,10 @@ final class AutoClearHandler { // MARK: - Private - private func confirmAutoClear() -> Bool { + private func confirmAutoClear() -> NSApplication.ModalResponse { let alert = NSAlert.autoClearAlert() let response = alert.runModal() - return response == .alertFirstButtonReturn + return response } @MainActor diff --git a/DuckDuckGo/Common/Extensions/NSAlertExtension.swift b/DuckDuckGo/Common/Extensions/NSAlertExtension.swift index 84706ba09a..dcf298a733 100644 --- a/DuckDuckGo/Common/Extensions/NSAlertExtension.swift +++ b/DuckDuckGo/Common/Extensions/NSAlertExtension.swift @@ -221,9 +221,9 @@ extension NSAlert { alert.alertStyle = .warning alert.icon = .burnAlert alert.addButton(withTitle: UserText.clearAndQuit) + alert.addButton(withTitle: UserText.quitWithoutClearing) alert.addButton(withTitle: UserText.cancel) - // Create a checkbox let checkbox = NSButton(checkboxWithTitle: UserText.warnBeforeQuitDialogCheckboxMessage, target: DataClearingPreferences.shared, action: #selector(DataClearingPreferences.toggleWarnBeforeClearing)) @@ -234,13 +234,11 @@ extension NSAlert { let containerView = NSView(frame: NSRect(x: 0, y: 0, width: 224, height: 25)) containerView.addSubview(checkbox) - // Constraints for the checkbox within the container NSLayoutConstraint.activate([ checkbox.centerXAnchor.constraint(equalTo: containerView.centerXAnchor), checkbox.centerYAnchor.constraint(equalTo: containerView.centerYAnchor, constant: -10) // Slightly up for better visual alignment ]) - // Set the container view as the accessoryView alert.accessoryView = containerView return alert diff --git a/DuckDuckGo/Common/Localizables/UserText.swift b/DuckDuckGo/Common/Localizables/UserText.swift index d5aefcfdf4..8b7d04b190 100644 --- a/DuckDuckGo/Common/Localizables/UserText.swift +++ b/DuckDuckGo/Common/Localizables/UserText.swift @@ -53,7 +53,8 @@ struct UserText { static let pasteAndGo = NSLocalizedString("paste.and.go", value: "Paste & Go", comment: "Paste & Go button") static let pasteAndSearch = NSLocalizedString("paste.and.search", value: "Paste & Search", comment: "Paste & Search button") static let clear = NSLocalizedString("clear", value: "Clear", comment: "Clear button") - static let clearAndQuit = NSLocalizedString("clear.and.quit", value: "Clear and Quit", comment: "button to Clear data and quit the application") + static let clearAndQuit = NSLocalizedString("clear.and.quit", value: "Clear and Quit", comment: "Button to clear data and quit the application") + static let quitWithoutClearing = NSLocalizedString("quit.without.clearing", value: "Quit without Clearing", comment: "Button to quit the application without clearing data") static let `continue` = NSLocalizedString("`continue`", value: "Continue", comment: "Continue button") static let bookmarkDialogAdd = NSLocalizedString("bookmark.dialog.add", value: "Add", comment: "Button to confim a bookmark creation") static let newFolderDialogAdd = NSLocalizedString("folder.dialog.add", value: "Add", comment: "Button to confim a bookmark folder creation") diff --git a/DuckDuckGo/Localizable.xcstrings b/DuckDuckGo/Localizable.xcstrings index c271ecddb3..2a77fa27ae 100644 --- a/DuckDuckGo/Localizable.xcstrings +++ b/DuckDuckGo/Localizable.xcstrings @@ -10719,7 +10719,7 @@ } }, "clear.and.quit" : { - "comment" : "button to Clear data and quit the application", + "comment" : "Button to clear data and quit the application", "extractionState" : "extracted_with_value", "localizations" : { "en" : { @@ -45765,6 +45765,18 @@ } } }, + "quit.without.clearing" : { + "comment" : "Button to quit the application without clearing data", + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Quit without Clearing" + } + } + } + }, "Recently Closed" : { "comment" : "Main Menu History item", "localizations" : {