From c7e1f667c30b4e8a3fc4b2b465f44ad74befe151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 6 Mar 2026 10:02:30 +0800 Subject: [PATCH] Persist log and connection search state across tabs --- .../Views/Connections/ConnectionListView.swift | 5 +++++ ApplicationLibrary/Views/Log/LogView.swift | 10 +++++++--- ApplicationLibrary/Views/Log/LogViewModel.swift | 4 +++- Library/Network/ExtensionEnvironments.swift | 3 +++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ApplicationLibrary/Views/Connections/ConnectionListView.swift b/ApplicationLibrary/Views/Connections/ConnectionListView.swift index 2f5ef8b..84510f3 100644 --- a/ApplicationLibrary/Views/Connections/ConnectionListView.swift +++ b/ApplicationLibrary/Views/Connections/ConnectionListView.swift @@ -60,10 +60,15 @@ public struct ConnectionListView: View { #endif .alert($viewModel.alert) .onAppear { + if !environments.connectionSearchText.isEmpty { + viewModel.searchText = environments.connectionSearchText + viewModel.isSearching = true + } viewModel.connect() commandClient.connect() } .onDisappear { + environments.connectionSearchText = viewModel.searchText viewModel.disconnect() commandClient.disconnect() } diff --git a/ApplicationLibrary/Views/Log/LogView.swift b/ApplicationLibrary/Views/Log/LogView.swift index f9e29d2..de2b118 100644 --- a/ApplicationLibrary/Views/Log/LogView.swift +++ b/ApplicationLibrary/Views/Log/LogView.swift @@ -15,15 +15,16 @@ public struct LogView: View { public init() {} public var body: some View { - LogViewContent(commandClient: environments.commandClient) + LogViewContent(commandClient: environments.commandClient, initialSearchText: environments.logSearchText) } } private struct LogViewContent: View { + @EnvironmentObject private var environments: ExtensionEnvironments @StateObject private var viewModel: LogViewModel - init(commandClient: CommandClient) { - _viewModel = StateObject(wrappedValue: LogViewModel(commandClient: commandClient)) + init(commandClient: CommandClient, initialSearchText: String = "") { + _viewModel = StateObject(wrappedValue: LogViewModel(commandClient: commandClient, searchText: initialSearchText)) } var body: some View { @@ -35,6 +36,9 @@ private struct LogViewContent: View { toolbarButtons } } + .onDisappear { + environments.logSearchText = viewModel.searchText + } .alert($viewModel.alert) .background( LogExportView( diff --git a/ApplicationLibrary/Views/Log/LogViewModel.swift b/ApplicationLibrary/Views/Log/LogViewModel.swift index 83ab307..4bf34ca 100644 --- a/ApplicationLibrary/Views/Log/LogViewModel.swift +++ b/ApplicationLibrary/Views/Log/LogViewModel.swift @@ -176,8 +176,10 @@ public class LogViewModel: BaseViewModel { public let commandClient: CommandClient public private(set) var dataModel: LogDataModel! - public init(commandClient: CommandClient) { + public init(commandClient: CommandClient, searchText: String = "") { self.commandClient = commandClient + self.searchText = searchText + self.isSearching = !searchText.isEmpty super.init() dataModel = LogDataModel(commandClient: commandClient, viewModel: self) } diff --git a/Library/Network/ExtensionEnvironments.swift b/Library/Network/ExtensionEnvironments.swift index 7d7def7..d099d2e 100644 --- a/Library/Network/ExtensionEnvironments.swift +++ b/Library/Network/ExtensionEnvironments.swift @@ -180,6 +180,9 @@ public class ExtensionEnvironments: ObservableObject { @Published public var emptyProfiles = false @Published public var pendingImportRemoteProfile: ImportRemoteProfileRequest? + public var logSearchText = "" + public var connectionSearchText = "" + public let profileUpdate = ObjectWillChangePublisher() public let selectedProfileUpdate = ObjectWillChangePublisher() public let openSettings = ObjectWillChangePublisher()