52 lines
1.8 KiB
Swift
52 lines
1.8 KiB
Swift
//
|
|
// FeelsApp.swift
|
|
// Shared
|
|
//
|
|
// Created by Trey Tartt on 1/5/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
import BackgroundTasks
|
|
import WidgetKit
|
|
|
|
@main
|
|
struct FeelsApp: App {
|
|
@Environment(\.scenePhase) private var scenePhase
|
|
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
|
|
|
let persistenceController = PersistenceController.shared
|
|
@StateObject var iapManager = IAPManager()
|
|
|
|
init() {
|
|
BGTaskScheduler.shared.cancelAllTaskRequests()
|
|
BGTaskScheduler.shared.register(forTaskWithIdentifier: BGTask.updateDBMissingID, using: nil) { (task) in
|
|
BGTask.runFillInMissingDatesTask(task: task as! BGProcessingTask)
|
|
}
|
|
UIApplication.shared.applicationIconBadgeNumber = 0
|
|
}
|
|
|
|
var body: some Scene {
|
|
WindowGroup {
|
|
// build these here so when tints and other things get updated the views / their data dont
|
|
// have to get redrawn
|
|
MainTabView(dayView: DayView(viewModel: DayViewViewModel(addMonthStartWeekdayPadding: false)),
|
|
monthView: MonthView(viewModel: DayViewViewModel(addMonthStartWeekdayPadding: true)),
|
|
yearView: YearView(viewModel: YearViewModel()),
|
|
customizeView: CustomizeView())
|
|
.environment(\.managedObjectContext, persistenceController.viewContext)
|
|
.environmentObject(iapManager)
|
|
}.onChange(of: scenePhase) { phase in
|
|
if phase == .background {
|
|
//BGTask.scheduleBackgroundProcessing()
|
|
WidgetCenter.shared.reloadAllTimelines()
|
|
}
|
|
|
|
if phase == .active {
|
|
UIApplication.shared.applicationIconBadgeNumber = 0
|
|
iapManager.refresh()
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|