Add support for openURL event

This commit is contained in:
世界
2024-11-04 23:04:58 +08:00
parent 59aebddaa4
commit 2b33d09134
2 changed files with 17 additions and 2 deletions
+12 -1
View File
@@ -14,6 +14,7 @@ public class CommandClient: ObservableObject {
private let logMaxLines: Int
private var commandClient: LibboxCommandClient?
private var connectTask: Task<Void, Error>?
private var openURLFunc: ((String) -> Void)?
@Published public var isConnected: Bool
@Published public var status: LibboxStatusMessage?
@@ -30,13 +31,15 @@ public class CommandClient: ObservableObject {
public init(_ connectionType: ConnectionType, logMaxLines: Int = 300) {
self.connectionType = connectionType
self.logMaxLines = logMaxLines
openURLFunc = nil
logList = []
clashModeList = []
clashMode = ""
isConnected = false
}
public func connect() {
public func connect(_ openURLFunc: ((String) -> Void)? = nil) {
self.openURLFunc = openURLFunc
if isConnected {
return
}
@@ -49,6 +52,7 @@ public class CommandClient: ObservableObject {
}
public func disconnect() {
openURLFunc = nil
if let connectTask {
connectTask.cancel()
self.connectTask = nil
@@ -223,6 +227,13 @@ public class CommandClient: ObservableObject {
commandClient.connections = connections
}
}
func openURL(_ url: String?) {
guard let url else {
return
}
commandClient.openURLFunc?(url)
}
}
}