diff --git a/ios/FinaleWidget/Components/FinaleWidget.swift b/ios/FinaleWidget/Components/FinaleWidget.swift index f28d98b..8a91fed 100644 --- a/ios/FinaleWidget/Components/FinaleWidget.swift +++ b/ios/FinaleWidget/Components/FinaleWidget.swift @@ -1,9 +1,5 @@ import SwiftUI -func getWidgetBackgroundGradient(for themeColor: ThemeColor) -> LinearGradient { - return LinearGradient(gradient: Gradient(colors: [themeColor.gradientStart, themeColor.gradientEnd]), startPoint: .top, endPoint: .bottom) -} - func getLinkUrl(_ method: String, queryItems: [URLQueryItem]? = nil) -> URL { var components = URLComponents() components.scheme = "finale" @@ -12,6 +8,29 @@ func getLinkUrl(_ method: String, queryItems: [URLQueryItem]? = nil) -> URL { return components.url! } +struct FinaleWidget : View where Content : View { + let themeColor: ThemeColor + @ViewBuilder let content: () -> Content + + private var gradient: some View { + return LinearGradient(gradient: Gradient(colors: [themeColor.gradientStart, themeColor.gradientEnd]), startPoint: .top, endPoint: .bottom) + } + + var body: some View { + if #available(iOS 17.0, *) { + content() + .containerBackground(for: .widget) { + gradient + } + } else { + ZStack { + gradient + content() + } + } + } +} + struct FinaleWidgetLarge : View where Content : View { let title: String let period: Period @@ -21,8 +40,7 @@ struct FinaleWidgetLarge : View where Content : View { @ViewBuilder let content: () -> Content var body: some View { - ZStack { - getWidgetBackgroundGradient(for: themeColor) + FinaleWidget(themeColor: themeColor) { VStack { TitleBar(title: title, period: period, themeColor: themeColor) if !isPreview && username?.isEmpty ?? true { diff --git a/ios/FinaleWidget/FinaleWidgets.swift b/ios/FinaleWidget/FinaleWidgets.swift index c212664..4fc906d 100644 --- a/ios/FinaleWidget/FinaleWidgets.swift +++ b/ios/FinaleWidget/FinaleWidgets.swift @@ -1,6 +1,6 @@ import SwiftUI -@available(iOS 14.0, *) +@available(iOS 15.0, *) @main struct FinaleWidgets: WidgetBundle { @WidgetBundleBuilder diff --git a/ios/FinaleWidget/StatisticsWidget.swift b/ios/FinaleWidget/StatisticsWidget.swift index 83cb8c3..29bd910 100644 --- a/ios/FinaleWidget/StatisticsWidget.swift +++ b/ios/FinaleWidget/StatisticsWidget.swift @@ -96,8 +96,7 @@ struct StatisticsWidgetEntryViewSmall : View { var entry: StatisticsProvider.Entry var body: some View { - ZStack { - getWidgetBackgroundGradient(for: entry.configuration.themeColor) + FinaleWidget(themeColor: entry.configuration.themeColor) { if !entry.isPreview && entry.configuration.username?.isEmpty ?? true { VStack { Image("FinaleIcon") @@ -128,6 +127,7 @@ struct StatisticsWidgetEntryViewLarge : View { } } +@available(iOS 15.0, *) struct StatisticsWidget: Widget { let kind: String = "StatisticsWidget" @@ -138,6 +138,7 @@ struct StatisticsWidget: Widget { .configurationDisplayName("Statistics") .description("Your statistics for a given period.") .supportedFamilies([.systemSmall, .systemMedium]) + .contentMarginsDisabled() } } diff --git a/ios/FinaleWidget/TopEntitiesWidget.swift b/ios/FinaleWidget/TopEntitiesWidget.swift index b66fd58..82350a1 100644 --- a/ios/FinaleWidget/TopEntitiesWidget.swift +++ b/ios/FinaleWidget/TopEntitiesWidget.swift @@ -130,7 +130,7 @@ struct TopEntitiesWidgetEntryViewSmall : View { } } - var body: some View { + var content: some View { ZStack(alignment: .bottomLeading) { EntityImage(imageUrl: imageUrl, entityType: entity?.type, size: .large) .aspectRatio(contentMode: .fit) @@ -172,6 +172,15 @@ struct TopEntitiesWidgetEntryViewSmall : View { } .widgetURL(entity != nil ? getLinkUrl(entity!) : nil) } + + var body: some View { + if #available(iOS 17.0, *) { + content + .containerBackground(for: .widget) { } + } else { + content + } + } } struct TopEntitiesWidgetEntryViewLarge : View { @@ -233,6 +242,7 @@ struct TopEntitiesWidgetEntryViewLarge : View { } } +@available(iOS 15.0, *) struct TopEntitiesWidget: Widget { let kind: String = "TopEntitiesWidget" @@ -242,6 +252,7 @@ struct TopEntitiesWidget: Widget { } .configurationDisplayName("Top Charts") .description("Your top albums, artists, or tracks for a given period.") + .contentMarginsDisabled() } } diff --git a/macos/Podfile.lock b/macos/Podfile.lock index 117de7e..71967f6 100644 --- a/macos/Podfile.lock +++ b/macos/Podfile.lock @@ -24,7 +24,7 @@ PODS: - FlutterMacOS - url_launcher_macos (0.0.1): - FlutterMacOS - - wakelock_macos (0.0.1): + - wakelock_plus (0.0.1): - FlutterMacOS DEPENDENCIES: @@ -39,7 +39,7 @@ DEPENDENCIES: - shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin`) - sqflite (from `Flutter/ephemeral/.symlinks/plugins/sqflite/darwin`) - url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`) - - wakelock_macos (from `Flutter/ephemeral/.symlinks/plugins/wakelock_macos/macos`) + - wakelock_plus (from `Flutter/ephemeral/.symlinks/plugins/wakelock_plus/macos`) EXTERNAL SOURCES: flutter_local_notifications: @@ -64,8 +64,8 @@ EXTERNAL SOURCES: :path: Flutter/ephemeral/.symlinks/plugins/sqflite/darwin url_launcher_macos: :path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos - wakelock_macos: - :path: Flutter/ephemeral/.symlinks/plugins/wakelock_macos/macos + wakelock_plus: + :path: Flutter/ephemeral/.symlinks/plugins/wakelock_plus/macos SPEC CHECKSUMS: flutter_local_notifications: 3805ca215b2fb7f397d78b66db91f6a747af52e4 @@ -79,7 +79,7 @@ SPEC CHECKSUMS: shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78 sqflite: 673a0e54cc04b7d6dba8d24fb8095b31c3a99eec url_launcher_macos: 5f437abeda8c85500ceb03f5c1938a8c5a705399 - wakelock_macos: bc3f2a9bd8d2e6c89fee1e1822e7ddac3bd004a9 + wakelock_plus: 4783562c9a43d209c458cb9b30692134af456269 PODFILE CHECKSUM: f123aa273a6e264bc3e7f1cdc07e8b0ccfdecac7