feat: toolbar items

This commit is contained in:
mrFq1
2023-05-27 18:14:13 +08:00
parent 33a4eab579
commit 30922826e8
8 changed files with 134 additions and 54 deletions

View File

@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
010F693B29ED639A00BAAFB5 /* ClashServerAppStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 010F693A29ED639A00BAAFB5 /* ClashServerAppStorage.swift */; };
01359A392A21D88B00A2B3FB /* SidebarListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01359A382A21D88B00A2B3FB /* SidebarListView.swift */; };
01505C4A2A147B84001ACC4F /* DBProviderStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01505C492A147B84001ACC4F /* DBProviderStorage.swift */; };
01505C4C2A14A1A3001ACC4F /* ProviderRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01505C4B2A14A1A3001ACC4F /* ProviderRowView.swift */; };
01505C4E2A14AAEB001ACC4F /* ProviderProxiesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01505C4D2A14AAEB001ACC4F /* ProviderProxiesView.swift */; };
@@ -69,6 +70,7 @@
/* Begin PBXFileReference section */
010F693A29ED639A00BAAFB5 /* ClashServerAppStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClashServerAppStorage.swift; sourceTree = "<group>"; };
01359A382A21D88B00A2B3FB /* SidebarListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarListView.swift; sourceTree = "<group>"; };
01505C492A147B84001ACC4F /* DBProviderStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBProviderStorage.swift; sourceTree = "<group>"; };
01505C4B2A14A1A3001ACC4F /* ProviderRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderRowView.swift; sourceTree = "<group>"; };
01505C4D2A14AAEB001ACC4F /* ProviderProxiesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderProxiesView.swift; sourceTree = "<group>"; };
@@ -282,6 +284,7 @@
isa = PBXGroup;
children = (
0192317029DD566000539EDD /* SidebarView.swift */,
01359A382A21D88B00A2B3FB /* SidebarListView.swift */,
0192318429DD7DCD00539EDD /* SidebarItemView.swift */,
0192318229DD70B400539EDD /* SidebarItem.swift */,
);
@@ -481,6 +484,7 @@
01A351A229DD8F440054894E /* RuleItemView.swift in Sources */,
01F885D529E053DE008241EB /* ProxyItemView.swift in Sources */,
0172F1312A1FB06100EE2B6D /* String+Encode.swift in Sources */,
01359A392A21D88B00A2B3FB /* SidebarListView.swift in Sources */,
01DCEFB12A150E8B00DBBDB3 /* RuleProvidersRowView.swift in Sources */,
01F5E3F42A1E53F4008F3DEB /* ConfigItemView.swift in Sources */,
0172F1352A1FB0B900EE2B6D /* ConfigManager.swift in Sources */,

View File

@@ -18,10 +18,15 @@ struct ConnectionsView: View {
filterString: searchString)
.background(Color(nsColor: .textBackgroundColor))
.searchable(text: $searchString)
.toolbar {
ToolbarItem {
Button {
ApiRequest.closeAllConnection()
} label: {
Image(systemName: "stop.circle.fill")
}
}
}
}
}

View File

@@ -11,6 +11,7 @@ struct LogsView: View {
@EnvironmentObject var logStorage: ClashLogStorage
@State var searchString: String = ""
@State var logLevel = ConfigManager.selectLoggingApiLevel
var logs: [ClashLogStorage.ClashLog] {
let logs: [ClashLogStorage.ClashLog] = logStorage.logs.reversed()
@@ -45,6 +46,28 @@ struct LogsView: View {
TableColumn("", value: \.log)
}
.searchable(text: $searchString)
.toolbar {
ToolbarItem {
Picker("", selection: $logLevel) {
ForEach([
ClashLogLevel.silent,
.error,
.warning,
.info,
.debug
], id: \.self) {
Text($0.rawValue.capitalized).tag($0)
}
}
.pickerStyle(.menu)
.onChange(of: logLevel) { newValue in
guard newValue != ConfigManager.selectLoggingApiLevel else { return }
logStorage.logs.removeAll()
ConfigManager.selectLoggingApiLevel = newValue
ApiRequest.shared.resetLogStreamApi()
}
}
}
}
}

View File

