From 476e0d5542b604863d3b1118052df46075559e7e Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Sat, 21 Oct 2023 18:00:29 +0800 Subject: [PATCH] fix: `ios home widget` --- ios/StatusWidget/StatusWidget.swift | 15 +++++---------- ios/WatchApp/ContentView.swift | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/ios/StatusWidget/StatusWidget.swift b/ios/StatusWidget/StatusWidget.swift index b2dcc48f..262f67a1 100644 --- a/ios/StatusWidget/StatusWidget.swift +++ b/ios/StatusWidget/StatusWidget.swift @@ -28,7 +28,7 @@ struct Provider: IntentTimelineProvider { func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline) -> ()) { var url = configuration.url - @Environment(\.widgetFamily) var family: WidgetFamily + let family = context.family if #available(iOSApplicationExtension 16.0, *) { if family == .accessoryInline || family == .accessoryRectangular { url = UserDefaults.standard.string(forKey: accessoryKey) @@ -57,9 +57,6 @@ struct Provider: IntentTimelineProvider { completion(.error(.url("parse url failed"))) return } - completion(.loading) - - UserDefaults.standard.set(url.absoluteString, forKey: accessoryKey) let task = URLSession.shared.dataTask(with: url) { (data, response, error) in if error != nil { @@ -104,7 +101,7 @@ struct StatusWidgetEntryView : View { var body: some View { switch entry.state { case .loading: - ProgressView().widgetBackground() + Text("Loading").widgetBackground() case .error(let err): switch err { case .http(let description): @@ -115,12 +112,11 @@ struct StatusWidgetEntryView : View { Image(systemName: "arrow.clockwise") .resizable() .frame(width: 10, height: 12.7) - } - tint(.gray) + }.tint(.gray) } } .widgetBackground() - case .url(let _): + case .url(_): Link("Open wiki ⬅️", destination: helpUrl) .widgetBackground() } @@ -156,8 +152,7 @@ struct StatusWidgetEntryView : View { Image(systemName: "arrow.clockwise") .resizable() .frame(width: 10, height: 12.7) - } - tint(.gray) + }.tint(.gray) } } else { Text(data.name).font(.system(.title3, design: .monospaced)) diff --git a/ios/WatchApp/ContentView.swift b/ios/WatchApp/ContentView.swift index d6cd94f4..c6b3b66f 100644 --- a/ios/WatchApp/ContentView.swift +++ b/ios/WatchApp/ContentView.swift @@ -52,7 +52,7 @@ struct PageView: View { Image(systemName: "arrow.clockwise") }.buttonStyle(.plain) } - case .emptyUrl, .invalidUrl: + case .url(_): Link("View help", destination: helpUrl) } case .normal(let status):