UI fixes
This commit is contained in:
@@ -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