Skip to content

Commit

Permalink
Option to add the application to the Dock from Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasstrba committed May 1, 2024
1 parent 6c5e4c5 commit d2dbeb8
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo/Application/DockCustomizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protocol DockCustomization {
func addToDock() -> Bool
}

final class DockCustomizer: DockCustomization {
final class DockCustomizer: DockCustomization, ObservableObject {

static func appDict(appPath: String, bundleIdentifier: String) -> [String: AnyObject] {
return ["tile-type": "file-tile" as AnyObject,
Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/Common/Localizables/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,10 @@ struct UserText {
static let isDefaultBrowser = NSLocalizedString("preferences.default-browser.active", value: "DuckDuckGo is your default browser", comment: "Indicate that the browser is the default")
static let isNotDefaultBrowser = NSLocalizedString("preferences.default-browser.inactive", value: "DuckDuckGo is not your default browser.", comment: "Indicate that the browser is not the default")
static let makeDefaultBrowser = NSLocalizedString("preferences.default-browser.button.make-default", value: "Make DuckDuckGo Default…", comment: "represents a prompt message asking the user to make DuckDuckGo their default browser.")
static let shortcuts = NSLocalizedString("preferences.shortcuts", value: "Shortcuts", comment: "Name of the preferences section related to shortcuts")
static let isAddedToDock = NSLocalizedString("preferences.is-added-to-dock", value: "DuckDuckGo is added to the Dock.", comment: "Indicates that the browser is the added to macOS system Dock")
static let isNotAddedToDock = NSLocalizedString("preferences.not-added-to-dock", value: "DuckDuckGo is not added to the Dock.", comment: "Indicate that the browser is not added to macOS system Dock")
static let addToDock = NSLocalizedString("preferences.add-to-dock", value: "Add to Dock…", comment: "Action button to add the app to the Dock")
static let onStartup = NSLocalizedString("preferences.on-startup", value: "On Startup", comment: "Name of the preferences section related to app startup")
static let reopenAllWindowsFromLastSession = NSLocalizedString("preferences.reopen-windows", value: "Reopen all windows from last session", comment: "Option to control session restoration")
static let showHomePage = NSLocalizedString("preferences.show-home", value: "Open a new window", comment: "Option to control session startup")
Expand Down
48 changes: 48 additions & 0 deletions DuckDuckGo/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -43464,6 +43464,18 @@
}
}
},
"preferences.add-to-dock" : {
"comment" : "Action button to add the app to the Dock",
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "Add to Dock…"
}
}
}
},
"preferences.always-on" : {
"comment" : "Status indicator of a browser privacy protection feature.",
"extractionState" : "extracted_with_value",
Expand Down Expand Up @@ -44904,6 +44916,18 @@
}
}
},
"preferences.is-added-to-dock" : {
"comment" : "Indicates that the browser is the added to macOS system Dock",
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "DuckDuckGo is added to the Dock."
}
}
}
},
"preferences.main-settings" : {
"comment" : "Section header in Preferences for main settings",
"extractionState" : "extracted_with_value",
Expand Down Expand Up @@ -44964,6 +44988,18 @@
}
}
},
"preferences.not-added-to-dock" : {
"comment" : "Indicate that the browser is not added to macOS system Dock",
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "DuckDuckGo is not added to the Dock."
}
}
}
},
"preferences.off" : {
"comment" : "Status indicator of a browser privacy protection feature.",
"extractionState" : "extracted_with_value",
Expand Down Expand Up @@ -45384,6 +45420,18 @@
}
}
},
"preferences.shortcuts" : {
"comment" : "Name of the preferences section related to shortcuts",
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "Shortcuts"
}
}
}
},
"preferences.show-home" : {
"comment" : "Option to control session startup",
"extractionState" : "extracted_with_value",
Expand Down
42 changes: 38 additions & 4 deletions DuckDuckGo/Preferences/View/PreferencesGeneralView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,46 @@ extension Preferences {
@ObservedObject var startupModel: StartupPreferences
@ObservedObject var downloadsModel: DownloadsPreferences
@ObservedObject var searchModel: SearchPreferences
@ObservedObject var dockCustomizer: DockCustomizer
@State private var showingCustomHomePageSheet = false
@State private var isAddedToDock = false

var body: some View {
PreferencePane(UserText.general) {

// SECTION 1: On Startup
// SECTION 1: Shortcuts
PreferencePaneSection(UserText.shortcuts, spacing: 4) {
PreferencePaneSubSection {
HStack {
if isAddedToDock || dockCustomizer.isAddedToDock {
HStack {
Image(.successCheckmark)
Text(UserText.isAddedToDock)
}
.transition(.opacity)
.padding(.trailing, 8)
} else {
HStack {
Image(.warning).foregroundColor(Color(.linkBlue))
Text(UserText.isNotAddedToDock)
}
.padding(.trailing, 8)
Button(action: {
withAnimation {
dockCustomizer.addToDock()
isAddedToDock = true
}
}) {
Text(UserText.addToDock)
.fixedSize(horizontal: true, vertical: false)
.multilineTextAlignment(.center)
}
}
}
}
}

// SECTION 2: On Startup
PreferencePaneSection(UserText.onStartup) {

PreferencePaneSubSection {
Expand All @@ -49,7 +83,7 @@ extension Preferences {
}
}

// SECTION 2: Home Page
// SECTION 3: Home Page
PreferencePaneSection(UserText.homePage) {

PreferencePaneSubSection {
Expand Down Expand Up @@ -93,12 +127,12 @@ extension Preferences {
CustomHomePageSheet(startupModel: startupModel, isSheetPresented: $showingCustomHomePageSheet)
}

// SECTION 3: Search Settings
// SECTION 4: Search Settings
PreferencePaneSection(UserText.privateSearch) {
ToggleMenuItem(UserText.showAutocompleteSuggestions, isOn: $searchModel.showAutocompleteSuggestions).accessibilityIdentifier("PreferencesGeneralView.showAutocompleteSuggestions")
}

// SECTION 4: Downloads
// SECTION 5: Downloads
PreferencePaneSection(UserText.downloads) {
PreferencePaneSubSection {
ToggleMenuItem(UserText.downloadsOpenPopupOnCompletion,
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/Preferences/View/PreferencesRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ enum Preferences {
case .general:
GeneralView(startupModel: StartupPreferences.shared,
downloadsModel: DownloadsPreferences.shared,
searchModel: SearchPreferences.shared)
searchModel: SearchPreferences.shared,
dockCustomizer: DockCustomizer())
case .sync:
SyncView()
case .appearance:
Expand Down

0 comments on commit d2dbeb8

Please sign in to comment.