Files
ios-client/NetBirdWidgetExtension/Intents/VPNStatusIntent.swift
T
evgeniyChepelev 315283822c iOS home screen widget (#78)
* Add Home Screen widget with VPN toggle and refactor app activation logic

- Add NetBirdWidgetExtension target with small/medium widget sizes
- Support direct connect/disconnect from widget via interactive buttons (iOS 17+)
- Detect missing VPN config or login-required state and open app via deep link
- Poll for stable VPN state after toggle to prevent loader getting stuck
- Add widget shared state keys to GlobalConstants and sync status from MainViewModel
- Fix false "authentication required" alert on app resume after widget disconnect
- Deduplicate app activation logic into shared startActivation/stopActivation
- Extract polling helpers: updateDetailsIfChanged, updatePeersIfChanged, applyExtensionStatus
2026-04-14 10:30:08 +02:00

26 lines
1014 B
Swift

import AppIntents
import NetworkExtension
@available(iOS 16.0, *)
struct VPNStatusIntent: AppIntent {
static var title: LocalizedStringResource = "Get NetBird VPN Status"
static var description: IntentDescription = "Check whether NetBird VPN is connected."
static var openAppWhenRun: Bool = false
func perform() async throws -> some IntentResult & ProvidesDialog {
guard let manager = try await VPNIntentHelpers.loadManager() else {
return .result(dialog: "NetBird VPN is not configured.")
}
if VPNIntentHelpers.isLoginRequired {
return .result(dialog: "NetBird VPN requires sign-in.")
}
let status = WidgetVPNStatus(neStatus: manager.connection.status)
let ip = VPNIntentHelpers.defaults?.string(forKey: WidgetConstants.keyIP) ?? ""
let detail = status == .connected && !ip.isEmpty ? " Your IP is \(ip)." : ""
return .result(dialog: "NetBird VPN is \(status.displayText.lowercased()).\(detail)")
}
}