@@ -8,9 +8,11 @@ import SwiftUI
struct ProvidersView: View {
@ObservedObject var providerStorage = DBProviderStorage()
@EnvironmentObject var hideProxyNames: HideProxyNames
@State private var searchString = ProxiesSearchString()
@StateObject private var hideProxyNames = HideProxyNames()
var body: some View {
NavigationView {
@@ -40,6 +42,16 @@ struct ProvidersView: View {
.onAppear {
loadProviders()
}
.environmentObject(hideProxyNames)
.toolbar {
ToolbarItem {
Button {
hideProxyNames.hide = !hideProxyNames.hide
} label: {
Image(systemName: hideProxyNames.hide ? "eyeglasses" : "wand.and.stars")
}
}
}
}
func loadProviders() {

View File

@@ -19,6 +19,8 @@ struct ProxiesView: View {
@State private var searchString = ProxiesSearchString()
@State private var isGlobalMode = false
@StateObject private var hideProxyNames = HideProxyNames()
var body: some View {
NavigationView {
List(proxyStorage.groups, id: \.id) { group in
@@ -36,6 +38,16 @@ struct ProxiesView: View {
.onAppear {
loadProxies()
}
.environmentObject(hideProxyNames)
.toolbar {
ToolbarItem {
Button {
hideProxyNames.hide = !hideProxyNames.hide
} label: {
Image(systemName: hideProxyNames.hide ? "eyeglasses" : "wand.and.stars")
}
}
}
}

View File

@@ -16,8 +16,6 @@ struct ContentView: View {
private let runningState = NotificationCenter.default.publisher(for: .init("ClashRunningStateChanged"))
@State private var isRunning = false
@StateObject private var hideProxyNames = HideProxyNames()
var body: some View {
Group {
if !isRunning {
@@ -31,7 +29,6 @@ struct ContentView: View {
}
}
}
.environmentObject(hideProxyNames)
.toolbar {
ToolbarItem(placement: .navigation) {
Button {
@@ -40,16 +37,6 @@ struct ContentView: View {
Image(systemName: "sidebar.left")
}
.help("Toggle Sidebar")
.disabled(!isRunning)
}
ToolbarItem {
Button {
hideProxyNames.hide = !hideProxyNames.hide
} label: {
Image(systemName: hideProxyNames.hide ? "eyeglasses" : "wand.and.stars")
}
.disabled(!isRunning)
}
}
.onReceive(runningState) { _ in

View File

@@ -0,0 +1,68 @@
//
// SidebarListView.swift
// ClashX Dashboard
//
//
import SwiftUI
struct SidebarListView: View {
@Binding var selectionName: String?
var body: some View {
List {
NavigationLink(destination: OverviewView(),
tag: "Overview",
selection: $selectionName) {
Label("Overview", systemImage: "chart.bar.xaxis")
}
NavigationLink(destination: ProxiesView(),
tag: "Proxies",
selection: $selectionName) {
Label("Proxies", systemImage: "globe.asia.australia")
}
NavigationLink(destination: ProvidersView(),
tag: "Providers",
selection: $selectionName) {
Label("Providers", systemImage: "link.icloud")
}
NavigationLink(destination: RulesView(),
tag: "Rules",
selection: $selectionName) {
Label("Rules", systemImage: "waveform.and.magnifyingglass")
}
NavigationLink(destination: ConnectionsView(),
tag: "Conns",
selection: $selectionName) {
Label("Conns", systemImage: "app.connected.to.app.below.fill")
}
NavigationLink(destination: ConfigView(),
tag: "Config",
selection: $selectionName) {
Label("Config", systemImage: "slider.horizontal.3")
}
NavigationLink(destination: LogsView(),
tag: "Logs",
selection: $selectionName) {
Label("Logs", systemImage: "wand.and.stars.inverse")
}
}
.listStyle(.sidebar)
}
}
//struct SidebarListView_Previews: PreviewProvider {
// static var previews: some View {
// SidebarListView()
// }
//}

View File

@@ -15,50 +15,19 @@ struct SidebarView: View {
@State private var sidebarSelectionName: String? = "Overview"
@State private var sidebarItems = [
SidebarItem(name: "Overview",
icon: "chart.bar.xaxis",
view: AnyView(OverviewView())),
SidebarItem(name: "Proxies",
icon: "globe.asia.australia",
view: AnyView(ProxiesView())),
SidebarItem(name: "Providers",
icon: "link.icloud",
view: AnyView(ProvidersView())),
SidebarItem(name: "Rules",
icon: "waveform.and.magnifyingglass",
view: AnyView(RulesView())),
SidebarItem(name: "Conns",
icon: "app.connected.to.app.below.fill",
view: AnyView(ConnectionsView())),
SidebarItem(name: "Config",
icon: "slider.horizontal.3",
view: AnyView(ConfigView())),
SidebarItem(name: "Logs",
icon: "wand.and.stars.inverse",
view: AnyView(LogsView()))
]
var body: some View {
ScrollViewReader { scrollViewProxy in
List(sidebarItems, id: \.id) { item in
SidebarItemView(item: item, selectionName: $sidebarSelectionName)
}
.listStyle(.sidebar)
SidebarListView(selectionName: $sidebarSelectionName)
}
.environmentObject(clashApiDatasStorage.overviewData)
.environmentObject(clashApiDatasStorage.logStorage)
.environmentObject(clashApiDatasStorage.connsStorage)
.onAppear {
ConfigManager.selectLoggingApiLevel = .debug
clashApiDatasStorage.resetStreamApi()
if ConfigManager.selectLoggingApiLevel == .unknow {
ConfigManager.selectLoggingApiLevel = .info
}
clashApiDatasStorage.resetStreamApi()
connsQueue.sync {
clashApiDatasStorage.connsStorage.conns
.removeAll()