Fix always on
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import Libbox
|
|
||||||
import Library
|
import Library
|
||||||
import NetworkExtension
|
import NetworkExtension
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
@@ -81,16 +80,7 @@ public struct StartStopButton: View {
|
|||||||
try await profile.start()
|
try await profile.start()
|
||||||
await environments.logClient.connect()
|
await environments.logClient.connect()
|
||||||
} else {
|
} else {
|
||||||
var err: Error?
|
try await profile.stop()
|
||||||
do {
|
|
||||||
try LibboxNewStandaloneCommandClient()!.serviceClose()
|
|
||||||
} catch {
|
|
||||||
err = error
|
|
||||||
}
|
|
||||||
await profile.stop()
|
|
||||||
if let err {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ struct StartServiceIntent: AppIntent {
|
|||||||
}
|
}
|
||||||
try LibboxNewStandaloneCommandClient()!.serviceReload()
|
try LibboxNewStandaloneCommandClient()!.serviceReload()
|
||||||
} else if extensionProfile.status.isConnected {
|
} else if extensionProfile.status.isConnected {
|
||||||
extensionProfile.stop()
|
try await extensionProfile.stop()
|
||||||
try await Task.sleep(nanoseconds: UInt64(100 * Double(NSEC_PER_MSEC)))
|
try await Task.sleep(nanoseconds: UInt64(100 * Double(NSEC_PER_MSEC)))
|
||||||
try await extensionProfile.start()
|
try await extensionProfile.start()
|
||||||
} else {
|
} else {
|
||||||
@@ -65,7 +65,7 @@ struct RestartServiceIntent: AppIntent {
|
|||||||
if extensionProfile.status == .connected {
|
if extensionProfile.status == .connected {
|
||||||
try LibboxNewStandaloneCommandClient()!.serviceReload()
|
try LibboxNewStandaloneCommandClient()!.serviceReload()
|
||||||
} else if extensionProfile.status.isConnected {
|
} else if extensionProfile.status.isConnected {
|
||||||
extensionProfile.stop()
|
try await extensionProfile.stop()
|
||||||
try await Task.sleep(nanoseconds: UInt64(100 * Double(NSEC_PER_MSEC)))
|
try await Task.sleep(nanoseconds: UInt64(100 * Double(NSEC_PER_MSEC)))
|
||||||
try await extensionProfile.start()
|
try await extensionProfile.start()
|
||||||
} else {
|
} else {
|
||||||
@@ -89,7 +89,7 @@ struct StopServiceIntent: AppIntent {
|
|||||||
guard let extensionProfile = try await (ExtensionProfile.load()) else {
|
guard let extensionProfile = try await (ExtensionProfile.load()) else {
|
||||||
return .result()
|
return .result()
|
||||||
}
|
}
|
||||||
extensionProfile.stop()
|
try await extensionProfile.stop()
|
||||||
return .result()
|
return .result()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ struct ToggleServiceIntent: AppIntent {
|
|||||||
return .result(value: false)
|
return .result(value: false)
|
||||||
}
|
}
|
||||||
if extensionProfile.status.isConnected {
|
if extensionProfile.status.isConnected {
|
||||||
extensionProfile.stop()
|
try await extensionProfile.stop()
|
||||||
return .result(value: false)
|
return .result(value: false)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
import Libbox
|
||||||
import NetworkExtension
|
import NetworkExtension
|
||||||
|
|
||||||
public class ExtensionProfile: ObservableObject {
|
public class ExtensionProfile: ObservableObject {
|
||||||
@@ -75,8 +76,14 @@ public class ExtensionProfile: ObservableObject {
|
|||||||
try manager.connection.startVPNTunnel()
|
try manager.connection.startVPNTunnel()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func stop() {
|
public func stop() async throws {
|
||||||
manager.isOnDemandEnabled = false
|
if manager.isOnDemandEnabled {
|
||||||
|
manager.isOnDemandEnabled = false
|
||||||
|
try await manager.saveToPreferences()
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
try LibboxNewStandaloneCommandClient()!.serviceClose()
|
||||||
|
} catch {}
|
||||||
manager.connection.stopVPNTunnel()
|
manager.connection.stopVPNTunnel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public struct MenuView: View {
|
|||||||
if isEnabled {
|
if isEnabled {
|
||||||
try await profile.start()
|
try await profile.start()
|
||||||
} else {
|
} else {
|
||||||
profile.stop()
|
try await profile.stop()
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
alert = Alert(error)
|
alert = Alert(error)
|
||||||
|
|||||||
Reference in New Issue
Block a user