From 9d5e4a4e304cf39c9f4ad0fd8241e8e3f9a4aa8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 5 Jan 2026 22:38:24 +0800 Subject: [PATCH] Fix menu in connections & Fix sidebar status --- .../Connections/ConnectionListViewModel.swift | 9 ++ Localizable.xcstrings | 81 +++++++++-- MacLibrary/SidebarView.swift | 128 +++++++++++++----- 3 files changed, 177 insertions(+), 41 deletions(-) diff --git a/ApplicationLibrary/Views/Connections/ConnectionListViewModel.swift b/ApplicationLibrary/Views/Connections/ConnectionListViewModel.swift index b3d25ab..51efe96 100644 --- a/ApplicationLibrary/Views/Connections/ConnectionListViewModel.swift +++ b/ApplicationLibrary/Views/Connections/ConnectionListViewModel.swift @@ -16,6 +16,15 @@ public class ConnectionListViewModel: BaseViewModel { } } + @Published public var isSearching = false + + public func toggleSearch() { + isSearching.toggle() + if !isSearching { + searchText = "" + } + } + @Published public var filteredConnections: [Connection] = [] @Published public var connectionStateFilter: ConnectionStateFilter { didSet { diff --git a/Localizable.xcstrings b/Localizable.xcstrings index a92ce07..2aab534 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -741,7 +741,14 @@ } }, "Detailed" : { - + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "详细" + } + } + } }, "Disable Deprecated Warnings" : { "localizations" : { @@ -754,7 +761,14 @@ } }, "Disabled" : { - + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "已禁用" + } + } + } }, "Disconnect" : { "localizations" : { @@ -1017,7 +1031,14 @@ } }, "Enabled" : { - + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "已启用" + } + } + } }, "enforceRoutes" : { "shouldTranslate" : false @@ -1152,7 +1173,14 @@ } }, "Format" : { - + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "格式化" + } + } + } }, "FPS" : { "shouldTranslate" : false @@ -1191,7 +1219,14 @@ "shouldTranslate" : false }, "Group" : { - + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "分组" + } + } + } }, "Groups" : { "localizations" : { @@ -2107,7 +2142,14 @@ } }, "Real-time Speed" : { - + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "实时速率" + } + } + } }, "Reboot required." : { "localizations" : { @@ -2120,10 +2162,24 @@ } }, "Redo" : { - + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "重做" + } + } + } }, "Register task failed" : { - + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "注册任务失败" + } + } + } }, "Releases" : { "shouldTranslate" : false @@ -2738,7 +2794,14 @@ } }, "Undo" : { - + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "撤销" + } + } + } }, "Unexpected message type %lld" : { "localizations" : { diff --git a/MacLibrary/SidebarView.swift b/MacLibrary/SidebarView.swift index 2e57cdc..b8622ad 100644 --- a/MacLibrary/SidebarView.swift +++ b/MacLibrary/SidebarView.swift @@ -2,49 +2,28 @@ import ApplicationLibrary import Library import SwiftUI -public struct SidebarView: View { +private struct SidebarContentView: View { @Binding var selection: NavigationPage - @EnvironmentObject private var environments: ExtensionEnvironments - @State private var localSelection: NavigationPage = .dashboard + @Binding var localSelection: NavigationPage + @ObservedObject var profile: ExtensionProfile + var environments: ExtensionEnvironments - public init(selection: Binding) { - _selection = selection + private var hasGroups: Bool { + environments.commandClient.groups?.isEmpty == false } - public var body: some View { - if ApplicationLibrary.inPreview { - sidebarContent(isConnected: true, profile: nil) - } else if environments.extensionProfileLoading { - ProgressView() - } else if let profile = environments.extensionProfile { - sidebarContent(isConnected: profile.status.isConnectedStrict, profile: profile) - .onReceive(profile.$status) { _ in } - .onChangeCompat(of: profile.status) { - if !localSelection.visible(profile) { - Task { @MainActor in - localSelection = .dashboard - } - } - } - } else { - sidebarContent(isConnected: false, profile: nil) - } - } - - @ViewBuilder - private func sidebarContent(isConnected: Bool, profile: ExtensionProfile?) -> some View { + var body: some View { List(selection: $localSelection) { - if isConnected { + if profile.status.isConnectedStrict { Section(NavigationPage.dashboard.title) { Label("Overview", systemImage: "text.and.command.macwindow") .tint(.textColor) .tag(NavigationPage.dashboard) - NavigationPage.groups.label.tag(NavigationPage.groups) - if Variant.isBeta { - NavigationPage.connections.label.tag(NavigationPage.connections) + if hasGroups { + NavigationPage.groups.label.tag(NavigationPage.groups) } + NavigationPage.connections.label.tag(NavigationPage.connections) } - Divider() ForEach(NavigationPage.macosDefaultPages, id: \.self) { it in it.label } @@ -71,5 +50,90 @@ public struct SidebarView: View { } } } + .onChangeCompat(of: profile.status) { + if !localSelection.visible(profile) { + Task { @MainActor in + localSelection = .dashboard + } + } + } + .onReceive(environments.commandClient.$groups) { groups in + if localSelection == .groups, groups?.isEmpty != false { + Task { @MainActor in + localSelection = .dashboard + } + } + } + } +} + +public struct SidebarView: View { + @Binding var selection: NavigationPage + @EnvironmentObject private var environments: ExtensionEnvironments + @State private var localSelection: NavigationPage = .dashboard + + public init(selection: Binding) { + _selection = selection + } + + public var body: some View { + if ApplicationLibrary.inPreview { + previewContent + } else if environments.extensionProfileLoading { + ProgressView() + } else if let profile = environments.extensionProfile { + SidebarContentView( + selection: $selection, + localSelection: $localSelection, + profile: profile, + environments: environments + ) + } else { + disconnectedContent + } + } + + @ViewBuilder + private var previewContent: some View { + List(selection: $localSelection) { + Section(NavigationPage.dashboard.title) { + Label("Overview", systemImage: "text.and.command.macwindow") + .tint(.textColor) + .tag(NavigationPage.dashboard) + NavigationPage.groups.label.tag(NavigationPage.groups) + NavigationPage.connections.label.tag(NavigationPage.connections) + } + ForEach(NavigationPage.macosDefaultPages, id: \.self) { it in + it.label + } + } + .listStyle(.sidebar) + .scrollDisabled(true) + } + + @ViewBuilder + private var disconnectedContent: some View { + List(selection: $localSelection) { + ForEach(NavigationPage.allCases.filter { $0.visible(nil) }, id: \.self) { it in + it.label + } + } + .listStyle(.sidebar) + .scrollDisabled(true) + .onAppear { + localSelection = selection + } + .onChangeCompat(of: selection) { newValue in + if localSelection != newValue { + localSelection = newValue + } + } + .onChangeCompat(of: localSelection) { newValue in + if selection != newValue { + Task { @MainActor in + selection = newValue + } + } + } } }