mirror of
https://github.com/abue-ammar/tinycast.git
synced 2026-10-02 08:14:38 +08:00
Scroll to an extension when opening its settings (#1191)
This commit is contained in:
@@ -3,6 +3,7 @@ import SwiftUI
|
||||
/// Settings › Extensions: the master switch, then a row per extension that expands in place.
|
||||
struct ExtensionsSettingsView: View {
|
||||
@Environment(AppCore.self) private var core
|
||||
@Environment(SettingsNavigationState.self) private var navigation
|
||||
@State private var expanded: String?
|
||||
@State private var filter = ""
|
||||
@State private var importCandidates: ImportCandidates?
|
||||
@@ -63,8 +64,10 @@ struct ExtensionsSettingsView: View {
|
||||
.settingsEditorPanel(isPresented: $editingRegistries) {
|
||||
ExtensionRegistriesPanel(onClose: { editingRegistries = false })
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: .tinycastSelectExtension)) { note in
|
||||
if let name = note.object as? String { expanded = name }
|
||||
.onChange(of: navigation.scrollRequest, initial: true) {
|
||||
if case .row(.extensionsInstalled, let name)? = navigation.scrollRequest?.target {
|
||||
(expanded, filter) = (name, "")
|
||||
}
|
||||
}
|
||||
.onChange(of: core.extensions.installed.count) { Task { await measureReclaimable() } }
|
||||
.task {
|
||||
@@ -368,6 +371,7 @@ private struct ExtensionDisclosure: View {
|
||||
.accessibilityAddTraits(.isButton)
|
||||
.accessibilityLabel(
|
||||
isExpanded ? "Hide \(installed.title) settings" : "Configure \(installed.title)")
|
||||
.id(SettingsTarget.row(.extensionsInstalled, installed.manifest.name))
|
||||
}
|
||||
|
||||
/// One `Grid` for every run: separate grids size columns apart, stranding controls.
|
||||
|
||||
@@ -234,9 +234,8 @@ final class ExtensionCoordinator {
|
||||
|
||||
func showExtensionSettings(for owner: InstalledExtension) {
|
||||
paletteCoordinator.hidePalette(restoreFocus: false)
|
||||
settingsCoordinator.showSettings(tab: .extensions)
|
||||
NotificationCenter.default.post(
|
||||
name: .tinycastSelectExtension, object: owner.manifest.name)
|
||||
settingsCoordinator.showSettings(
|
||||
tab: .extensions, revealing: .row(.extensionsInstalled, owner.manifest.name))
|
||||
}
|
||||
|
||||
// MARK: - Host callbacks, routed here so the manager never touches a window itself
|
||||
@@ -283,8 +282,3 @@ final class ExtensionCoordinator {
|
||||
dismissTitle: alert.dismissTitle)
|
||||
}
|
||||
}
|
||||
|
||||
extension Notification.Name {
|
||||
/// Carries an extension's name so the Settings pane can select it once shown.
|
||||
static let tinycastSelectExtension = Notification.Name("tinycastSelectExtension")
|
||||
}
|
||||
|
||||
@@ -20,12 +20,13 @@ final class SettingsCoordinator {
|
||||
|
||||
/// A fresh window mounts on `tab`; an open one navigates to it, recording the jump in history.
|
||||
/// A nil `tab` only reveals the window, so re-opening a minimised one keeps the pane it was on.
|
||||
func showSettings(tab: SettingsTab? = nil) {
|
||||
func showSettings(tab: SettingsTab? = nil, revealing target: SettingsTarget? = nil) {
|
||||
if window.focus() {
|
||||
if let tab { navigation?.select(tab) }
|
||||
if let tab { navigation?.select(tab, revealing: target) }
|
||||
return
|
||||
}
|
||||
let navigation = SettingsNavigationState(tab: tab ?? .general)
|
||||
navigation.select(navigation.tab, revealing: target)
|
||||
let editorPresenter = SettingsEditorPresenter(core: core, navigation: navigation)
|
||||
self.navigation = navigation
|
||||
self.editorPresenter = editorPresenter
|
||||
|
||||
Reference in New Issue
Block a user