123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import WidgetKit
- import SwiftUI
- struct Provider: TimelineProvider {
- typealias Entry = DashboardDataEntry
- func placeholder(in context: Context) -> Entry {
- return Entry(date: Date(), dashboardDatas: [], isPlaceholder: true, title: getTitle(account: nil))
- }
- func getSnapshot(in context: Context, completion: @escaping (Entry) -> Void) {
- readDashboard { dashboardDatas, isPlaceholder, title in
- completion(Entry(date: Date(), dashboardDatas: dashboardDatas, isPlaceholder: isPlaceholder, title: title))
- }
- }
- func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> Void) {
- readDashboard { dashboardDatas, isPlaceholder, title in
- let timeLine = Timeline(entries: [Entry(date: Date(), dashboardDatas: dashboardDatas, isPlaceholder: isPlaceholder, title: title)], policy: .atEnd)
- completion(timeLine)
- }
- }
- }
- @main
- struct DashboardWidget: Widget {
- let kind: String = "NextcloudWidget"
- var body: some WidgetConfiguration {
- StaticConfiguration(kind: kind, provider: Provider()) { entry in
- DashboardWidgetView(entry: entry)
- }
- .supportedFamilies([.systemLarge])
- .configurationDisplayName("Nextcloud Dashboard")
- .description(NSLocalizedString("_subtitle_dashboard_", comment: ""))
- }
- }
- struct DashboardWidget_Previews: PreviewProvider {
- static var previews: some View {
- let entry = DashboardDataEntry(date: Date(), dashboardDatas: dashboardDatasTest, isPlaceholder: false, title: getTitle(account: nil))
- DashboardWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
- }
- }
|