WIP - a lot of uncommitted work
This commit is contained in:
@@ -7,15 +7,17 @@
|
||||
|
||||
import SwiftUI
|
||||
import BackgroundTasks
|
||||
import WidgetKit
|
||||
|
||||
@main
|
||||
struct FeelsApp: App {
|
||||
@Environment(\.scenePhase) private var scenePhase
|
||||
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
||||
|
||||
let persistenceController = PersistenceController.shared
|
||||
|
||||
init() {
|
||||
// persistenceController.fillInMissingDates()
|
||||
|
||||
BGTaskScheduler.shared.cancelAllTaskRequests()
|
||||
BGTaskScheduler.shared.register(forTaskWithIdentifier: BGTask.updateDBMissingID, using: nil) { (task) in
|
||||
BGTask.runFillInMissingDatesTask(task: task as! BGProcessingTask)
|
||||
@@ -30,38 +32,8 @@ struct FeelsApp: App {
|
||||
if phase == .background {
|
||||
BGTask.scheduleBackgroundProcessing()
|
||||
print("background")
|
||||
WidgetCenter.shared.reloadAllTimelines()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class BGTask {
|
||||
static let updateDBMissingID = "com.88oak.Feels.dbUpdateMissing"
|
||||
|
||||
class func runFillInMissingDatesTask(task: BGProcessingTask) {
|
||||
BGTask.scheduleBackgroundProcessing()
|
||||
|
||||
task.expirationHandler = {
|
||||
task.setTaskCompleted(success: false)
|
||||
}
|
||||
|
||||
PersistenceController.shared.fillInMissingDates()
|
||||
task.setTaskCompleted(success: true)
|
||||
}
|
||||
|
||||
class func scheduleBackgroundProcessing() {
|
||||
let request = BGProcessingTaskRequest(identifier: BGTask.updateDBMissingID)
|
||||
request.requiresNetworkConnectivity = false
|
||||
request.requiresExternalPower = false
|
||||
|
||||
var runDate = Calendar.current.date(byAdding: .day, value: 1, to: Date())
|
||||
runDate = Calendar.current.date(bySettingHour: 0, minute: 1, second: 0, of: runDate!)
|
||||
request.earliestBeginDate = runDate
|
||||
|
||||
do {
|
||||
try BGTaskScheduler.shared.submit(request)
|
||||
} catch {
|
||||
print("Could not schedule image fetch: (error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user