diff --git a/extensions/widget/app/TaskTimeTerminateWidgetWrapper/TaskTimeTerminateWidget/TaskTimeTerminateWidget.swift b/extensions/widget/app/TaskTimeTerminateWidgetWrapper/TaskTimeTerminateWidget/TaskTimeTerminateWidget.swift index 32a568b..85bbaf9 100644 --- a/extensions/widget/app/TaskTimeTerminateWidgetWrapper/TaskTimeTerminateWidget/TaskTimeTerminateWidget.swift +++ b/extensions/widget/app/TaskTimeTerminateWidgetWrapper/TaskTimeTerminateWidget/TaskTimeTerminateWidget.swift @@ -9,51 +9,57 @@ import WidgetKit import SwiftUI import Intents -struct Provider: IntentTimelineProvider { - func placeholder(in context: Context) -> SimpleEntry { - SimpleEntry(date: Date(), configuration: ConfigurationIntent()) +struct Provider: TimelineProvider { + // single preview + func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> Void) { + completion(SimpleEntry(date: Date(), configuration: ConfigurationIntent())) } - - func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) { - let entry = SimpleEntry(date: Date(), configuration: configuration) - completion(entry) + + // multi preview + func getTimeline(in context: Context, completion: @escaping (Timeline) -> Void) { + completion(Timeline(entries: [SimpleEntry(date: Date(), configuration: ConfigurationIntent())], policy: .atEnd)) } - - func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline) -> ()) { - var entries: [SimpleEntry] = [] - - // Generate a timeline consisting of five entries an hour apart, starting from the current date. - let currentDate = Date() - for hourOffset in 0 ..< 5 { - let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)! - let entry = SimpleEntry(date: entryDate, configuration: configuration) - entries.append(entry) - } - - let timeline = Timeline(entries: entries, policy: .atEnd) - completion(timeline) + + // empty element + func placeholder(in context: Context) -> SimpleEntry { + SimpleEntry(date: Date(), configuration: ConfigurationIntent()) } } +// the content struct SimpleEntry: TimelineEntry { let date: Date let configuration: ConfigurationIntent } +// the real view (showing the content from file!!) struct TaskTimeTerminateWidgetEntryView : View { var entry: Provider.Entry var body: some View { - Text(entry.date, style: .time) + theMainView() + } + + func theMainView() -> AnyView { + let filepath = NSHomeDirectory() + "/TaskTimeTerminateWidget.txt" + var content = "" + do { + let path = URL(fileURLWithPath: filepath); + content = try String(contentsOf: path, encoding: .utf8) + } catch { + content = "Error unable to load stats!" + } + return AnyView(Text(content).font(.system(.body, design: .monospaced))) } } @main struct TaskTimeTerminateWidget: Widget { - let kind: String = "TaskTimeTerminateWidget" - var body: some WidgetConfiguration { - IntentConfiguration(kind: kind, intent: ConfigurationIntent.self, provider: Provider()) { entry in + StaticConfiguration( + kind: "TaskTimeTerminateWidget", + provider: Provider() + ) { entry in TaskTimeTerminateWidgetEntryView(entry: entry) } .configurationDisplayName("TTT Widget")