2023-10-24 18:29:53 +03:30
|
|
|
import Foundation
|
2024-02-03 21:21:46 +03:30
|
|
|
import Combine
|
2024-02-04 02:50:54 +03:30
|
|
|
import Libcore
|
2023-10-24 18:29:53 +03:30
|
|
|
|
2024-02-10 04:42:58 +03:30
|
|
|
class LogsEventHandler: NSObject, FlutterPlugin, FlutterStreamHandler {
|
2023-12-26 22:26:06 +03:30
|
|
|
static let name = "\(Bundle.main.serviceIdentifier)/service.logs"
|
2023-10-24 18:29:53 +03:30
|
|
|
|
2024-02-10 04:42:58 +03:30
|
|
|
private var commandClient: CommandClient?
|
2024-02-04 02:50:54 +03:30
|
|
|
private var events: FlutterEventSink?
|
2024-02-10 04:42:58 +03:30
|
|
|
private var channel: FlutterEventChannel?
|
|
|
|
|
private var cancellable: AnyCancellable?
|
2024-02-04 02:50:54 +03:30
|
|
|
|
2023-10-24 18:29:53 +03:30
|
|
|
public static func register(with registrar: FlutterPluginRegistrar) {
|
2024-02-10 04:42:58 +03:30
|
|
|
let instance = LogsEventHandler()
|
|
|
|
|
instance.channel = FlutterEventChannel(name: Self.name,
|
|
|
|
|
binaryMessenger: registrar.messenger())
|
2024-02-04 02:50:54 +03:30
|
|
|
instance.channel?.setStreamHandler(instance)
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-24 18:29:53 +03:30
|
|
|
public func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {
|
2024-02-10 04:42:58 +03:30
|
|
|
FileManager.default.changeCurrentDirectoryPath(FilePath.sharedDirectory.path)
|
2024-02-04 02:50:54 +03:30
|
|
|
self.events = events
|
2024-02-10 04:42:58 +03:30
|
|
|
commandClient = CommandClient(.log)
|
|
|
|
|
commandClient?.connect()
|
|
|
|
|
cancellable = commandClient?.$logList.sink{ [self] logs in
|
|
|
|
|
events(logs)
|
|
|
|
|
}
|
2023-10-24 18:29:53 +03:30
|
|
|
return nil
|
|
|
|
|
}
|
2024-02-04 02:50:54 +03:30
|
|
|
|
2023-10-24 18:29:53 +03:30
|
|
|
public func onCancel(withArguments arguments: Any?) -> FlutterError? {
|
2024-02-10 04:42:58 +03:30
|
|
|
commandClient?.disconnect()
|
|
|
|
|
cancellable?.cancel()
|
2024-02-04 02:50:54 +03:30
|
|
|
events = nil
|
2023-10-24 18:29:53 +03:30
|
|
|
return nil
|
|
|
|
|
}
|
2024-02-04 02:50:54 +03:30
|
|
|
}
|
|
|
|
|
|
2024-02-10 04:42:58 +03:30
|
|
|
/*
|
2024-02-04 02:50:54 +03:30
|
|
|
extension LogsEventHandler {
|
|
|
|
|
public func clearLog() {}
|
|
|
|
|
public func connected() {}
|
|
|
|
|
public func disconnected(_ message: String?) {}
|
|
|
|
|
public func initializeClashMode(_ modeList: LibboxStringIteratorProtocol?, currentMode: String?) {}
|
|
|
|
|
public func updateClashMode(_ newMode: String?) {}
|
|
|
|
|
public func writeGroups(_ message: LibboxOutboundGroupIteratorProtocol?) {}
|
|
|
|
|
public func writeStatus(_ message: LibboxStatusMessage?) {}
|
2023-10-24 18:29:53 +03:30
|
|
|
}
|
2024-02-10 04:42:58 +03:30
|
|
|
*/
|