RestartLiveActivityIntent.swift 1.4 KB

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