Add swiftlint & Minor fixes

This commit is contained in:
世界
2025-11-27 16:10:55 +08:00
parent 8855e0eef9
commit 0bfb6d2516
29 changed files with 382 additions and 196 deletions
@@ -23,8 +23,10 @@ public struct GroupListView: View {
}
}
.onAppear {
viewModel.setCommandClient(environments.commandClient)
viewModel.connect()
}
.onReceive(environments.commandClient.$groups) { groups in
viewModel.setGroups(groups)
}
}
}
@@ -1,4 +1,3 @@
import Combine
import Libbox
import Library
import SwiftUI
@@ -8,21 +7,8 @@ public class GroupListViewModel: ObservableObject {
@Published public var isLoading = true
@Published public var groups: [OutboundGroup] = []
private var commandClient: CommandClient?
private var cancellables = Set<AnyCancellable>()
public init() {}
public func setCommandClient(_ client: CommandClient) {
commandClient = client
client.$groups
.compactMap { $0 }
.sink { [weak self] goGroups in
self?.setGroups(goGroups)
}
.store(in: &cancellables)
}
public func connect() {
if ApplicationLibrary.inPreview {
groups = [
@@ -40,7 +26,8 @@ public class GroupListViewModel: ObservableObject {
}
}
private func setGroups(_ goGroups: [LibboxOutboundGroup]) {
public func setGroups(_ goGroups: [LibboxOutboundGroup]?) {
guard let goGroups else { return }
var groups = [OutboundGroup]()
for goGroup in goGroups {
var items = [OutboundGroupItem]()
@@ -2,7 +2,7 @@ import Foundation
import Libbox
import SwiftUI
public struct OutboundGroup: Codable {
public struct OutboundGroup: Codable, Hashable {
let tag: String
let type: String
var selected: String
@@ -10,13 +10,16 @@ public struct OutboundGroup: Codable {
var isExpand: Bool
let items: [OutboundGroupItem]
var hashValue: Int {
var value = tag.hashValue
(value, _) = value.addingReportingOverflow(selected.hashValue)
public func hash(into hasher: inout Hasher) {
hasher.combine(tag)
hasher.combine(selected)
for item in items {
(value, _) = value.addingReportingOverflow(item.urlTestTime.hashValue)
hasher.combine(item.urlTestTime)
}
return value
}
public static func == (lhs: OutboundGroup, rhs: OutboundGroup) -> Bool {
lhs.hashValue == rhs.hashValue
}
}