Show theme-install prompt when settings scree is open. Fixes #5578 and #5580.

This commit is contained in:
Brent Simmons committed 2026-11-21 21:55:37 -08:00
1 parent 3966db21e5
commit a6a07157a2
4 files changed
+48 -26

No files matched your search

+27 -7
View File
@@ -705,8 +705,10 @@ struct SidebarItemNode: Hashable, Sendable {
return
}
DispatchQueue.main.async {
let title = NSLocalizedString("Theme Error", comment: "Theme download error")
self.rootSplitViewController.presentError(title: title, message: ArticleThemesManager.importErrorMessage(for: error))
self.withFrontmostController { controller in
let title = NSLocalizedString("Theme Error", comment: "Theme download error")
controller.presentError(title: title, message: ArticleThemesManager.importErrorMessage(for: error))
}
}
}
@@ -1778,12 +1780,13 @@ struct SidebarItemNode: Hashable, Sendable {
}
func importTheme(filename: String) {
do {
try ArticleThemeImporter.importTheme(controller: rootSplitViewController, url: URL(fileURLWithPath: filename))
} catch {
NotificationCenter.default.post(name: .didFailToImportThemeWithError, object: nil, userInfo: ["error": error])
withFrontmostController { controller in
do {
try ArticleThemeImporter.importTheme(controller: controller, url: URL(fileURLWithPath: filename))
} catch {
NotificationCenter.default.post(name: .didFailToImportThemeWithError, object: nil, userInfo: ["error": error])
}
}
}
/// This will dismiss the foremost view controller if the user
@@ -1955,6 +1958,23 @@ private extension SceneCoordinator {
}
}
/// Calls `handler` with the frontmost presented controller (such as Settings), so
/// alerts can be presented over it. Waits for any presentation transition to finish.
func withFrontmostController(_ handler: @escaping @MainActor (UIViewController) -> Void) {
var controller: UIViewController = rootSplitViewController
while let presentedController = controller.presentedViewController, !presentedController.isBeingDismissed {
controller = presentedController
}
if let transitionCoordinator = controller.transitionCoordinator {
transitionCoordinator.animate(alongsideTransition: nil) { _ in
handler(controller)
}
} else {
handler(controller)
}
}
// Focus once the navigation transition finishes, so becomeFirstResponder lands on the
// revealed column rather than firing mid-animation. Falls back to the next runloop.
func focusWhenTransitionCompletes(in navController: UINavigationController, thenFocus focus: @escaping @MainActor () -> Void) {
+15 -19
View File
@@ -121,6 +121,21 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
DispatchQueue.main.async {
// Theme URLs leave Settings open so the install prompt can appear over it.
let filename = context.url.standardizedFileURL.path
if filename.hasSuffix(ArticleTheme.nnwThemeSuffix) {
self.coordinator.importTheme(filename: filename)
return
}
// Handle theme URLs: netnewswire://theme/add?url={url}
if let urlComponents = URLComponents(url: context.url, resolvingAgainstBaseURL: false), urlComponents.scheme?.lowercased() == "netnewswire", urlComponents.host == "theme" {
if let providedThemeURL = urlComponents.queryItems?.first(where: { $0.name == "url" })?.value, let themeURL = URL(string: providedThemeURL) {
ArticleThemeDownloader.shared.downloadTheme(from: themeURL)
}
return
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.coordinator.dismissIfLaunchingFromExternalAction()
}
@@ -192,25 +207,6 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}
return
}
let filename = context.url.standardizedFileURL.path
if filename.hasSuffix(ArticleTheme.nnwThemeSuffix) {
self.coordinator.importTheme(filename: filename)
return
}
// Handle theme URLs: netnewswire://theme/add?url={url}
guard let comps = URLComponents(url: context.url, resolvingAgainstBaseURL: false),
comps.scheme?.lowercased() == "netnewswire",
"theme" == comps.host,
let queryItems = comps.queryItems else {
return
}
if let providedThemeURL = queryItems.first(where: { $0.name == "url" })?.value,
let themeURL = URL(string: providedThemeURL) {
ArticleThemeDownloader.shared.downloadTheme(from: themeURL)
}
}
}
}
+3
View File
@@ -57,6 +57,9 @@ struct ArticleThemesView: View {
SafariView(url: themesGalleryURL)
}
}
.onReceive(NotificationCenter.default.publisher(for: .didBeginDownloadingTheme)) { _ in
isShowingThemesGallery = false
}
.alert(String(localized: "Delete Theme?", comment: "Delete Theme"), isPresented: isShowingDeleteThemeConfirmation, presenting: themeNamePendingDeletion) { themeName in
Button(String(localized: "Cancel", comment: "Cancel button"), role: .cancel) {
}
+3
View File
@@ -123,6 +123,9 @@ struct SettingsView: View {
SafariView(url: safariURL)
}
}
.onReceive(NotificationCenter.default.publisher(for: .didBeginDownloadingTheme)) { _ in
safariURL = nil
}
.alert(alert?.title ?? "", isPresented: isShowingAlert, presenting: alert) { _ in
Button(NSLocalizedString("OK", comment: "OK button")) {
}