From e74b472895d444fb7d09090ea184b316ccc4711d Mon Sep 17 00:00:00 2001 From: Ebrahim Tahernejad Date: Sun, 4 Feb 2024 19:16:55 +0330 Subject: [PATCH 1/2] Added shared instance for LogsEventHandler --- ios/Runner/Handlers/LogsEventHandler.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ios/Runner/Handlers/LogsEventHandler.swift b/ios/Runner/Handlers/LogsEventHandler.swift index c1b862083..a3a852470 100644 --- a/ios/Runner/Handlers/LogsEventHandler.swift +++ b/ios/Runner/Handlers/LogsEventHandler.swift @@ -3,6 +3,7 @@ import Combine import Libcore class LogsEventHandler: NSObject, FlutterPlugin, FlutterStreamHandler, LibboxCommandClientHandlerProtocol { + static let shared: LogsEventHandler = LogsEventHandler() static let name = "\(Bundle.main.serviceIdentifier)/service.logs" private var channel: FlutterEventChannel? @@ -15,7 +16,7 @@ class LogsEventHandler: NSObject, FlutterPlugin, FlutterStreamHandler, LibboxCom private var lock: NSLock = NSLock() public static func register(with registrar: FlutterPluginRegistrar) { - let instance = LogsEventHandler() + let instance = LogsEventHandler.shared instance.channel = FlutterEventChannel(name: Self.name, binaryMessenger: registrar.messenger()) instance.channel?.setStreamHandler(instance) } From faf69288898fa503091bb03d9ffe0b95066dc27a Mon Sep 17 00:00:00 2001 From: Ebrahim Tahernejad Date: Sun, 4 Feb 2024 19:19:55 +0330 Subject: [PATCH 2/2] Use shared instance of logs to log --- ios/Runner/VPN/VPNManager.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ios/Runner/VPN/VPNManager.swift b/ios/Runner/VPN/VPNManager.swift index 8bdff45bb..24370285d 100644 --- a/ios/Runner/VPN/VPNManager.swift +++ b/ios/Runner/VPN/VPNManager.swift @@ -86,7 +86,7 @@ class VPNManager: ObservableObject { do { try await loadVPNPreference() } catch { - LogsEventHandler().writeLog(error.localizedDescription) + LogsEventHandler.shared.writeLog(error.localizedDescription) } } @@ -107,7 +107,7 @@ class VPNManager: ObservableObject { try await newManager.loadFromPreferences() self.manager = newManager } catch { - LogsEventHandler().writeLog(error.localizedDescription) + LogsEventHandler.shared.writeLog(error.localizedDescription) } } @@ -117,7 +117,7 @@ class VPNManager: ObservableObject { try await manager.saveToPreferences() try await manager.loadFromPreferences() } catch { - LogsEventHandler().writeLog(error.localizedDescription) + LogsEventHandler.shared.writeLog(error.localizedDescription) } } @@ -157,7 +157,7 @@ class VPNManager: ObservableObject { } try await self?.loadVPNPreference() } catch { - LogsEventHandler().writeLog(error.localizedDescription) + LogsEventHandler.shared.writeLog(error.localizedDescription) } } }.store(in: &cancelBag) @@ -188,7 +188,7 @@ class VPNManager: ObservableObject { } } } catch { - LogsEventHandler().writeLog(error.localizedDescription) + LogsEventHandler.shared.writeLog(error.localizedDescription) } } @@ -202,7 +202,7 @@ class VPNManager: ObservableObject { "DisableMemoryLimit": (disableMemoryLimit ? "YES" : "NO") as NSString, ]) } catch { - LogsEventHandler().writeLog(error.localizedDescription) + LogsEventHandler.shared.writeLog(error.localizedDescription) } connectTime = .now }