From 94afbb1bcfd52752cb3860b0e971cacd034aeef6 Mon Sep 17 00:00:00 2001 From: Shawn Date: Thu, 2 Nov 2023 09:58:07 -0600 Subject: [PATCH] Cleanup --- .../WonderWidgetViewComponents.swift | 8 +++++--- ios/WonderousWidget/WonderousWidget.swift | 18 +++++++++--------- ios/WonderousWidget/WonderousWidgetView.swift | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/ios/WonderousWidget/WonderWidgetViewComponents.swift b/ios/WonderousWidget/WonderWidgetViewComponents.swift index d9fc8529..5b558a95 100644 --- a/ios/WonderousWidget/WonderWidgetViewComponents.swift +++ b/ios/WonderousWidget/WonderWidgetViewComponents.swift @@ -5,13 +5,16 @@ import SwiftUI // Loads a default image from the flutter assets bundle, // or displays a base64 encoded image that has been saved from the flutter application struct BgImage : View { - var entry: WonderousEntry + var entry: WonderousTimelineEntry var body: some View { var uiImage:UIImage?; + // If there is no saved imageData, use the default bg image if(entry.imageData.isEmpty){ let defaultImage = flutterAssetBundle.appending(path: "/assets/images/widget/background-empty.jpg").path(); uiImage = UIImage(contentsOfFile: defaultImage); - } else { + } + // Load a base64 encoded image that has been written by the flutter app + else { uiImage = UIImage(data: Data(base64Encoded: entry.imageData)!) } if(uiImage != nil){ @@ -34,7 +37,6 @@ struct BgImage : View { struct GaugeProgressStyle: ProgressViewStyle { func makeBody(configuration: Configuration) -> some View { let fractionCompleted = configuration.fractionCompleted ?? 0 - return ZStack { Circle() .stroke(Color.body, style: StrokeStyle(lineWidth: 2)) diff --git a/ios/WonderousWidget/WonderousWidget.swift b/ios/WonderousWidget/WonderousWidget.swift index a2bfc5fe..d7d65fd0 100644 --- a/ios/WonderousWidget/WonderousWidget.swift +++ b/ios/WonderousWidget/WonderousWidget.swift @@ -3,7 +3,7 @@ import SwiftUI import Intents /// Entry, is passed into the view and defines the data it needs -struct WonderousEntry : TimelineEntry { +struct WonderousTimelineEntry : TimelineEntry { let date: Date let discoveredCount:Int; var title:String = ""; @@ -17,7 +17,7 @@ struct WonderousWidget: Widget { let kind: String = "WonderousWidget" var body: some WidgetConfiguration { - StaticConfiguration(kind: kind, provider: Provider()) { entry in + StaticConfiguration(kind: kind, provider: WonderousTimelineProvider()) { entry in WonderousWidgetView(entry: entry) } .configurationDisplayName("Wonderous Widget") @@ -27,15 +27,15 @@ struct WonderousWidget: Widget { } // Provider,returns various WonderousEntry configs based on current context -struct Provider: TimelineProvider { +struct WonderousTimelineProvider: TimelineProvider { // Provide an entry for a placeholder version of the widget - func placeholder(in context: Context) -> WonderousEntry { - WonderousEntry(date: Date(), discoveredCount: 0) + func placeholder(in context: Context) -> WonderousTimelineEntry { + WonderousTimelineEntry(date: Date(), discoveredCount: 0) } // Provide an entry for the current time and state of the widget - func getSnapshot(in context: Context, completion: @escaping (WonderousEntry) -> ()) { - let entry:WonderousEntry + func getSnapshot(in context: Context, completion: @escaping (WonderousTimelineEntry) -> ()) { + let entry:WonderousTimelineEntry let userDefaults = UserDefaults(suiteName: "group.com.gskinner.flutter.wonders.widget") let discoveredCount = userDefaults?.integer(forKey: "discoveredCount") ?? 0 let title = userDefaults?.string(forKey: "lastDiscoveredTitle") ?? "" @@ -44,7 +44,7 @@ struct Provider: TimelineProvider { // if(context.isPreview){ // entry = WonderousEntry(date: Date(), discoveredCount: discoveredCount) // } - entry = WonderousEntry( + entry = WonderousTimelineEntry( date: Date(), discoveredCount:discoveredCount, title: title, @@ -55,7 +55,7 @@ struct Provider: TimelineProvider { } // Provide an array of entries for the current time and, optionally, any future times - func getTimeline(in context: Context, completion: @escaping (Timeline) -> ()) { + func getTimeline(in context: Context, completion: @escaping (Timeline) -> ()) { getSnapshot(in: context) { (entry) in let timeline = Timeline(entries: [entry], policy: .atEnd) completion(timeline) diff --git a/ios/WonderousWidget/WonderousWidgetView.swift b/ios/WonderousWidget/WonderousWidgetView.swift index f11c441d..1d23ee3d 100644 --- a/ios/WonderousWidget/WonderousWidgetView.swift +++ b/ios/WonderousWidget/WonderousWidgetView.swift @@ -5,7 +5,7 @@ import Intents // Defines the view / layout of the widget struct WonderousWidgetView : View { @Environment(\.widgetFamily) var family: WidgetFamily - var entry: Provider.Entry + var entry: WonderousTimelineProvider.Entry var body: some View { let showTitle = family == .systemLarge let showIcon = family != .systemSmall @@ -62,7 +62,7 @@ struct WonderousWidgetView : View { startPoint: .center, endPoint: .bottom) content.padding(16) - }.widgetURL(URL(string: "wonderous://collection")) + }.widgetURL(URL(string: "wonderous:///collection")) } }