ProfileTask.swift 789 B

12345678910111213141516171819202122232425262728
  1. // LoopFollow
  2. // ProfileTask.swift
  3. // Created by Jonas Björkert on 2025-01-13.
  4. import Foundation
  5. extension MainViewController {
  6. func scheduleProfileTask(initialDelay: TimeInterval = 3) {
  7. let firstRun = Date().addingTimeInterval(initialDelay)
  8. TaskScheduler.shared.scheduleTask(id: .profile, nextRun: firstRun) { [weak self] in
  9. guard let self = self else { return }
  10. self.profileTaskAction()
  11. }
  12. }
  13. func profileTaskAction() {
  14. guard IsNightscoutEnabled() else {
  15. TaskScheduler.shared.rescheduleTask(id: .profile, to: Date().addingTimeInterval(60))
  16. return
  17. }
  18. webLoadNSProfile()
  19. TaskScheduler.shared.rescheduleTask(id: .profile, to: Date().addingTimeInterval(10 * 60))
  20. }
  21. }