Widget Features: - Add inline voting to timeline widget when no entry exists for today - Show random prompt from notification strings in voting mode - Update vote widget to use simple icon style for selection - Make stats bar full width in voted state view - Add Localizable.strings to widget extension target Bug Fixes: - Fix inverted date calculation in InsightsViewModel streak logic - Replace force unwraps with safe optional handling in widgets - Replace fatalError calls with graceful error handling - Fix CSV import safety in SettingsView Warning Fixes: - Add @retroactive to Color and Date extension conformances - Update deprecated onChange(of:perform:) to new syntax - Replace deprecated applicationIconBadgeNumber with setBadgeCount - Replace deprecated UIApplication.shared.windows API - Add @preconcurrency for Swift 6 protocol conformances - Add missing widget family cases to switch statement - Remove unused variables and #warning directives 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
77 lines
3.1 KiB
Swift
77 lines
3.1 KiB
Swift
//
|
|
// AppDelegate.swift
|
|
// Feels (iOS)
|
|
//
|
|
// Created by Trey Tartt on 1/10/22.
|
|
//
|
|
|
|
import Foundation
|
|
import UserNotifications
|
|
import UIKit
|
|
import WidgetKit
|
|
import SwiftUI
|
|
|
|
class AppDelegate: NSObject, UIApplicationDelegate {
|
|
private let savedOnboardingData = UserDefaultsStore.getOnboarding()
|
|
@AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor
|
|
|
|
@MainActor
|
|
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
|
|
DataController.shared.removeNoForDates()
|
|
DataController.shared.fillInMissingDates()
|
|
UNUserNotificationCenter.current().delegate = self
|
|
|
|
UIPageControl.appearance().currentPageIndicatorTintColor = UIColor(textColor)
|
|
UIPageControl.appearance().pageIndicatorTintColor = UIColor.systemGray
|
|
|
|
let appearance = UITabBarAppearance()
|
|
appearance.configureWithOpaqueBackground()
|
|
UITabBar.appearance().standardAppearance = appearance
|
|
UITabBar.appearance().scrollEdgeAppearance = appearance
|
|
|
|
EventLogger.log(event: "app_launced")
|
|
|
|
return true
|
|
}
|
|
|
|
@MainActor
|
|
func applicationWillEnterForeground(_ application: UIApplication) {
|
|
DataController.shared.fillInMissingDates()
|
|
|
|
// reschedule notifications so there's a new title next notification
|
|
LocalNotification.rescheduleNotifiations()
|
|
|
|
EventLogger.log(event: "app_foregorund")
|
|
}
|
|
}
|
|
|
|
extension AppDelegate: @preconcurrency UNUserNotificationCenterDelegate {
|
|
func requestAuthorization() { }
|
|
|
|
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
|
completionHandler([.badge, .banner, .sound])
|
|
}
|
|
|
|
@MainActor
|
|
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
|
|
if let action = LocalNotification.ActionType(rawValue: response.actionIdentifier) {
|
|
let date = ShowBasedOnVoteLogics.getCurrentVotingDate(onboardingData: savedOnboardingData)
|
|
switch action {
|
|
case .horrible:
|
|
DataController.shared.add(mood: .horrible, forDate: date, entryType: .notification)
|
|
case .bad:
|
|
DataController.shared.add(mood: .bad, forDate: date, entryType: .notification)
|
|
case .average:
|
|
DataController.shared.add(mood: .average, forDate: date, entryType: .notification)
|
|
case .good:
|
|
DataController.shared.add(mood: .good, forDate: date, entryType: .notification)
|
|
case .great:
|
|
DataController.shared.add(mood: .great, forDate: date, entryType: .notification)
|
|
}
|
|
UNUserNotificationCenter.current().setBadgeCount(0)
|
|
}
|
|
WidgetCenter.shared.reloadAllTimelines()
|
|
completionHandler()
|
|
}
|
|
}
|