From 03d23ea5adede8171362600896a0507a55118bbc Mon Sep 17 00:00:00 2001 From: Alexey Martemyanov Date: Fri, 1 Mar 2024 22:02:14 +0600 Subject: [PATCH 1/4] fix tab title not updated --- DuckDuckGo/Tab/Model/Tab.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/DuckDuckGo/Tab/Model/Tab.swift b/DuckDuckGo/Tab/Model/Tab.swift index 09fc3be7a4..a477674a7b 100644 --- a/DuckDuckGo/Tab/Model/Tab.swift +++ b/DuckDuckGo/Tab/Model/Tab.swift @@ -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, From 92d0745204f72ee8487de642e5d4efcc5075756a Mon Sep 17 00:00:00 2001 From: Alexey Martemyanov Date: Fri, 1 Mar 2024 22:10:10 +0600 Subject: [PATCH 2/4] fix favicon not updated --- DuckDuckGo/Tab/ViewModel/TabViewModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DuckDuckGo/Tab/ViewModel/TabViewModel.swift b/DuckDuckGo/Tab/ViewModel/TabViewModel.swift index 7ed73a4504..b1dc2ab42a 100644 --- a/DuckDuckGo/Tab/ViewModel/TabViewModel.swift +++ b/DuckDuckGo/Tab/ViewModel/TabViewModel.swift @@ -140,9 +140,9 @@ final class TabViewModel { guard let self else { return } updateAddressBarStrings() + updateFavicon() if case .didCommit = event { updateCanBeBookmarked() - updateFavicon() } } .store(in: &cancellables) From 658b89574ce3297ccaaac4f8ef9ae152361753fe Mon Sep 17 00:00:00 2001 From: Alexey Martemyanov Date: Mon, 4 Mar 2024 16:39:31 +0600 Subject: [PATCH 3/4] fix favicon blinking on .newtab <-> pdf navigation; fix build and warnings --- DuckDuckGo/Tab/ViewModel/TabViewModel.swift | 17 +++++++---------- Submodules/privacy-reference-tests | 2 +- UnitTests/Onboarding/OnboardingTests.swift | 4 +++- .../Preferences/DownloadsPreferencesTests.swift | 1 + UnitTests/Tab/Services/FaviconManagerMock.swift | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/DuckDuckGo/Tab/ViewModel/TabViewModel.swift b/DuckDuckGo/Tab/ViewModel/TabViewModel.swift index b1dc2ab42a..d90fa2aa37 100644 --- a/DuckDuckGo/Tab/ViewModel/TabViewModel.swift +++ b/DuckDuckGo/Tab/ViewModel/TabViewModel.swift @@ -136,14 +136,12 @@ final class TabViewModel { } } .switchToLatest() - .sink { [weak self] event in + .sink { [weak self] _ in guard let self else { return } updateAddressBarStrings() updateFavicon() - if case .didCommit = event { - updateCanBeBookmarked() - } + updateCanBeBookmarked() } .store(in: &cancellables) } @@ -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) } @@ -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 @@ -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 } } diff --git a/Submodules/privacy-reference-tests b/Submodules/privacy-reference-tests index a603ff9af2..40ce86837d 160000 --- a/Submodules/privacy-reference-tests +++ b/Submodules/privacy-reference-tests @@ -1 +1 @@ -Subproject commit a603ff9af22ca3ff7ce2e7ffbfe18c447d9f23e8 +Subproject commit 40ce86837def0adbf558f00ed0531ab4df5839a8 diff --git a/UnitTests/Onboarding/OnboardingTests.swift b/UnitTests/Onboarding/OnboardingTests.swift index 729d97636e..f0366d6498 100644 --- a/UnitTests/Onboarding/OnboardingTests.swift +++ b/UnitTests/Onboarding/OnboardingTests.swift @@ -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) @@ -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) { diff --git a/UnitTests/Preferences/DownloadsPreferencesTests.swift b/UnitTests/Preferences/DownloadsPreferencesTests.swift index afefd8fb8f..fbcb7a9b13 100644 --- a/UnitTests/Preferences/DownloadsPreferencesTests.swift +++ b/UnitTests/Preferences/DownloadsPreferencesTests.swift @@ -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 { diff --git a/UnitTests/Tab/Services/FaviconManagerMock.swift b/UnitTests/Tab/Services/FaviconManagerMock.swift index 70356792c6..ed0efbd473 100644 --- a/UnitTests/Tab/Services/FaviconManagerMock.swift +++ b/UnitTests/Tab/Services/FaviconManagerMock.swift @@ -29,7 +29,7 @@ final class FaviconManagerMock: FaviconManagement { @Published var areFaviconsLoaded = true var faviconsLoadedPublisher: Published.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) } @@ -49,12 +49,12 @@ final class FaviconManagerMock: FaviconManagement { return nil } - func burnExcept(fireproofDomains: DuckDuckGo_Privacy_Browser.FireproofDomains, bookmarkManager: DuckDuckGo_Privacy_Browser.BookmarkManager, savedLogins: Set, completion: @escaping () -> Void) { + func burnExcept(fireproofDomains: DuckDuckGo_Privacy_Browser.FireproofDomains, bookmarkManager: DuckDuckGo_Privacy_Browser.BookmarkManager, savedLogins: Set, completion: @escaping @MainActor () -> Void) { completion() } // swiftlint:disable:next function_parameter_count - func burnDomains(_ domains: Set, exceptBookmarks bookmarkManager: DuckDuckGo_Privacy_Browser.BookmarkManager, exceptSavedLogins: Set, exceptExistingHistory history: History, tld: Common.TLD, completion: @escaping () -> Void) { + func burnDomains(_ domains: Set, exceptBookmarks bookmarkManager: DuckDuckGo_Privacy_Browser.BookmarkManager, exceptSavedLogins: Set, exceptExistingHistory history: History, tld: Common.TLD, completion: @escaping @MainActor () -> Void) { completion() } } From e40c2782f5bc1d01630ad36293b9beddef253b9e Mon Sep 17 00:00:00 2001 From: Alexey Martemyanov Date: Mon, 4 Mar 2024 16:52:20 +0600 Subject: [PATCH 4/4] rollback Submodules/privacy-reference-tests --- Submodules/privacy-reference-tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Submodules/privacy-reference-tests b/Submodules/privacy-reference-tests index 40ce86837d..a603ff9af2 160000 --- a/Submodules/privacy-reference-tests +++ b/Submodules/privacy-reference-tests @@ -1 +1 @@ -Subproject commit 40ce86837def0adbf558f00ed0531ab4df5839a8 +Subproject commit a603ff9af22ca3ff7ce2e7ffbfe18c447d9f23e8