Sesame-iOS/Sesame-Widget/Sesame_Widget.swift

59 lines
1.6 KiB
Swift
Raw Normal View History

import WidgetKit
import SwiftUI
import SFSafeSymbols
struct Provider: TimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry(date: Date())
}
func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
let entry = SimpleEntry(date: Date())
completion(entry)
}
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
let entries = [Entry(date: .now), Entry(date: .distantFuture)]
completion(Timeline(entries: entries, policy: .atEnd))
}
}
struct SimpleEntry: TimelineEntry {
let date: Date
}
struct Sesame_WidgetEntryView : View {
var entry: Provider.Entry
var body: some View {
Image(systemSymbol: .lock)
.resizable()
.aspectRatio(contentMode: .fit)
.padding()
.fontWeight(.thin)
.widgetURL(URL(string: "sesame:///open")!)
}
}
@main
struct Sesame_Widget: Widget {
let kind: String = "SesameOpen"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
Sesame_WidgetEntryView(entry: entry)
}
.configurationDisplayName("Open")
.description("This widget can be used to unlock the door with a single tap.")
}
}
struct Sesame_Widget_Previews: PreviewProvider {
static var previews: some View {
Sesame_WidgetEntryView(entry: SimpleEntry(date: Date()))
.previewContext(WidgetPreviewContext(family: .accessoryRectangular))
}
}