LiveActivitySettingsView.swift 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // LoopFollow
  2. // LiveActivitySettingsView.swift
  3. import SwiftUI
  4. struct LiveActivitySettingsView: View {
  5. @State private var laEnabled: Bool = Storage.shared.laEnabled.value
  6. @State private var restartConfirmed = false
  7. var body: some View {
  8. Form {
  9. Section(header: Text("Live Activity")) {
  10. Toggle("Enable Live Activity", isOn: $laEnabled)
  11. }
  12. if laEnabled {
  13. Section {
  14. Button(restartConfirmed ? "Live Activity Restarted" : "Restart Live Activity") {
  15. LiveActivityManager.shared.forceRestart()
  16. restartConfirmed = true
  17. DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
  18. restartConfirmed = false
  19. }
  20. }
  21. .disabled(restartConfirmed)
  22. }
  23. }
  24. }
  25. .onReceive(Storage.shared.laEnabled.$value) { newValue in
  26. if newValue != laEnabled { laEnabled = newValue }
  27. }
  28. .onChange(of: laEnabled) { newValue in
  29. Storage.shared.laEnabled.value = newValue
  30. if !newValue {
  31. LiveActivityManager.shared.end(dismissalPolicy: .immediate)
  32. }
  33. }
  34. .preferredColorScheme(Storage.shared.appearanceMode.value.colorScheme)
  35. .navigationTitle("Live Activity")
  36. .navigationBarTitleDisplayMode(.inline)
  37. }
  38. }