Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tab title not updated #2302

Merged
merged 6 commits into from
Mar 4, 2024
Merged
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
5 changes: 1 addition & 4 deletions DuckDuckGo/Tab/Model/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,7 @@ protocol NewWindowPolicyDecisionMaker {
return
}

let title = webView.title?.trimmingWhitespace()
if title != self.title {
self.title = title
}
self.title = webView.title?.trimmingWhitespace()

if let wkBackForwardListItem = webView.backForwardList.currentItem,
content.urlForWebView == wkBackForwardListItem.url,
Expand Down
19 changes: 8 additions & 11 deletions DuckDuckGo/Tab/ViewModel/TabViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,12 @@ final class TabViewModel {
}
}
.switchToLatest()
.sink { [weak self] event in
.sink { [weak self] _ in
guard let self else { return }

updateAddressBarStrings()
if case .didCommit = event {
updateCanBeBookmarked()
updateFavicon()
}
updateFavicon()
updateCanBeBookmarked()
}
.store(in: &cancellables)
}
Expand Down Expand Up @@ -180,9 +178,8 @@ final class TabViewModel {
.filter { [weak self] _ in
self?.tab.isLazyLoadingInProgress == false
}
.receive(on: DispatchQueue.main)
.sink { [weak self] _ in
self?.updateFavicon()
.sink { [weak self] favicon in
self?.updateFavicon(favicon)
}
.store(in: &cancellables)
}
Expand Down Expand Up @@ -315,7 +312,7 @@ final class TabViewModel {
}
}

private func updateFavicon() {
private func updateFavicon(_ tabFavicon: NSImage?? = .none /* provided from .sink or taken from tab.favicon (optional) if .none */) {
guard !isShowingErrorPage else {
favicon = .alertCircleColor16
return
Expand All @@ -341,10 +338,10 @@ final class TabViewModel {
case .url, .onboarding, .none, .subscription: break
}

if let favicon = tab.favicon {
if let favicon: NSImage? = tabFavicon {
self.favicon = favicon
} else {
favicon = nil
self.favicon = tab.favicon
}
}

Expand Down
4 changes: 3 additions & 1 deletion UnitTests/Onboarding/OnboardingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class OnboardingTests: XCTestCase {
XCTAssertEqual(model.state, .startFlow)
}

@MainActor
func testStateChanges() {
let model = OnboardingViewModel(delegate: delegate)
assertStateChange(model, .startFlow, .welcome, model.onSplashFinished)
Expand Down Expand Up @@ -94,10 +95,11 @@ class OnboardingTests: XCTestCase {
XCTAssertEqual(model.state, .startFlow)
}

@MainActor
private func assertStateChange(_ model: OnboardingViewModel,
_ expectedCurrentState: OnboardingViewModel.OnboardingPhase,
_ expectedFinalState: OnboardingViewModel.OnboardingPhase,
_ mutator: () -> Void,
_ mutator: @MainActor () -> Void,
file: StaticString = #file,
line: UInt = #line) {

Expand Down
1 change: 1 addition & 0 deletions UnitTests/Preferences/DownloadsPreferencesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class DownloadsPreferencesTests: XCTestCase {
waitForExpectations(timeout: 0)
XCTAssertFalse(preferences.shouldOpenPopupOnCompletion)
XCTAssertEqual(persistor2.values().difference(from: valuesWithFalse), [])
withExtendedLifetime(c) {}
}

private func createTemporaryTestDirectory(named name: String = DownloadsPreferencesTests.defaultTestDirectoryName) -> URL {
Expand Down
6 changes: 3 additions & 3 deletions UnitTests/Tab/Services/FaviconManagerMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class FaviconManagerMock: FaviconManagement {
@Published var areFaviconsLoaded = true
var faviconsLoadedPublisher: Published<Bool>.Publisher { $areFaviconsLoaded }

func handleFaviconLinks(_ faviconLinks: [FaviconUserScript.FaviconLink], documentUrl: URL, completion: @escaping (Favicon?) -> Void) {
func handleFaviconLinks(_ faviconLinks: [FaviconUserScript.FaviconLink], documentUrl: URL, completion: @escaping @MainActor (Favicon?) -> Void) {
completion(nil)
}

Expand All @@ -49,12 +49,12 @@ final class FaviconManagerMock: FaviconManagement {
return nil
}

func burnExcept(fireproofDomains: DuckDuckGo_Privacy_Browser.FireproofDomains, bookmarkManager: DuckDuckGo_Privacy_Browser.BookmarkManager, savedLogins: Set<String>, completion: @escaping () -> Void) {
func burnExcept(fireproofDomains: DuckDuckGo_Privacy_Browser.FireproofDomains, bookmarkManager: DuckDuckGo_Privacy_Browser.BookmarkManager, savedLogins: Set<String>, completion: @escaping @MainActor () -> Void) {
completion()
}

// swiftlint:disable:next function_parameter_count
func burnDomains(_ domains: Set<String>, exceptBookmarks bookmarkManager: DuckDuckGo_Privacy_Browser.BookmarkManager, exceptSavedLogins: Set<String>, exceptExistingHistory history: History, tld: Common.TLD, completion: @escaping () -> Void) {
func burnDomains(_ domains: Set<String>, exceptBookmarks bookmarkManager: DuckDuckGo_Privacy_Browser.BookmarkManager, exceptSavedLogins: Set<String>, exceptExistingHistory history: History, tld: Common.TLD, completion: @escaping @MainActor () -> Void) {
completion()
}
}
Loading