diff --git a/TigerDine.xcodeproj/project.pbxproj b/TigerDine.xcodeproj/project.pbxproj index e40f0d8..150fdd3 100644 --- a/TigerDine.xcodeproj/project.pbxproj +++ b/TigerDine.xcodeproj/project.pbxproj @@ -289,7 +289,7 @@ CODE_SIGN_ENTITLEMENTS = TigerDineWidgets/TigerDineWidgets.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 26; + CURRENT_PROJECT_VERSION = 27; DEVELOPMENT_TEAM = 5GF7GKNTK4; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = TigerDineWidgets/Info.plist; @@ -322,7 +322,7 @@ CODE_SIGN_ENTITLEMENTS = TigerDineWidgets/TigerDineWidgets.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 26; + CURRENT_PROJECT_VERSION = 27; DEVELOPMENT_TEAM = 5GF7GKNTK4; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = TigerDineWidgets/Info.plist; @@ -478,7 +478,7 @@ CODE_SIGN_ENTITLEMENTS = TigerDine/TigerDine.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 26; + CURRENT_PROJECT_VERSION = 27; DEVELOPMENT_TEAM = 5GF7GKNTK4; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; @@ -515,7 +515,7 @@ CODE_SIGN_ENTITLEMENTS = TigerDine/TigerDine.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 26; + CURRENT_PROJECT_VERSION = 27; DEVELOPMENT_TEAM = 5GF7GKNTK4; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; diff --git a/TigerDine/Data/DiningModel.swift b/TigerDine/Data/DiningModel.swift index b0d11d5..50b56bd 100644 --- a/TigerDine/Data/DiningModel.swift +++ b/TigerDine/Data/DiningModel.swift @@ -6,6 +6,7 @@ // import SwiftUI +import WidgetKit @Observable class DiningModel { @@ -74,6 +75,9 @@ class DiningModel { // And then schedule push notifications. await scheduleAllPushes() + // Then refresh widget timelines with the new data. + WidgetCenter.shared.reloadAllTimelines() + // And finally schedule a background refresh 6 hours from now. scheduleNextRefresh() } @@ -88,7 +92,6 @@ class DiningModel { await getDaysRepresented() let decoder = JSONDecoder() let cachedLocationsByDay = try decoder.decode([[DiningLocation]].self, from: (UserDefaults(suiteName: "group.dev.ninjacheetah.RIT-Dining")!.data(forKey: "cachedLocationsByDay")!)) - print(cachedLocationsByDay) // Load cache, update open status, do a notification cleanup, and return. We only need to clean up because loading // cache means that there can't be any new notifications to schedule since the last real data refresh. diff --git a/TigerDineWidgets/Components/HoursGague.swift b/TigerDineWidgets/Components/HoursGague.swift index 89223fa..8e0632b 100644 --- a/TigerDineWidgets/Components/HoursGague.swift +++ b/TigerDineWidgets/Components/HoursGague.swift @@ -40,8 +40,11 @@ struct OpeningHoursGauge: View { GeometryReader { geometry in let width = geometry.size.width let barHeight: CGFloat = 16 + + let startOfToday = Calendar.current.startOfDay(for: now) + let startOfTomorrow = Calendar.current.date(byAdding: .day, value: 1, to: startOfToday)! - let nowX = position(for: now, width: width) + let nowX = position(for: now, start: startOfToday, width: width) ZStack(alignment: .leading) { Capsule() @@ -51,8 +54,12 @@ struct OpeningHoursGauge: View { // We can skip drawing this entire capsule if the location is never open, since there would be no opening period // to draw. if let openTime = openTime, let closeTime = closeTime { - let openX = position(for: openTime, width: width) - let closeX = position(for: closeTime, width: width) + let openX = position(for: openTime, start: startOfToday, width: width) + let closeX = position( + for: closeTime, + start: closeTime < openTime ? startOfTomorrow : startOfToday, + width: width + ) Capsule() .fill( @@ -77,10 +84,9 @@ struct OpeningHoursGauge: View { .frame(height: 20) } - private func position(for date: Date, width: CGFloat) -> CGFloat { - let startOfDay = Calendar.current.startOfDay(for: date) - let seconds = date.timeIntervalSince(startOfDay) - let normalized = min(max(seconds / dayDuration, 0), 1) + private func position(for date: Date, start: Date, width: CGFloat) -> CGFloat { + let seconds = date.timeIntervalSince(start) + let normalized = seconds / dayDuration return normalized * width } }