From 942736dde2f2f06f74daf7272375663c827c4251 Mon Sep 17 00:00:00 2001 From: Tomas Strba Date: Mon, 12 Aug 2024 08:42:55 +0200 Subject: [PATCH 1/5] Making sure onUpdate() is called after initialSetup message --- DuckDuckGo/Updates/ReleaseNotesUserScript.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/DuckDuckGo/Updates/ReleaseNotesUserScript.swift b/DuckDuckGo/Updates/ReleaseNotesUserScript.swift index b2ef3a006f..829e065120 100644 --- a/DuckDuckGo/Updates/ReleaseNotesUserScript.swift +++ b/DuckDuckGo/Updates/ReleaseNotesUserScript.swift @@ -31,6 +31,7 @@ final class ReleaseNotesUserScript: NSObject, Subfeature { weak var broker: UserScriptMessageBroker? weak var webView: WKWebView? private var cancellables = Set() + private var initialized = false // MARK: - MessageNames enum MessageNames: String, CaseIterable { @@ -62,12 +63,9 @@ final class ReleaseNotesUserScript: NSObject, Subfeature { } public func onUpdate() { - guard NSApp.runType != .uiTests else { + guard NSApp.runType != .uiTests, initialized, let webView = webView else { return } - guard let webView = webView else { - return assertionFailure("Could not access webView") - } guard webView.url?.isReleaseNotesScheme ?? false else { return @@ -99,6 +97,8 @@ extension ReleaseNotesUserScript { #else let env = "production" #endif + + initialized = true return InitialSetupResult(env: env, locale: Locale.current.identifier) } From 5013d8f167ab6c3d88b813de5aa60be5573c00e1 Mon Sep 17 00:00:00 2001 From: Tomas Strba Date: Mon, 12 Aug 2024 09:17:30 +0200 Subject: [PATCH 2/5] X button on the upgrade notification, pixel exception for the download error --- DuckDuckGo/Updates/UpdateController.swift | 3 ++- DuckDuckGo/Updates/UpdateNotificationPresenter.swift | 2 +- .../Sources/SwiftUIExtensions/PopoverMessageView.swift | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/DuckDuckGo/Updates/UpdateController.swift b/DuckDuckGo/Updates/UpdateController.swift index f0b7af5062..b875f6a8f0 100644 --- a/DuckDuckGo/Updates/UpdateController.swift +++ b/DuckDuckGo/Updates/UpdateController.swift @@ -222,7 +222,8 @@ extension UpdateController: SPUUpdaterDelegate { let errorCode = (error as NSError).code guard ![Int(Sparkle.SUError.noUpdateError.rawValue), Int(Sparkle.SUError.installationCanceledError.rawValue), - Int(Sparkle.SUError.runningTranslocated.rawValue)].contains(errorCode) else { + Int(Sparkle.SUError.runningTranslocated.rawValue), + Int(Sparkle.SUError.downloadError.rawValue)].contains(errorCode) else { return } diff --git a/DuckDuckGo/Updates/UpdateNotificationPresenter.swift b/DuckDuckGo/Updates/UpdateNotificationPresenter.swift index 6134ed81e2..e11ea6929b 100644 --- a/DuckDuckGo/Updates/UpdateNotificationPresenter.swift +++ b/DuckDuckGo/Updates/UpdateNotificationPresenter.swift @@ -41,7 +41,7 @@ final class UpdateNotificationPresenter { image: icon, buttonText: buttonText, buttonAction: buttonAction, - shouldShowCloseButton: buttonText == nil, + shouldShowCloseButton: true, presentMultiline: presentMultiline, autoDismissDuration: Self.presentationTimeInterval, onClick: { [weak self] in diff --git a/LocalPackages/SwiftUIExtensions/Sources/SwiftUIExtensions/PopoverMessageView.swift b/LocalPackages/SwiftUIExtensions/Sources/SwiftUIExtensions/PopoverMessageView.swift index 2a47c35e8b..1cbeb3674d 100644 --- a/LocalPackages/SwiftUIExtensions/Sources/SwiftUIExtensions/PopoverMessageView.swift +++ b/LocalPackages/SwiftUIExtensions/Sources/SwiftUIExtensions/PopoverMessageView.swift @@ -101,6 +101,7 @@ public struct PopoverMessageView: View { .frame(width: 16, height: 16) } .buttonStyle(PlainButtonStyle()) + .padding(.top, viewModel.buttonText != nil ? 4 : 0) } } .padding() From 67237b3f73159ba723e6c91b8f483518463715c3 Mon Sep 17 00:00:00 2001 From: Tomas Strba Date: Mon, 19 Aug 2024 12:46:04 +0200 Subject: [PATCH 3/5] isInitialized + assignment changed --- DuckDuckGo/Updates/ReleaseNotesUserScript.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/DuckDuckGo/Updates/ReleaseNotesUserScript.swift b/DuckDuckGo/Updates/ReleaseNotesUserScript.swift index 829e065120..5fb510443c 100644 --- a/DuckDuckGo/Updates/ReleaseNotesUserScript.swift +++ b/DuckDuckGo/Updates/ReleaseNotesUserScript.swift @@ -31,7 +31,7 @@ final class ReleaseNotesUserScript: NSObject, Subfeature { weak var broker: UserScriptMessageBroker? weak var webView: WKWebView? private var cancellables = Set() - private var initialized = false + private var isInitialized = false // MARK: - MessageNames enum MessageNames: String, CaseIterable { @@ -63,7 +63,7 @@ final class ReleaseNotesUserScript: NSObject, Subfeature { } public func onUpdate() { - guard NSApp.runType != .uiTests, initialized, let webView = webView else { + guard NSApp.runType != .uiTests, isInitialized, let webView = webView else { return } @@ -87,6 +87,8 @@ final class ReleaseNotesUserScript: NSObject, Subfeature { extension ReleaseNotesUserScript { @MainActor private func initialSetup(params: Any, original: WKScriptMessage) async throws -> Encodable? { + isInitialized = true + // Initialize the page right after sending the initial setup result DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in self?.onUpdate() @@ -98,7 +100,6 @@ extension ReleaseNotesUserScript { let env = "production" #endif - initialized = true return InitialSetupResult(env: env, locale: Locale.current.identifier) } From 4e393d5c1008d6ba5c05d7fe35f6a82e41334c63 Mon Sep 17 00:00:00 2001 From: Tomas Strba Date: Mon, 19 Aug 2024 13:29:21 +0200 Subject: [PATCH 4/5] Edge case resolved --- DuckDuckGo/Updates/ReleaseNotesUserScript.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/DuckDuckGo/Updates/ReleaseNotesUserScript.swift b/DuckDuckGo/Updates/ReleaseNotesUserScript.swift index 5fb510443c..199d0da2d0 100644 --- a/DuckDuckGo/Updates/ReleaseNotesUserScript.swift +++ b/DuckDuckGo/Updates/ReleaseNotesUserScript.swift @@ -29,7 +29,11 @@ final class ReleaseNotesUserScript: NSObject, Subfeature { var messageOriginPolicy: MessageOriginPolicy = .only(rules: [.exact(hostname: "release-notes")]) let featureName: String = "release-notes" weak var broker: UserScriptMessageBroker? - weak var webView: WKWebView? + weak var webView: WKWebView? { + didSet { + onUpdate() + } + } private var cancellables = Set() private var isInitialized = false @@ -85,6 +89,7 @@ final class ReleaseNotesUserScript: NSObject, Subfeature { } extension ReleaseNotesUserScript { + @MainActor private func initialSetup(params: Any, original: WKScriptMessage) async throws -> Encodable? { isInitialized = true From 352c71ab73eda9b1e6ee76369e39efbfa7f3482f Mon Sep 17 00:00:00 2001 From: Tomas Strba Date: Mon, 19 Aug 2024 15:00:54 +0200 Subject: [PATCH 5/5] Problem with SpecialPagesUserScript resolved --- .../Tab/Model/SpecialPagesUserScriptExtension.swift | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/DuckDuckGo/Tab/Model/SpecialPagesUserScriptExtension.swift b/DuckDuckGo/Tab/Model/SpecialPagesUserScriptExtension.swift index 1fddfc49f9..15dc8d38a1 100644 --- a/DuckDuckGo/Tab/Model/SpecialPagesUserScriptExtension.swift +++ b/DuckDuckGo/Tab/Model/SpecialPagesUserScriptExtension.swift @@ -42,21 +42,11 @@ extension SpecialPagesUserScript { self.registerSubfeature(delegate: sslErrorPageUserScript) } -#if SPARKLE - func withReleaseNotes() { - let releaseNotesUserScript = ReleaseNotesUserScript() - self.registerSubfeature(delegate: releaseNotesUserScript) - } -#endif - @MainActor func withAllSubfeatures() { withOnboarding() withErrorPages() withDuckPlayerIfAvailable() -#if SPARKLE - withReleaseNotes() -#endif } @MainActor