Skip to content

Commit

Permalink
implement show bookmark name in tab feature
Browse files Browse the repository at this point in the history
  • Loading branch information
SabrinaTardio committed Feb 8, 2024
1 parent df23d49 commit a1cd9d7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions DuckDuckGo/Common/Utilities/UserDefaultsWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public struct UserDefaultsWrapper<T> {
case customHomePageURL = "preferences.startup.customHomePageURL"
case currentThemeName = "com.duckduckgo.macos.currentThemeNameKey"
case showFullURL = "preferences.appearance.show-full-url"
case showBookmarkTitleInTab = "preferences.appearance.show-bookmark-title-in-tab"
case showAutocompleteSuggestions = "preferences.appearance.show-autocomplete-suggestions"
case defaultPageZoom = "preferences.appearance.default-page-zoom"
case bookmarksBarAppearance = "preferences.appearance.bookmarks-bar"
Expand Down
11 changes: 11 additions & 0 deletions DuckDuckGo/Preferences/Model/AppearancePreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Common

protocol AppearancePreferencesPersistor {
var showFullURL: Bool { get set }
var showBookmarkTitleInTab: Bool { get set }
var showAutocompleteSuggestions: Bool { get set }
var currentThemeName: String { get set }
var defaultPageZoom: CGFloat { get set }
Expand All @@ -39,6 +40,9 @@ struct AppearancePreferencesUserDefaultsPersistor: AppearancePreferencesPersisto
@UserDefaultsWrapper(key: .showFullURL, defaultValue: false)
var showFullURL: Bool

@UserDefaultsWrapper(key: .showBookmarkTitleInTab, defaultValue: true)
var showBookmarkTitleInTab: Bool

@UserDefaultsWrapper(key: .showAutocompleteSuggestions, defaultValue: true)
var showAutocompleteSuggestions: Bool

Expand Down Expand Up @@ -181,6 +185,12 @@ final class AppearancePreferences: ObservableObject {
}
}

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

@Published var showAutocompleteSuggestions: Bool {
didSet {
persistor.showAutocompleteSuggestions = showAutocompleteSuggestions
Expand Down Expand Up @@ -269,6 +279,7 @@ final class AppearancePreferences: ObservableObject {
showBookmarksBar = persistor.showBookmarksBar
bookmarksBarAppearance = persistor.bookmarksBarAppearance
homeButtonPosition = persistor.homeButtonPosition
showBookmarkTitleInTab = persistor.showBookmarkTitleInTab
}

private var persistor: AppearancePreferencesPersistor
Expand Down
5 changes: 4 additions & 1 deletion DuckDuckGo/Preferences/View/PreferencesAppearanceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,14 @@ extension Preferences {

// SECTION 1: Theme
PreferencePaneSection(UserText.theme) {

ThemePicker()
.environmentObject(model)
}

PreferencePaneSection("Tabs") {
ToggleMenuItem("Show Bookmark Titles in Tabs", isOn: $model.showBookmarkTitleInTab)
}

// SECTION 2: Address Bar
PreferencePaneSection(UserText.addressBar) {
ToggleMenuItem(UserText.showFullWebsiteAddress, isOn: $model.showFullURL)
Expand Down
16 changes: 16 additions & 0 deletions DuckDuckGo/Tab/Model/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ protocol NewWindowPolicyDecisionMaker {

private let statisticsLoader: StatisticsLoader?
private let internalUserDecider: InternalUserDecider?
private let bookmarksManager: BookmarkManager = LocalBookmarkManager.shared
private let appearancePreferences = AppearancePreferences.shared
let pinnedTabsManager: PinnedTabsManager

#if NETWORK_PROTECTION
Expand Down Expand Up @@ -450,6 +452,14 @@ protocol NewWindowPolicyDecisionMaker {
handleFavicon()
}

bookmarksManager.listPublisher.receive(on: RunLoop.main).sink { [weak self] _ in
self?.updateTitle()
}.store(in: &bookmarkManagerCancellables)

appearancePreferences.$showBookmarkTitleInTab.sink { [weak self] _ in
self?.updateTitle()
}.store(in: &bookmarkManagerCancellables)

emailDidSignOutCancellable = NotificationCenter.default.publisher(for: .emailDidSignOut)
.receive(on: DispatchQueue.main)
.sink { [weak self] notification in
Expand Down Expand Up @@ -665,6 +675,11 @@ protocol NewWindowPolicyDecisionMaker {
if title != self.title {
self.title = title
}

guard appearancePreferences.showBookmarkTitleInTab else { return }
if let url = webView.url, let bookmark = bookmarksManager.getBookmark(for: url) {
self.title = bookmark.title
}
}

@PublishedAfter var error: WKError? {
Expand Down Expand Up @@ -939,6 +954,7 @@ protocol NewWindowPolicyDecisionMaker {
_ = FireproofDomains.shared.toggle(domain: host)
}

private var bookmarkManagerCancellables = Set<AnyCancellable>()
private var webViewCancellables = Set<AnyCancellable>()
private var emailDidSignOutCancellable: AnyCancellable?

Expand Down

0 comments on commit a1cd9d7

Please sign in to comment.