Fix menu in connections & Fix sidebar status
This commit is contained in:
@@ -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 {
|
||||
|
||||
+72
-9
@@ -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" : {
|
||||
|
||||
@@ -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<NavigationPage>) {
|
||||
_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<NavigationPage>) {
|
||||
_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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user