Skip to content

Commit

Permalink
Quit without clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasstrba committed Apr 12, 2024
1 parent c631833 commit 0a29cbb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
17 changes: 13 additions & 4 deletions DuckDuckGo/Application/AutoClearHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions DuckDuckGo/Common/Extensions/NSAlertExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/Common/Localizables/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 13 additions & 1 deletion DuckDuckGo/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -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" : {
Expand Down Expand Up @@ -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" : {
Expand Down

0 comments on commit 0a29cbb

Please sign in to comment.