From e34f3ce201dd170d2f291903db831b023695a4b2 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Mon, 11 Sep 2023 12:04:49 -0500 Subject: [PATCH] [AltWidget] Fixes widgets not appearing pre-iOS 17 --- AltWidget/AltWidgetBundle.swift | 5 +---- AltWidget/Widgets/ActiveAppsWidget.swift | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/AltWidget/AltWidgetBundle.swift b/AltWidget/AltWidgetBundle.swift index b8446a86..7b24ea78 100644 --- a/AltWidget/AltWidgetBundle.swift +++ b/AltWidget/AltWidgetBundle.swift @@ -18,9 +18,6 @@ struct AltWidgetBundle: WidgetBundle IconLockScreenWidget() TextLockScreenWidget() - if #available(iOS 17, *) - { - ActiveAppsWidget() - } + ActiveAppsWidget() } } diff --git a/AltWidget/Widgets/ActiveAppsWidget.swift b/AltWidget/Widgets/ActiveAppsWidget.swift index 5160c1aa..26b81473 100644 --- a/AltWidget/Widgets/ActiveAppsWidget.swift +++ b/AltWidget/Widgets/ActiveAppsWidget.swift @@ -21,18 +21,27 @@ private extension Color static let altGradientExtraDark = Color.init(.displayP3, red: 2.0/255.0, green: 82.0/255.0, blue: 103.0/255.0) } -@available(iOS 17, *) +//@available(iOS 17, *) struct ActiveAppsWidget: Widget { private let kind: String = "ActiveApps" public var body: some WidgetConfiguration { - StaticConfiguration(kind: kind, provider: AppsTimelineProvider()) { entry in - ActiveAppsWidgetView(entry: entry) + if #available(iOS 17, *) + { + return StaticConfiguration(kind: kind, provider: AppsTimelineProvider()) { entry in + ActiveAppsWidgetView(entry: entry) + } + .supportedFamilies([.systemMedium]) + .configurationDisplayName("AltWidget") + .description("View remaining days until your active apps expire. Tap any timer to refresh them in the background.") + } + else + { + // Can't mark ActiveAppsWidget as requiring iOS 17 directly without causing crash on older versions. + // So instead we just return EmptyWidgetConfiguration pre-iOS 17. + return EmptyWidgetConfiguration() } - .supportedFamilies([.systemMedium]) - .configurationDisplayName("AltWidget") - .description("View remaining days until your active apps expire.") } } @@ -139,7 +148,6 @@ private struct ActiveAppsWidgetView: View } #Preview(as: .systemMedium) { - guard #available(iOS 17, *) else { fatalError() } return ActiveAppsWidget() } timeline: { let expiredDate = Date().addingTimeInterval(1 * 60 * 60 * 24 * 7)