Skip to content

Commit

Permalink
Merge branch 'meta-dev' into meta
Browse files Browse the repository at this point in the history
  • Loading branch information
mrFq1 committed Dec 10, 2024
2 parents e9178a1 + 0726361 commit a7871c6
Show file tree
Hide file tree
Showing 23 changed files with 191 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: robinraju/[email protected]
with:
repository: 'MetaCubeX/mihomo'
tag: "v1.18.10"
tag: "v1.19.0"
fileName: ".*darwin.*64-v.*.gz"

# releaseId: "62870807"
Expand Down
22 changes: 11 additions & 11 deletions ClashX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -443,36 +443,36 @@
01BCDAC72C9ECD010028FA94 /* Config */ = {
isa = PBXGroup;
children = (
01BCDAC52C9ECD010028FA94 /* ConfigItemView.swift */,
01BCDAC62C9ECD010028FA94 /* ConfigView.swift */,
01BCDAC52C9ECD010028FA94 /* ConfigItemView.swift */,
);
path = Config;
sourceTree = "<group>";
};
01BCDACB2C9ECD010028FA94 /* Connections */ = {
isa = PBXGroup;
children = (
01BCDAC82C9ECD010028FA94 /* Connections.swift */,
01BCDAC92C9ECD010028FA94 /* ConnectionsTableView.swift */,
01BCDACA2C9ECD010028FA94 /* ConnectionsView.swift */,
01BCDAC92C9ECD010028FA94 /* ConnectionsTableView.swift */,
01BCDAC82C9ECD010028FA94 /* Connections.swift */,
);
path = Connections;
sourceTree = "<group>";
};
01BCDACE2C9ECD010028FA94 /* Logs */ = {
isa = PBXGroup;
children = (
01BCDACC2C9ECD010028FA94 /* LogsTableView.swift */,
01BCDACD2C9ECD010028FA94 /* LogsView.swift */,
01BCDACC2C9ECD010028FA94 /* LogsTableView.swift */,
);
path = Logs;
sourceTree = "<group>";
};
01BCDAD22C9ECD010028FA94 /* Overview */ = {
isa = PBXGroup;
children = (
01BCDACF2C9ECD010028FA94 /* OverviewTopItemView.swift */,
01BCDAD02C9ECD010028FA94 /* OverviewView.swift */,
01BCDACF2C9ECD010028FA94 /* OverviewTopItemView.swift */,
01BCDAD12C9ECD010028FA94 /* TrafficGraphView.swift */,
);
path = Overview;
Expand All @@ -481,8 +481,8 @@
01BCDADA2C9ECD010028FA94 /* Providers */ = {
isa = PBXGroup;
children = (
01BCDAD42C9ECD010028FA94 /* ProviderRowView.swift */,
01BCDAD52C9ECD010028FA94 /* ProvidersView.swift */,
01BCDAD42C9ECD010028FA94 /* ProviderRowView.swift */,
01BCDAD62C9ECD010028FA94 /* ProxyProviderInfoView.swift */,
01BCDAD72C9ECD010028FA94 /* ProxyProvidersRowView.swift */,
01BCDAD82C9ECD010028FA94 /* RuleProvidersRowView.swift */,
Expand All @@ -506,22 +506,22 @@
01BCDAE22C9ECD010028FA94 /* Rules */ = {
isa = PBXGroup;
children = (
01BCDAE02C9ECD010028FA94 /* RuleItemView.swift */,
01BCDAE12C9ECD010028FA94 /* RulesView.swift */,
01BCDAE02C9ECD010028FA94 /* RuleItemView.swift */,
);
path = Rules;
sourceTree = "<group>";
};
01BCDAE32C9ECD010028FA94 /* ContentTabs */ = {
isa = PBXGroup;
children = (
01BCDAC72C9ECD010028FA94 /* Config */,
01BCDACB2C9ECD010028FA94 /* Connections */,
01BCDACE2C9ECD010028FA94 /* Logs */,
01BCDAD22C9ECD010028FA94 /* Overview */,
01BCDADA2C9ECD010028FA94 /* Providers */,
01BCDADF2C9ECD010028FA94 /* Proxies */,
01BCDADA2C9ECD010028FA94 /* Providers */,
01BCDAE22C9ECD010028FA94 /* Rules */,
01BCDACB2C9ECD010028FA94 /* Connections */,
01BCDAC72C9ECD010028FA94 /* Config */,
01BCDACE2C9ECD010028FA94 /* Logs */,
01BCDAD32C9ECD010028FA94 /* ProviderProxiesView.swift */,
);
path = ContentTabs;
Expand Down
41 changes: 41 additions & 0 deletions ClashX/Dashboard/DashboardViewContoller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ class DashboardViewContoller: NSViewController {
.info,
.debug
]

enum LogFilter: String, CaseIterable {
case all = "All"
case rule = "Rule"
case dns = "DNS"
case others = "Others"
}

private var sidebarItemObserver: NSObjectProtocol?
private var searchStringObserver: NSObjectProtocol?
Expand Down Expand Up @@ -109,6 +116,7 @@ class DashboardViewContoller: NSViewController {
items.append(.stopConnsItem)
items.append(.searchItem)
case .logs:
items.append(.logFilterItem)
items.append(.logLevelItem)
items.append(.searchItem)
}
Expand Down Expand Up @@ -187,6 +195,7 @@ extension NSToolbarItem.Identifier {
static let hideNamesItem = NSToolbarItem.Identifier("HideNamesItem")
static let stopConnsItem = NSToolbarItem.Identifier("StopConnsItem")
static let logLevelItem = NSToolbarItem.Identifier("LogLevelItem")
static let logFilterItem = NSToolbarItem.Identifier("logFilterItem")
static let searchItem = NSToolbarItem.Identifier("SearchItem")
}

Expand Down Expand Up @@ -224,6 +233,14 @@ extension DashboardViewContoller: NSSearchFieldDelegate {
NotificationCenter.default.post(name: .logLevelChanged, object: nil, userInfo: ["level": level])
}


@objc func setLogFilter(_ sender: NSToolbarItemGroup) {
guard sender.selectedIndex < LogFilter.allCases.count, sender.selectedIndex >= 0 else { return }
let filter = LogFilter.allCases[sender.selectedIndex]

NotificationCenter.default.post(name: .logFilterChanged, object: nil, userInfo: ["filter": filter])
}

}

extension DashboardViewContoller: NSToolbarDelegate, NSToolbarItemValidation {
Expand Down Expand Up @@ -254,21 +271,43 @@ extension DashboardViewContoller: NSToolbarDelegate, NSToolbarItemValidation {
group.controlRepresentation = .collapsed
group.selectedIndex = levels.firstIndex(of: ConfigManager.selectLoggingApiLevel) ?? 0

group.label = "Log Level"

return group
case .logFilterItem:
let titles = LogFilter.allCases.map {
$0.rawValue
}

let group = NSToolbarItemGroup(itemIdentifier: .logFilterItem, titles: titles, selectionMode: .selectOne, labels: titles, target: nil, action: #selector(setLogFilter(_:)))

group.selectionMode = .selectOne
group.controlRepresentation = .collapsed
group.selectedIndex = 0

group.label = "Log Filter"

return group
case .hideNamesItem:
let item = NSToolbarItem(itemIdentifier: .hideNamesItem)
item.target = self
item.action = #selector(hideNames(_:))
item.isBordered = true
item.tag = 0
item.image = NSImage(systemSymbolName: "wand.and.stars", accessibilityDescription: nil)

item.label = "Hide Names"

return item
case .stopConnsItem:
let item = NSToolbarItem(itemIdentifier: .stopConnsItem)
item.target = self
item.action = #selector(stopConns(_:))
item.isBordered = true
item.image = NSImage(systemSymbolName: "stop.circle.fill", accessibilityDescription: nil)

item.label = "Stop All"

return item
default:
break
Expand All @@ -284,6 +323,7 @@ extension DashboardViewContoller: NSToolbarDelegate, NSToolbarItemValidation {
.stopConnsItem,
.hideNamesItem,
.logLevelItem,
.logFilterItem,
.searchItem
]
}
Expand All @@ -294,6 +334,7 @@ extension DashboardViewContoller: NSToolbarDelegate, NSToolbarItemValidation {
.stopConnsItem,
.hideNamesItem,
.logLevelItem,
.logFilterItem,
.searchItem
]
}
Expand Down
1 change: 1 addition & 0 deletions ClashX/Dashboard/Extensions/NotificationNames.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ extension NSNotification.Name {
static let stopConns = NSNotification.Name("StopConns")
static let hideNames = NSNotification.Name("HideNames")
static let logLevelChanged = NSNotification.Name("LogLevelChanged")
static let logFilterChanged = NSNotification.Name("LogFilterChanged")
}
18 changes: 17 additions & 1 deletion ClashX/Dashboard/Models/DBProxyStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class DBProxy: ObservableObject {

switch delay {
case 0:
return .gray
return .red
case ..<200 where !httpsTest:
return .green
case ..<800 where httpsTest:
Expand All @@ -118,3 +118,19 @@ class DBProxy: ObservableObject {
}
}


extension String {
var hiddenID: String {
guard UUID(uuidString: self) != nil else { return "" }
let components = split(separator: "-").map(String.init)
guard components.count == 5 else { return "" }

let re = components[0].prefix(2)
+ components[1].prefix(1)
+ components[2].prefix(1)
+ components[3].prefix(1)
+ components[4].suffix(3)

return String(re)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct ConfigItemView<Content: View>: View {
HStack(content: content)
}
.padding(EdgeInsets(top: 10, leading: 13, bottom: 10, trailing: 13))
.background(Color(compatible: .textBackgroundColor))
.background(Color("SwiftUI Colors/ContentBackgroundColor"))
.cornerRadius(10)
}
}
Expand Down
1 change: 1 addition & 0 deletions ClashX/Dashboard/Views/ContentTabs/Config/ConfigView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct ConfigView: View {
content2
.padding()
}
.background(Color("SwiftUI Colors/WindowBackgroundColor"))
.disabled(!configInited)
.onAppear {
configInited = false
Expand Down
24 changes: 24 additions & 0 deletions ClashX/Dashboard/Views/ContentTabs/Logs/LogsTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct LogsTableView<Item: Hashable>: NSViewRepresentable {

var data: [Item]
var filterString: String
var logFilter: DashboardViewContoller.LogFilter

class NonRespondingScrollView: NSScrollView {
override var acceptsFirstResponder: Bool { false }
Expand Down Expand Up @@ -84,6 +85,29 @@ struct LogsTableView<Item: Hashable>: NSViewRepresentable {
"log",
]

switch logFilter {
case .all:
break
case .rule:
re = re.filter {
$0.log.starts(with: "[Rule")
|| $0.log.starts(with: "[TCP")
|| $0.log.starts(with: "[UDP")
}
case .dns:
re = re.filter {
$0.log.starts(with: "[DNS")
}
case .others:
re = re.filter {
!$0.log.starts(with: "[DNS")
&& !$0.log.starts(with: "[Rule")
&& !$0.log.starts(with: "[TCP")
&& !$0.log.starts(with: "[UDP")
}
}


re = re.filtered(filterString, for: filterKeys)

return re
Expand Down
16 changes: 15 additions & 1 deletion ClashX/Dashboard/Views/ContentTabs/Logs/LogsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ struct LogsView: View {
@EnvironmentObject var logStorage: ClashLogStorage

@State var searchString: String = ""
@State var logFilter = DashboardViewContoller.LogFilter.all

@State var logLevel = ConfigManager.selectLoggingApiLevel

var body: some View {
Group {
LogsTableView(data: logStorage.logs.reversed(), filterString: searchString)
LogsTableView(
data: logStorage.logs.reversed(),
filterString: searchString,
logFilter: logFilter
)
}
.onAppear {
guard let s = ToolbarStore.shared.searchStrings["logs"] else { return }
Expand All @@ -33,13 +39,21 @@ struct LogsView: View {
guard let level = $0.userInfo?["level"] as? ClashLogLevel else { return }
logLevelChanged(level)
}
.onReceive(NotificationCenter.default.publisher(for: .logFilterChanged)) {
guard let level = $0.userInfo?["filter"] as? DashboardViewContoller.LogFilter else { return }
logFilterChanged(level)
}
}

func logLevelChanged(_ level: ClashLogLevel) {
logStorage.logs.removeAll()
ConfigManager.selectLoggingApiLevel = level
ApiRequest.shared.resetLogStreamApi()
}

func logFilterChanged(_ filter: DashboardViewContoller.LogFilter) {
logFilter = filter
}
}

struct LogsView_Previews: PreviewProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct OverviewTopItemView: View {
}
.frame(width: 125)
.padding(EdgeInsets(top: 10, leading: 13, bottom: 10, trailing: 13))
.background(Color(compatible: .textBackgroundColor))
.background(Color("SwiftUI Colors/ContentBackgroundColor"))
.cornerRadius(10)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct OverviewView: View {
self.version = $0?.version ?? ""
}
}
.background(Color("SwiftUI Colors/WindowBackgroundColor"))
}

func updateColumnCount(_ width: Double) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct ProviderRowView: View {
VStack(spacing: 2) {
HStack(alignment: .center) {
Text(hideProxyNames.hide
? String(proxyProvider.id.prefix(8))
? String(proxyProvider.id.hiddenID)
: proxyProvider.name)
.font(.system(size: 15))
Spacer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ struct ProvidersView: View {
@StateObject private var hideProxyNames = HideProxyNames()

var body: some View {

NavigationView {
listView
EmptyView()
}
.background(Color("SwiftUI Colors/WindowBackgroundColor"))
.onReceive(NotificationCenter.default.publisher(for: .toolbarSearchString)) {
guard let string = $0.userInfo?["String"] as? String else { return }
searchString.string = string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct ProxyProviderInfoView: View {
var header: some View {
HStack() {
Text(hideProxyNames.hide
? String(provider.id.prefix(8))
? String(provider.id.hiddenID)
: provider.name)
.font(.system(size: 17))
Text(provider.vehicleType.rawValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct RuleProviderView: View {
VStack(alignment: .leading) {
HStack {
Text(provider.name)
.font(.title)
.font(.title2)
.fontWeight(.medium)
Text(provider.type)
Text(provider.behavior)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct ProxiesView: View {
.listStyle(.plain)
EmptyView()
}
.background(Color("SwiftUI Colors/WindowBackgroundColor"))
.onReceive(NotificationCenter.default.publisher(for: .toolbarSearchString)) {
guard let string = $0.userInfo?["String"] as? String else { return }
searchString.string = string
Expand Down
Loading

0 comments on commit a7871c6

Please sign in to comment.