RestartLiveActivityIntent.swift 1.7 KB

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