Skip to content

Commit

Permalink
Copy changed
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasstrba committed Apr 12, 2024
1 parent f997036 commit 4aa5d52
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 109 deletions.
28 changes: 14 additions & 14 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
1D01A3DA2B88DF8B00FE8150 /* PreferencesSyncView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D01A3D72B88DF8B00FE8150 /* PreferencesSyncView.swift */; };
1D02633628D8A9A9005CBB41 /* BWEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D02633528D8A9A9005CBB41 /* BWEncryption.m */; settings = {COMPILER_FLAGS = "-Wno-deprecated -Wno-strict-prototypes"; }; };
1D074B272909A433006E4AC3 /* PasswordManagerCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D074B262909A433006E4AC3 /* PasswordManagerCoordinator.swift */; };
1D0E4F562BB419ED00670CFE /* BurnOnQuitHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D0E4F552BB419ED00670CFE /* BurnOnQuitHandler.swift */; };
1D0E4F572BB419ED00670CFE /* BurnOnQuitHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D0E4F552BB419ED00670CFE /* BurnOnQuitHandler.swift */; };
1D0E4F582BB419ED00670CFE /* BurnOnQuitHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D0E4F552BB419ED00670CFE /* BurnOnQuitHandler.swift */; };
1D0E4F562BB419ED00670CFE /* AutoClearHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D0E4F552BB419ED00670CFE /* AutoClearHandler.swift */; };
1D0E4F572BB419ED00670CFE /* AutoClearHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D0E4F552BB419ED00670CFE /* AutoClearHandler.swift */; };
1D0E4F582BB419ED00670CFE /* AutoClearHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D0E4F552BB419ED00670CFE /* AutoClearHandler.swift */; };
1D12F2E2298BC660009A65FD /* InternalUserDeciderStoreMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D12F2E1298BC660009A65FD /* InternalUserDeciderStoreMock.swift */; };
1D1A33492A6FEB170080ACED /* BurnerMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1A33482A6FEB170080ACED /* BurnerMode.swift */; };
1D1A334A2A6FEB170080ACED /* BurnerMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1A33482A6FEB170080ACED /* BurnerMode.swift */; };
Expand Down Expand Up @@ -72,8 +72,8 @@
1D43EB38292B636E0065E5D6 /* BWCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D43EB37292B636E0065E5D6 /* BWCommand.swift */; };
1D43EB3A292B63B00065E5D6 /* BWRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D43EB39292B63B00065E5D6 /* BWRequest.swift */; };
1D43EB3C292B664A0065E5D6 /* BWMessageIdGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D43EB3B292B664A0065E5D6 /* BWMessageIdGenerator.swift */; };
1D5FADA22BC7E734005D6EB1 /* BurnOnQuitHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D5FADA12BC7E734005D6EB1 /* BurnOnQuitHandlerTests.swift */; };
1D5FADA32BC7E734005D6EB1 /* BurnOnQuitHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D5FADA12BC7E734005D6EB1 /* BurnOnQuitHandlerTests.swift */; };
1D5FADA22BC7E734005D6EB1 /* AutoClearHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D5FADA12BC7E734005D6EB1 /* AutoClearHandlerTests.swift */; };
1D5FADA32BC7E734005D6EB1 /* AutoClearHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D5FADA12BC7E734005D6EB1 /* AutoClearHandlerTests.swift */; };
1D6216B229069BBF00386B2C /* BWKeyStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D6216B129069BBF00386B2C /* BWKeyStorage.swift */; };
1D69C553291302F200B75945 /* BWVault.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D69C552291302F200B75945 /* BWVault.swift */; };
1D6A492029CF7A490011DF74 /* NSPopoverExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A491F29CF7A490011DF74 /* NSPopoverExtension.swift */; };
Expand Down Expand Up @@ -3573,7 +3573,7 @@
1D02633428D8A9A9005CBB41 /* BWEncryption.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BWEncryption.h; sourceTree = "<group>"; };
1D02633528D8A9A9005CBB41 /* BWEncryption.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BWEncryption.m; sourceTree = "<group>"; };
1D074B262909A433006E4AC3 /* PasswordManagerCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordManagerCoordinator.swift; sourceTree = "<group>"; };
1D0E4F552BB419ED00670CFE /* BurnOnQuitHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BurnOnQuitHandler.swift; sourceTree = "<group>"; };
1D0E4F552BB419ED00670CFE /* AutoClearHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoClearHandler.swift; sourceTree = "<group>"; };
1D12F2E1298BC660009A65FD /* InternalUserDeciderStoreMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InternalUserDeciderStoreMock.swift; sourceTree = "<group>"; };
1D1A33482A6FEB170080ACED /* BurnerMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BurnerMode.swift; sourceTree = "<group>"; };
1D1C36E229FAE8DA001FA40C /* FaviconManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FaviconManagerTests.swift; sourceTree = "<group>"; };
Expand All @@ -3597,7 +3597,7 @@
1D43EB37292B636E0065E5D6 /* BWCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BWCommand.swift; sourceTree = "<group>"; };
1D43EB39292B63B00065E5D6 /* BWRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BWRequest.swift; sourceTree = "<group>"; };
1D43EB3B292B664A0065E5D6 /* BWMessageIdGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BWMessageIdGenerator.swift; sourceTree = "<group>"; };
1D5FADA12BC7E734005D6EB1 /* BurnOnQuitHandlerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BurnOnQuitHandlerTests.swift; sourceTree = "<group>"; };
1D5FADA12BC7E734005D6EB1 /* AutoClearHandlerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AutoClearHandlerTests.swift; sourceTree = "<group>"; };
1D6216B129069BBF00386B2C /* BWKeyStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BWKeyStorage.swift; sourceTree = "<group>"; };
1D69C552291302F200B75945 /* BWVault.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BWVault.swift; sourceTree = "<group>"; };
1D6A491F29CF7A490011DF74 /* NSPopoverExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSPopoverExtension.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6975,7 +6975,7 @@
isa = PBXGroup;
children = (
85F1B0C825EF9759004792B6 /* URLEventHandlerTests.swift */,
1D5FADA12BC7E734005D6EB1 /* BurnOnQuitHandlerTests.swift */,
1D5FADA12BC7E734005D6EB1 /* AutoClearHandlerTests.swift */,
0289041E2A7B23CE0028369C /* AppConfigurationURLProviderTests.swift */,
);
path = AppDelegate;
Expand Down Expand Up @@ -7179,7 +7179,7 @@
858A798226A8B75F00A75A42 /* CopyHandler.swift */,
1D36E65A298ACD2900AA485D /* AppIconChanger.swift */,
CB24F70B29A3D9CB006DCC58 /* AppConfigurationURLProvider.swift */,
1D0E4F552BB419ED00670CFE /* BurnOnQuitHandler.swift */,
1D0E4F552BB419ED00670CFE /* AutoClearHandler.swift */,
);
path = Application;
sourceTree = "<group>";
Expand Down Expand Up @@ -10949,7 +10949,7 @@
3706FC52293F65D500E42796 /* MouseOverAnimationButton.swift in Sources */,
B60293E72BA19ECD0033186B /* NetPPopoverManagerMock.swift in Sources */,
3706FC53293F65D500E42796 /* TabBarScrollView.swift in Sources */,
1D0E4F572BB419ED00670CFE /* BurnOnQuitHandler.swift in Sources */,
1D0E4F572BB419ED00670CFE /* AutoClearHandler.swift in Sources */,
B6104E9C2BA9C173008636B2 /* DownloadResumeData.swift in Sources */,
3706FC54293F65D500E42796 /* BookmarkListTreeControllerDataSource.swift in Sources */,
3706FC55293F65D500E42796 /* AddressBarViewController.swift in Sources */,
Expand Down Expand Up @@ -11223,7 +11223,7 @@
3706FE46293F661700E42796 /* EncryptedValueTransformerTests.swift in Sources */,
9F3910632B68C35600CB5112 /* DownloadsTabExtensionTests.swift in Sources */,
3706FE47293F661700E42796 /* URLExtensionTests.swift in Sources */,
1D5FADA32BC7E734005D6EB1 /* BurnOnQuitHandlerTests.swift in Sources */,
1D5FADA32BC7E734005D6EB1 /* AutoClearHandlerTests.swift in Sources */,
1DB9617B29F1D06D00CF5568 /* InternalUserDeciderMock.swift in Sources */,
317295D52AF058D3002C3206 /* MockWaitlistFeatureSetupHandler.swift in Sources */,
3706FE48293F661700E42796 /* PixelTests.swift in Sources */,
Expand Down Expand Up @@ -12043,7 +12043,7 @@
4B957AF12AC7AE700062CA31 /* AppStateRestorationManager.swift in Sources */,
4B957AF22AC7AE700062CA31 /* DailyPixel.swift in Sources */,
9FDA6C232B79A59D00E099A9 /* BookmarkFavoriteView.swift in Sources */,
1D0E4F582BB419ED00670CFE /* BurnOnQuitHandler.swift in Sources */,
1D0E4F582BB419ED00670CFE /* AutoClearHandler.swift in Sources */,
4B957AF32AC7AE700062CA31 /* NavigationHotkeyHandler.swift in Sources */,
B6CC266E2BAD9CD800F53F8D /* FileProgressPresenter.swift in Sources */,
4B957AF42AC7AE700062CA31 /* ClickToLoadUserScript.swift in Sources */,
Expand Down Expand Up @@ -12471,7 +12471,7 @@
B6A9E48426146AAB0067D1B9 /* PixelParameters.swift in Sources */,
AA5FA697275F90C400DCE9C9 /* FaviconImageCache.swift in Sources */,
1430DFF524D0580F00B8978C /* TabBarViewController.swift in Sources */,
1D0E4F562BB419ED00670CFE /* BurnOnQuitHandler.swift in Sources */,
1D0E4F562BB419ED00670CFE /* AutoClearHandler.swift in Sources */,
B62B483E2ADE48DE000DECE5 /* ArrayBuilder.swift in Sources */,
4B92929B26670D2A00AD2C21 /* BookmarkOutlineViewDataSource.swift in Sources */,
56D145EB29E6C99B00E3488A /* DataImportStatusProviding.swift in Sources */,
Expand Down Expand Up @@ -13334,7 +13334,7 @@
85F487B5276A8F2E003CE668 /* OnboardingTests.swift in Sources */,
B626A7642992506A00053070 /* SerpHeadersNavigationResponderTests.swift in Sources */,
AA652CCE25DD9071009059CC /* BookmarkListTests.swift in Sources */,
1D5FADA22BC7E734005D6EB1 /* BurnOnQuitHandlerTests.swift in Sources */,
1D5FADA22BC7E734005D6EB1 /* AutoClearHandlerTests.swift in Sources */,
859E7D6D274548F2009C2B69 /* BookmarksExporterTests.swift in Sources */,
B6A5A2A825BAA35500AA7ADA /* WindowManagerStateRestorationTests.swift in Sources */,
B6AE39F129373AF200C37AA4 /* EmptyAttributionRulesProver.swift in Sources */,
Expand Down
16 changes: 8 additions & 8 deletions DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
let internalUserDecider: InternalUserDecider
let featureFlagger: FeatureFlagger
private var appIconChanger: AppIconChanger!
private var burnOnQuitHandler: BurnOnQuitHandler!
private var autoClearHandler: AutoClearHandler!

