Skip to content
This repository has been archived by the owner on Feb 24, 2025. It is now read-only.

one-click Fire Button setting #2968

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DuckDuckGo/Common/Utilities/UserDefaultsWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public struct UserDefaultsWrapper<T> {
case loginDetectionEnabled = "fireproofing.login-detection-enabled"
case autoClearEnabled = "preferences.auto-clear-enabled"
case warnBeforeClearingEnabled = "preferences.warn-before-clearing-enabled"
case oneClickFireButton = "preferences.one-click-fire-button"
case gpcEnabled = "preferences.gpc-enabled"
case selectedDownloadLocationKey = "preferences.download-location"
case lastUsedCustomDownloadLocation = "preferences.custom-last-used-download-location"
Expand Down
20 changes: 15 additions & 5 deletions DuckDuckGo/Fire/View/FireCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//

import Cocoa
import PixelKit

@MainActor
final class FireCoordinator {
Expand Down Expand Up @@ -46,16 +47,25 @@ final class FireCoordinator {

if waitForOpening {
DispatchQueue.main.asyncAfter(deadline: .now() + 1/3) {
showFirePopover(relativeTo: mainViewController.tabBarViewController.fireButton,
tabCollectionViewModel: mainViewController.tabCollectionViewModel)
continueFireButtonActionAfterOpeningWindow(positioningView: mainViewController.tabBarViewController.fireButton,
tabCollectionViewModel: mainViewController.tabCollectionViewModel)
}
} else {
showFirePopover(relativeTo: mainViewController.tabBarViewController.fireButton,
tabCollectionViewModel: mainViewController.tabCollectionViewModel)
continueFireButtonActionAfterOpeningWindow(positioningView: mainViewController.tabBarViewController.fireButton,
tabCollectionViewModel: mainViewController.tabCollectionViewModel)
}
}

static func showFirePopover(relativeTo positioningView: NSView, tabCollectionViewModel: TabCollectionViewModel) {
private static func continueFireButtonActionAfterOpeningWindow(positioningView: NSView, tabCollectionViewModel: TabCollectionViewModel) {
if DataClearingPreferences.shared.oneClickFireButton {
PixelKit.fire(GeneralPixel.fireButton(option: .allSites))
fireViewModel.fire.burnAll()
} else {
showFirePopover(relativeTo: positioningView, tabCollectionViewModel: tabCollectionViewModel)
}
}

private static func showFirePopover(relativeTo positioningView: NSView, tabCollectionViewModel: TabCollectionViewModel) {
guard !(firePopover?.isShown ?? false) else {
firePopover?.close()
return
Expand Down
1 change: 0 additions & 1 deletion DuckDuckGo/Fire/View/FirePopoverViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ final class FirePopoverViewController: NSViewController {
@IBAction func clearButtonAction(_ sender: Any) {
delegate?.firePopoverViewControllerDidClear(self)
firePopoverViewModel.burn()

}

@IBAction func cancelButtonAction(_ sender: Any) {
Expand Down
11 changes: 11 additions & 0 deletions DuckDuckGo/Preferences/Model/DataClearingPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ final class DataClearingPreferences: ObservableObject, PreferencesTabOpening {
isWarnBeforeClearingEnabled.toggle()
}

@Published
var oneClickFireButton: Bool {
didSet {
persistor.oneClickFireButton = oneClickFireButton
}
}

@MainActor
func presentManageFireproofSitesDialog() {
let fireproofDomainsWindowController = FireproofDomainsViewController.create().wrappedInWindowController()
Expand All @@ -69,6 +76,7 @@ final class DataClearingPreferences: ObservableObject, PreferencesTabOpening {
isLoginDetectionEnabled = persistor.loginDetectionEnabled
isAutoClearEnabled = persistor.autoClearEnabled
isWarnBeforeClearingEnabled = persistor.warnBeforeClearingEnabled
oneClickFireButton = persistor.oneClickFireButton
}

private var persistor: FireButtonPreferencesPersistor
Expand All @@ -77,6 +85,7 @@ final class DataClearingPreferences: ObservableObject, PreferencesTabOpening {
protocol FireButtonPreferencesPersistor {
var loginDetectionEnabled: Bool { get set }
var autoClearEnabled: Bool { get set }
var oneClickFireButton: Bool { get set }
var warnBeforeClearingEnabled: Bool { get set }
}

Expand All @@ -91,6 +100,8 @@ struct FireButtonPreferencesUserDefaultsPersistor: FireButtonPreferencesPersisto
@UserDefaultsWrapper(key: .warnBeforeClearingEnabled, defaultValue: false)
var warnBeforeClearingEnabled: Bool

@UserDefaultsWrapper(key: .oneClickFireButton, defaultValue: false)
var oneClickFireButton: Bool
}

extension Notification.Name {
Expand Down
23 changes: 21 additions & 2 deletions DuckDuckGo/Preferences/View/PreferencesDataClearingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension Preferences {
var body: some View {
PreferencePane(UserText.dataClearing) {

// SECTION 1: Automatically Clear Data
// SECTION: Automatically Clear Data
PreferencePaneSection(UserText.autoClear) {

PreferencePaneSubSection {
Expand All @@ -41,7 +41,19 @@ extension Preferences {

}

// SECTION 2: Fireproof Site
// SECTION: Fire Window
PreferencePaneSection(UserText.dataClearing) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to change the section name


PreferencePaneSubSection {
ToggleMenuItem("One-click Fire button", isOn: $model.oneClickFireButton)
VStack(alignment: .leading, spacing: 1) {
TextMenuItemCaption("When active hitting the Fire Button will clear data with no extra dialogs")
}
}

}

// SECTION: Fireproof Site
PreferencePaneSection(UserText.fireproofSites) {

PreferencePaneSubSection {
Expand All @@ -65,3 +77,10 @@ extension Preferences {
}
}
}

#Preview {
ScrollView {
Preferences.DataClearingView(model: .shared)
.padding()
}
}
1 change: 1 addition & 0 deletions UnitTests/Preferences/DataClearingPreferencesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MockFireButtonPreferencesPersistor: FireButtonPreferencesPersistor {
var autoClearEnabled: Bool = false
var warnBeforeClearingEnabled: Bool = false
var loginDetectionEnabled: Bool = false
var oneClickFireButton: Bool = false

}

Expand Down
Loading