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

Release notes page loading fix + Adding close button to the upgrade notification #3094

Merged
merged 6 commits into from
Aug 22, 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
10 changes: 0 additions & 10 deletions DuckDuckGo/Tab/Model/SpecialPagesUserScriptExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,11 @@ extension SpecialPagesUserScript {
self.registerSubfeature(delegate: sslErrorPageUserScript)
}

#if SPARKLE
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the reason of the blank page. It's the fix from previous week of a problem that isn't that serious for this site compared to restoring release notes from state. Let's roll this back and I'll continue discussing it with Sabrina in Asana

func withReleaseNotes() {
let releaseNotesUserScript = ReleaseNotesUserScript()
self.registerSubfeature(delegate: releaseNotesUserScript)
}
#endif

@MainActor
func withAllSubfeatures() {
withOnboarding()
withErrorPages()
withDuckPlayerIfAvailable()
#if SPARKLE
withReleaseNotes()
#endif
}

@MainActor
Expand Down
16 changes: 11 additions & 5 deletions DuckDuckGo/Updates/ReleaseNotesUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ 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<AnyCancellable>()
private var isInitialized = false

// MARK: - MessageNames
enum MessageNames: String, CaseIterable {
Expand Down Expand Up @@ -62,12 +67,9 @@ final class ReleaseNotesUserScript: NSObject, Subfeature {
}

public func onUpdate() {
guard NSApp.runType != .uiTests else {
guard NSApp.runType != .uiTests, isInitialized, let webView = webView else {
return
}
guard let webView = webView else {
return assertionFailure("Could not access webView")
}

guard webView.url?.isReleaseNotesScheme ?? false else {
return
Expand All @@ -87,8 +89,11 @@ 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()
Expand All @@ -99,6 +104,7 @@ extension ReleaseNotesUserScript {
#else
let env = "production"
#endif

return InitialSetupResult(env: env, locale: Locale.current.identifier)
}

Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/Updates/UpdateController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/Updates/UpdateNotificationPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public struct PopoverMessageView: View {
.frame(width: 16, height: 16)
}
.buttonStyle(PlainButtonStyle())
.padding(.top, viewModel.buttonText != nil ? 4 : 0)
}
}
.padding()
Expand Down
Loading