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 filteredConnections: [Connection] = []
|
||||||
@Published public var connectionStateFilter: ConnectionStateFilter {
|
@Published public var connectionStateFilter: ConnectionStateFilter {
|
||||||
didSet {
|
didSet {
|
||||||
|
|||||||
+72
-9
@@ -741,7 +741,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Detailed" : {
|
"Detailed" : {
|
||||||
|
"localizations" : {
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "详细"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"Disable Deprecated Warnings" : {
|
"Disable Deprecated Warnings" : {
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
@@ -754,7 +761,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Disabled" : {
|
"Disabled" : {
|
||||||
|
"localizations" : {
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "已禁用"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"Disconnect" : {
|
"Disconnect" : {
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
@@ -1017,7 +1031,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Enabled" : {
|
"Enabled" : {
|
||||||
|
"localizations" : {
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "已启用"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"enforceRoutes" : {
|
"enforceRoutes" : {
|
||||||
"shouldTranslate" : false
|
"shouldTranslate" : false
|
||||||
@@ -1152,7 +1173,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Format" : {
|
"Format" : {
|
||||||
|
"localizations" : {
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "格式化"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"FPS" : {
|
"FPS" : {
|
||||||
"shouldTranslate" : false
|
"shouldTranslate" : false
|
||||||
@@ -1191,7 +1219,14 @@
|
|||||||
"shouldTranslate" : false
|
"shouldTranslate" : false
|
||||||
},
|
},
|
||||||
"Group" : {
|
"Group" : {
|
||||||
|
"localizations" : {
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "分组"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"Groups" : {
|
"Groups" : {
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
@@ -2107,7 +2142,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Real-time Speed" : {
|
"Real-time Speed" : {
|
||||||
|
"localizations" : {
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "实时速率"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"Reboot required." : {
|
"Reboot required." : {
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
@@ -2120,10 +2162,24 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Redo" : {
|
"Redo" : {
|
||||||
|
"localizations" : {
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "重做"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"Register task failed" : {
|
"Register task failed" : {
|
||||||
|
"localizations" : {
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "注册任务失败"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"Releases" : {
|
"Releases" : {
|
||||||
"shouldTranslate" : false
|
"shouldTranslate" : false
|
||||||
@@ -2738,7 +2794,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Undo" : {
|
"Undo" : {
|
||||||
|
"localizations" : {
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "撤销"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"Unexpected message type %lld" : {
|
"Unexpected message type %lld" : {
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
|
|||||||
@@ -2,49 +2,28 @@ import ApplicationLibrary
|
|||||||
import Library
|
import Library
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
public struct SidebarView: View {
|
private struct SidebarContentView: View {
|
||||||
@Binding var selection: NavigationPage
|
@Binding var selection: NavigationPage
|
||||||
@EnvironmentObject private var environments: ExtensionEnvironments
|
@Binding var localSelection: NavigationPage
|
||||||
@State private var localSelection: NavigationPage = .dashboard
|
@ObservedObject var profile: ExtensionProfile
|
||||||
|
var environments: ExtensionEnvironments
|
||||||
|
|
||||||
public init(selection: Binding<NavigationPage>) {
|
private var hasGroups: Bool {
|
||||||
_selection = selection
|
environments.commandClient.groups?.isEmpty == false
|
||||||
}
|
}
|
||||||
|
|
||||||
public var body: some View {
|
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 {
|
|
||||||
List(selection: $localSelection) {
|
List(selection: $localSelection) {
|
||||||
if isConnected {
|
if profile.status.isConnectedStrict {
|
||||||
Section(NavigationPage.dashboard.title) {
|
Section(NavigationPage.dashboard.title) {
|
||||||
Label("Overview", systemImage: "text.and.command.macwindow")
|
Label("Overview", systemImage: "text.and.command.macwindow")
|
||||||
.tint(.textColor)
|
.tint(.textColor)
|
||||||
.tag(NavigationPage.dashboard)
|
.tag(NavigationPage.dashboard)
|
||||||
NavigationPage.groups.label.tag(NavigationPage.groups)
|
if hasGroups {
|
||||||
if Variant.isBeta {
|
NavigationPage.groups.label.tag(NavigationPage.groups)
|
||||||
NavigationPage.connections.label.tag(NavigationPage.connections)
|
|
||||||
}
|
}
|
||||||
|
NavigationPage.connections.label.tag(NavigationPage.connections)
|
||||||
}
|
}
|
||||||
Divider()
|
|
||||||
ForEach(NavigationPage.macosDefaultPages, id: \.self) { it in
|
ForEach(NavigationPage.macosDefaultPages, id: \.self) { it in
|
||||||
it.label
|
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