|
|
@@ -65,6 +65,9 @@ private struct WidgetsWindowRootView: View {
|
|
|
let selectedAppID: UUID?
|
|
|
|
|
|
@AppStorage("widgetAppIDsData") private var widgetAppIDsData = ""
|
|
|
+ /// Survives `NSHostingController.rootView` replacement so the sidebar stays selected like macOS widget settings.
|
|
|
+ @AppStorage("widgetsLibrarySidebarSelectedAppID") private var persistedSidebarAppID: String = ""
|
|
|
+
|
|
|
@State private var selection: UUID?
|
|
|
|
|
|
var body: some View {
|
|
|
@@ -82,10 +85,35 @@ private struct WidgetsWindowRootView: View {
|
|
|
.padding(.top, 12)
|
|
|
}
|
|
|
.onAppear {
|
|
|
- selection = selectedAppID ?? selection ?? apps.first?.id
|
|
|
+ restoreSelectionFromStorage()
|
|
|
}
|
|
|
.onChange(of: selectedAppID) { newValue in
|
|
|
- if let newValue { selection = newValue }
|
|
|
+ if let newValue {
|
|
|
+ selection = newValue
|
|
|
+ persistedSidebarAppID = newValue.uuidString
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .onChange(of: selection) { newValue in
|
|
|
+ if let newValue {
|
|
|
+ persistedSidebarAppID = newValue.uuidString
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private func restoreSelectionFromStorage() {
|
|
|
+ if let selectedAppID {
|
|
|
+ selection = selectedAppID
|
|
|
+ persistedSidebarAppID = selectedAppID.uuidString
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if let stored = UUID(uuidString: persistedSidebarAppID),
|
|
|
+ apps.contains(where: { $0.id == stored }) {
|
|
|
+ selection = stored
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if let first = apps.first {
|
|
|
+ selection = first.id
|
|
|
+ persistedSidebarAppID = first.id.uuidString
|
|
|
}
|
|
|
}
|
|
|
}
|