|
|
|
//
|
|
|
|
// JustOneThingProvider.swift
|
|
|
|
// JustOneThing
|
|
|
|
//
|
|
|
|
// Created by Alan Francis on 24/06/2023.
|
|
|
|
//
|
|
|
|
|
|
|
|
import WidgetKit
|
|
|
|
import SwiftUI
|
|
|
|
import Intents
|
|
|
|
|
|
|
|
struct ThingProvider: IntentTimelineProvider {
|
|
|
|
func placeholder(in context: Context) -> ThingEntry {
|
|
|
|
ThingEntry(date: Date(), configuration: ConfigurationIntent(), thing: .placeholder)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (ThingEntry) -> ()) {
|
|
|
|
let entry = ThingEntry(date: Date(), configuration: configuration, thing: .placeholder)
|
|
|
|
context.
|
|
|
|
completion(entry)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<ThingEntry>) -> ()) {
|
|
|
|
var entries: [ThingEntry] = []
|
|
|
|
|
|
|
|
// 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 = ThingEntry(date: entryDate, configuration: configuration, thing: .placeholder)
|
|
|
|
entries.append(entry)
|
|
|
|
}
|
|
|
|
|
|
|
|
let timeline = Timeline(entries: entries, policy: .atEnd)
|
|
|
|
completion(timeline)
|
|
|
|
}
|
|
|
|
|
|
|
|
func recommendations() -> [IntentRecommendation<ConfigurationIntent>] {
|
|
|
|
return [
|
|
|
|
IntentRecommendation(intent: ConfigurationIntent(), description: "My Intent Widget")
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ThingEntry: TimelineEntry {
|
|
|
|
let date: Date
|
|
|
|
let configuration: ConfigurationIntent
|
|
|
|
let thing: Thing
|
|
|
|
}
|