mirror of
https://github.com/netbirdio/ios-client.git
synced 2026-09-23 09:28:33 -07:00
* feat(widget): replace action button with toggle switch control All connection states now render as a unified toggle-style control: green (connected), red (disconnected), orange with spinner (transitioning). * fix(widget+auth): toggle UI, VPN state sync, and login flow fixes * fix(widget+sdk): update Go SDK to fix/ios-debug-bundle, fix Control Center transitioning state and app disconnect flash * fix(widget): remove transitioning states, update toggle colors and UI * Change color indicator * fix(widget+auth): toggle UI, VPN state sync, and login flow fixes * fix framework version
54 lines
1.6 KiB
Swift
54 lines
1.6 KiB
Swift
import AppIntents
|
|
import NetworkExtension
|
|
import WidgetKit
|
|
|
|
@available(iOS 18.0, *)
|
|
struct SetVPNStateIntent: SetValueIntent {
|
|
static var title: LocalizedStringResource = "Set NetBird VPN State"
|
|
static var openAppWhenRun: Bool = false
|
|
|
|
@Parameter(title: "Connect")
|
|
var value: Bool
|
|
|
|
func perform() async throws -> some IntentResult {
|
|
let defaults = VPNIntentHelpers.defaults
|
|
let loginRequired = defaults?.bool(forKey: WidgetConstants.keyLoginRequired) ?? false
|
|
|
|
guard !loginRequired else {
|
|
await reload()
|
|
return .result()
|
|
}
|
|
|
|
guard let manager = await loadManager() else {
|
|
await reload()
|
|
return .result()
|
|
}
|
|
|
|
if value {
|
|
guard let session = manager.connection as? NETunnelProviderSession else {
|
|
await reload()
|
|
return .result()
|
|
}
|
|
try VPNIntentHelpers.startTunnel(session: session)
|
|
} else {
|
|
manager.connection.stopVPNTunnel()
|
|
}
|
|
|
|
await VPNIntentHelpers.waitForStableState(manager: manager)
|
|
await reload()
|
|
return .result()
|
|
}
|
|
|
|
private func loadManager() async -> NETunnelProviderManager? {
|
|
await withCheckedContinuation { continuation in
|
|
NETunnelProviderManager.loadAllFromPreferences { managers, error in
|
|
continuation.resume(returning: managers?.first)
|
|
}
|
|
}
|
|
}
|
|
|
|
private func reload() async {
|
|
await ControlCenter.shared.reloadControls(ofKind: NetBirdVPNControl.kind)
|
|
}
|
|
}
|