Files
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

36 lines
990 B
Swift

import WidgetKit
import SwiftUI
struct WidgetEntryView: View {
@Environment(\.widgetFamily) var family
let entry: VPNStatusEntry
var body: some View {
switch family {
case .systemMedium:
MediumWidgetView(entry: entry)
default:
SmallWidgetView(entry: entry)
}
}
}
struct NetBirdWidget: Widget {
let kind = "NetBirdWidgetExtension"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: VPNStatusProvider()) { entry in
if #available(iOS 17.0, *) {
WidgetEntryView(entry: entry)
.containerBackground(.fill.tertiary, for: .widget)
} else {
WidgetEntryView(entry: entry)
.padding()
}
}
.configurationDisplayName("NetBird VPN")
.description("Quick connect or disconnect your VPN.")
.supportedFamilies([.systemSmall, .systemMedium])
}
}