RestartLiveActivityIntent.swift 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // LoopFollow
  2. // RestartLiveActivityIntent.swift
  3. import AppIntents
  4. import UIKit
  5. @available(iOS 16.4, *)
  6. struct RestartLiveActivityIntent: AppIntent, ForegroundContinuableIntent {
  7. static var title: LocalizedStringResource = "Restart Live Activity"
  8. static var description = IntentDescription("Starts or restarts the LoopFollow Live Activity.")
  9. func perform() async throws -> some IntentResult & ProvidesDialog {
  10. Storage.shared.laEnabled.value = true
  11. let keyId = Storage.shared.lfKeyId.value
  12. let apnsKey = Storage.shared.lfApnsKey.value
  13. if keyId.isEmpty || apnsKey.isEmpty {
  14. if let url = URL(string: "loopfollow://settings/live-activity") {
  15. await MainActor.run { UIApplication.shared.open(url) }
  16. }
  17. return .result(dialog: "Please enter your APNs credentials in LoopFollow settings to use the Live Activity.")
  18. }
  19. if #available(iOS 26.0, *) {
  20. try await continueInForeground()
  21. }
  22. await MainActor.run { LiveActivityManager.shared.forceRestart() }
  23. return .result(dialog: "Live Activity restarted.")
  24. }
  25. }
  26. @available(iOS 16.4, *)
  27. struct LoopFollowAppShortcuts: AppShortcutsProvider {
  28. static var appShortcuts: [AppShortcut] {
  29. AppShortcut(
  30. intent: RestartLiveActivityIntent(),
  31. phrases: ["Restart Live Activity in \(.applicationName)"],
  32. shortTitle: "Restart Live Activity",
  33. systemImageName: "dot.radiowaves.left.and.right"
  34. )
  35. }
  36. }