UI fixes
This commit is contained in:
@@ -69,6 +69,32 @@ public class Profile: Record, Identifiable, ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
public struct ProfilePreview: Identifiable, Hashable {
|
||||
public let id: Int64
|
||||
public let name: String
|
||||
public var order: UInt32
|
||||
public let type: ProfileType
|
||||
public let path: String
|
||||
public let remoteURL: String?
|
||||
public let autoUpdate: Bool
|
||||
public let autoUpdateInterval: Int32
|
||||
public let lastUpdated: Date?
|
||||
public let origin: Profile
|
||||
|
||||
public init(_ profile: Profile) {
|
||||
id = profile.mustID
|
||||
name = profile.name
|
||||
order = profile.order
|
||||
type = profile.type
|
||||
path = profile.path
|
||||
remoteURL = profile.remoteURL
|
||||
autoUpdate = profile.autoUpdate
|
||||
autoUpdateInterval = profile.autoUpdateInterval
|
||||
lastUpdated = profile.lastUpdated
|
||||
origin = profile
|
||||
}
|
||||
}
|
||||
|
||||
public enum ProfileType: Int {
|
||||
case local = 0, icloud, remote
|
||||
}
|
||||
|
||||
@@ -93,33 +93,37 @@ public class CommandClient: ObservableObject {
|
||||
}
|
||||
|
||||
func connected() {
|
||||
DispatchQueue.main.sync {
|
||||
DispatchQueue.main.async { [self] in
|
||||
commandClient.isConnected = true
|
||||
}
|
||||
}
|
||||
|
||||
func disconnected(_: String?) {
|
||||
DispatchQueue.main.sync {
|
||||
DispatchQueue.main.async { [self] in
|
||||
commandClient.isConnected = false
|
||||
}
|
||||
}
|
||||
|
||||
func clearLog() {
|
||||
DispatchQueue.main.async { [self] in
|
||||
commandClient.logList.removeAll()
|
||||
}
|
||||
}
|
||||
|
||||
func writeLog(_ message: String?) {
|
||||
guard let message else {
|
||||
return
|
||||
}
|
||||
var logList = commandClient.logList
|
||||
if logList.count > commandClient.logMaxLines {
|
||||
logList.removeFirst()
|
||||
}
|
||||
logList.append(message)
|
||||
DispatchQueue.main.sync {
|
||||
commandClient.logList = logList
|
||||
DispatchQueue.main.async { [self] in
|
||||
if commandClient.logList.count > commandClient.logMaxLines {
|
||||
commandClient.logList.removeFirst()
|
||||
}
|
||||
commandClient.logList.append(message)
|
||||
}
|
||||
}
|
||||
|
||||
func writeStatus(_ message: LibboxStatusMessage?) {
|
||||
DispatchQueue.main.sync {
|
||||
DispatchQueue.main.async { [self] in
|
||||
commandClient.status = message
|
||||
}
|
||||
}
|
||||
@@ -132,20 +136,20 @@ public class CommandClient: ObservableObject {
|
||||
while groups.hasNext() {
|
||||
newGroups.append(groups.next()!)
|
||||
}
|
||||
DispatchQueue.main.sync {
|
||||
DispatchQueue.main.async { [self] in
|
||||
commandClient.groups = newGroups
|
||||
}
|
||||
}
|
||||
|
||||
func initializeClashMode(_ modeList: LibboxStringIteratorProtocol?, currentMode: String?) {
|
||||
DispatchQueue.main.sync {
|
||||
DispatchQueue.main.async { [self] in
|
||||
commandClient.clashModeList = modeList!.toArray()
|
||||
commandClient.clashMode = currentMode!
|
||||
}
|
||||
}
|
||||
|
||||
func updateClashMode(_ newMode: String?) {
|
||||
DispatchQueue.main.sync {
|
||||
DispatchQueue.main.async { [self] in
|
||||
commandClient.clashMode = newMode!
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
public class ExtensionEnvironments: ObservableObject {
|
||||
@Published public var logClient = CommandClient(.log)
|
||||
@Published public var extensionProfileLoading = true
|
||||
@Published public var extensionProfile: ExtensionProfile?
|
||||
public let profileUpdate = ObjectWillChangePublisher()
|
||||
public let selectedProfileUpdate = ObjectWillChangePublisher()
|
||||
|
||||
public init() {}
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ public class ExtensionPlatformInterface: NSObject, LibboxPlatformInterfaceProtoc
|
||||
}
|
||||
|
||||
public func serviceReload() throws {
|
||||
Task {
|
||||
runBlocking { [self] in
|
||||
await tunnel.reloadService()
|
||||
}
|
||||
}
|
||||
@@ -214,4 +214,8 @@ public class ExtensionPlatformInterface: NSObject, LibboxPlatformInterfaceProtoc
|
||||
try await self.tunnel.setTunnelNetworkSettings(networkSettings)
|
||||
}
|
||||
}
|
||||
|
||||
func reset() {
|
||||
networkSettings = nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +131,9 @@ open class ExtensionProvider: NEPacketTunnelProvider {
|
||||
boxService = nil
|
||||
commandServer.setService(nil)
|
||||
}
|
||||
if let platformInterface {
|
||||
platformInterface.reset()
|
||||
}
|
||||
}
|
||||
|
||||
func reloadService() async {
|
||||
|
||||
Reference in New Issue
Block a user