Restart service when settings change

This commit is contained in:
世界
2025-12-07 10:28:51 +08:00
parent bd5e5f3a79
commit 39338ab133
10 changed files with 77 additions and 22 deletions
+13
View File
@@ -108,6 +108,19 @@ public class ExtensionProfile: ObservableObject {
manager.connection.stopVPNTunnel()
}
public func restart() async throws {
try await stop()
var waitSeconds = 0
while await MainActor.run(body: { status }) != .disconnected {
try await Task.sleep(nanoseconds: NSEC_PER_SEC)
waitSeconds += 1
if waitSeconds >= 5 {
throw NSError(domain: "Restart service timeout", code: 0)
}
}
try await start()
}
public static func load() async throws -> ExtensionProfile? {
let managers = try await NETunnelProviderManager.loadAllFromPreferences()
if managers.isEmpty {