private(set) var syncDataProviders: SyncDataProviders!
private(set) var syncService: DDGSyncing?
Expand Down Expand Up @@ -313,7 +313,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {

#endif

setUpBurnOnQuitHandler()
setUpAutoClearHandler()
}

func applicationDidBecomeActive(_ notification: Notification) {
Expand Down Expand Up @@ -352,7 +352,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
stateRestorationManager?.applicationWillTerminate()

// Handling of "Burn on quit"
if let terminationReply = burnOnQuitHandler.handleAppTermination() {
if let terminationReply = autoClearHandler.handleAppTermination() {
return terminationReply
}

Expand Down Expand Up @@ -556,11 +556,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
}
}

private func setUpBurnOnQuitHandler() {
burnOnQuitHandler = BurnOnQuitHandler(preferences: .shared, fireViewModel: FireCoordinator.fireViewModel)
burnOnQuitHandler.burnOnStartIfNeeded()
burnOnQuitHandler.resetTheFlag()
burnOnQuitHandler.onBurnOnQuitCompleted = {
private func setUpAutoClearHandler() {
autoClearHandler = AutoClearHandler(preferences: .shared, fireViewModel: FireCoordinator.fireViewModel)
autoClearHandler.burnOnStartIfNeeded()
autoClearHandler.resetTheFlag()
autoClearHandler.onAutoClearCompleted = {
NSApplication.shared.reply(toApplicationShouldTerminate: true)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// BurnOnQuitHandler.swift
// AutoClearHandler.swift
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
Expand All @@ -19,7 +19,7 @@
import Foundation
import Combine

final class BurnOnQuitHandler {
final class AutoClearHandler {

private let preferences: DataClearingPreferences
private let fireViewModel: FireViewModel
Expand All @@ -29,17 +29,17 @@ final class BurnOnQuitHandler {
self.fireViewModel = fireViewModel
}

var onBurnOnQuitCompleted: (() -> Void)?
var onAutoClearCompleted: (() -> Void)?

@MainActor
func handleAppTermination() -> NSApplication.TerminateReply? {
guard preferences.isBurnDataOnQuitEnabled else { return nil }
guard preferences.isAutoClearEnabled else { return nil }

if preferences.isWarnBeforeClearingEnabled, !confirmBurnOnQuit() {
if preferences.isWarnBeforeClearingEnabled, !confirmAutoClear() {
return .terminateCancel
}

performBurnOnQuit()
performAutoClear()
return .terminateLater
}

Expand All @@ -49,17 +49,17 @@ final class BurnOnQuitHandler {

// MARK: - Private

private func confirmBurnOnQuit() -> Bool {
let alert = NSAlert.burnOnQuitAlert()
private func confirmAutoClear() -> Bool {
let alert = NSAlert.autoClearAlert()
let response = alert.runModal()
return response == .alertFirstButtonReturn
}

@MainActor
private func performBurnOnQuit() {
private func performAutoClear() {
fireViewModel.fire.burnAll { [weak self] in
self?.appTerminationHandledCorrectly = true
self?.onBurnOnQuitCompleted?()
self?.onAutoClearCompleted?()
}
}

Expand All @@ -72,7 +72,7 @@ final class BurnOnQuitHandler {
@MainActor
@discardableResult
func burnOnStartIfNeeded() -> Bool {
let shouldBurnOnStart = preferences.isBurnDataOnQuitEnabled && !appTerminationHandledCorrectly
let shouldBurnOnStart = preferences.isAutoClearEnabled && !appTerminationHandledCorrectly
guard shouldBurnOnStart else { return false }

fireViewModel.fire.burnAll()
Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/Common/Extensions/NSAlertExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ extension NSAlert {
return alert
}

static func burnOnQuitAlert() -> NSAlert {
static func autoClearAlert() -> NSAlert {
let alert = NSAlert()
alert.messageText = UserText.warnBeforeQuitDialogHeader
alert.informativeText = UserText.warnBeforeQuitDialogMessage
//TODO checkbox

Check failure on line 221 in DuckDuckGo/Common/Extensions/NSAlertExtension.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Prefer at least one space after slashes for comments (comment_spacing)

Check failure on line 221 in DuckDuckGo/Common/Extensions/NSAlertExtension.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

TODOs should be resolved (checkbox) (todo)
alert.alertStyle = .warning
alert.icon = .burnAlert
alert.addButton(withTitle: UserText.clear)
Expand Down
19 changes: 9 additions & 10 deletions DuckDuckGo/Common/Localizables/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1045,18 +1045,17 @@ struct UserText {
static let fireproofCheckboxTitle = NSLocalizedString("fireproof.checkbox.title", value: "Ask to Fireproof websites when signing in", comment: "Fireproof settings checkbox title")
static let fireproofExplanation = NSLocalizedString("fireproof.explanation", value: "When you Fireproof a site, cookies won't be erased and you'll stay signed in, even after using the Fire Button.", comment: "Fireproofing mechanism explanation")
static let manageFireproofSites = NSLocalizedString("fireproof.manage-sites", value: "Manage Fireproof Sites…", comment: "Fireproof settings button caption")
static let automaticallyClearData = NSLocalizedString("automatically.clear.data", value: "Automatically Clear", comment: "Header of a section in Settings. The setting configures clearing data automatically after quitting the app.")
static let burnDataOnQuit = NSLocalizedString("burn.data.on.quit", value: "Clear Data upon Quitting", comment: "Label after the checkbox in Settings which configures clearing data automatically after quitting the app.")
static let burnDataOnQuitExplanation = NSLocalizedString("burn.data.on.quit.explanation", value: "Data from \"Fireproofed\" sites won't be cleared, keeping your essential logins and preferences intact.", comment: "Explanation of a setting which configures clearing data automatically after quitting the app.")
static let warnBeforeQuit = NSLocalizedString("warn.before.quit", value: "Warn before Quit", comment: "Label after the checkbox in Settings which configures a warning before clearing data on the application termination.")
static let warnBeforeQuitDialogHeader = NSLocalizedString("warn.before.quit.dialog.header", value: "Quit the application and \nclear all data?", comment: "A header of warning before clearing data on the application termination.")
static let warnBeforeQuitDialogMessage = NSLocalizedString("warn.before.quit.dialog.message", value: "Cookies and site data for all sites will be cleared, unless the site is Fireproof.", comment: "A warning before clearing data on the application termination.")

static func disableBurnOnQuitToEnableSessionRestore() -> String {
let localized = NSLocalizedString("disable.burn.on.quit.to.enable.session.restore",
static let autoClear = NSLocalizedString("auto.clear", value: "Auto-Clear", comment: "Header of a section in Settings. The setting configures clearing data automatically after quitting the app.")
static let automaticallyClearData = NSLocalizedString("automatically.clear.data", value: "Automatically clear browsing data when DuckDuckGo quits", comment: "Label after the checkbox in Settings which configures clearing data automatically after quitting the app.")
static let warnBeforeQuit = NSLocalizedString("warn.before.quit", value: "Warn me that data will be cleared when quitting", comment: "Label after the checkbox in Settings which configures a warning before clearing data on the application termination.")
static let warnBeforeQuitDialogHeader = NSLocalizedString("warn.before.quit.dialog.header", value: "Clear browsing data and quit\nDuckDuckGo?", comment: "A header of warning before clearing data on the application termination.")
static let warnBeforeQuitDialogCheckboxMessage = NSLocalizedString("warn.before.quit.dialog.checkbox.message", value: "Warn me every time", comment: "A label after checkbox to configure the warning before clearing data on the application termination.")

static func disableAutoClearToEnableSessionRestore() -> String {
let localized = NSLocalizedString("disable.auto.clear.to.enable.session.restore",
value: "Disable the %@ setting to enable session restore on startup.",
comment: "Information label in Settings. It tells user that to enable session restoration setting they have to disable burn on quit")
return String(format: localized, automaticallyClearData)
return String(format: localized, autoClear)
}
static func showDataClearingSettings() -> String {
let localized = NSLocalizedString("show.data.clearing.settings",
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/Common/Utilities/UserDefaultsWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public struct UserDefaultsWrapper<T> {
case grammarCheckEnabledOnce = "grammar.check.enabled.once"

case loginDetectionEnabled = "fireproofing.login-detection-enabled"
case burnDataOnQuitEnabled = "preferences.burn-data-on-quit-enabled"
case autoClearEnabled = "preferences.auto-clear-enabled"
case warnBeforeClearingEnabled = "preferences.warn-before-clearing-enabled"
case clearDataAfter = "preferences.clear-data-after"
case gpcEnabled = "preferences.gpc-enabled"
Expand Down
Loading

0 comments on commit 4aa5d52

Please sign in to comment.