mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 18:19:43 +00:00
feat: add live draw feature and clean up docs
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
520d0a8444
commit
4c18afaeae
63 files changed
+6728
-12854
No files matched your search
@@ -0,0 +1,83 @@
|
||||
import WidgetKit
|
||||
import SwiftUI
|
||||
|
||||
struct LiveDrawEntry: TimelineEntry {
|
||||
let date: Date
|
||||
let image: UIImage?
|
||||
}
|
||||
|
||||
struct LiveDrawProvider: TimelineProvider {
|
||||
let suiteName = "group.com.sauci.app"
|
||||
let dataKey = "LiveDrawImage"
|
||||
|
||||
func placeholder(in context: Context) -> LiveDrawEntry {
|
||||
LiveDrawEntry(date: Date(), image: nil)
|
||||
}
|
||||
|
||||
func getSnapshot(in context: Context, completion: @escaping (LiveDrawEntry) -> Void) {
|
||||
completion(getEntry())
|
||||
}
|
||||
|
||||
func getTimeline(in context: Context, completion: @escaping (Timeline<LiveDrawEntry>) -> Void) {
|
||||
let entry = getEntry()
|
||||
let nextUpdate = Calendar.current.date(byAdding: .minute, value: 30, to: Date())!
|
||||
let timeline = Timeline(entries: [entry], policy: .after(nextUpdate))
|
||||
completion(timeline)
|
||||
}
|
||||
|
||||
private func getEntry() -> LiveDrawEntry {
|
||||
guard let suite = UserDefaults(suiteName: suiteName),
|
||||
let base64 = suite.string(forKey: dataKey),
|
||||
let imageData = Data(base64Encoded: base64),
|
||||
let image = UIImage(data: imageData)
|
||||
else {
|
||||
return LiveDrawEntry(date: Date(), image: nil)
|
||||
}
|
||||
return LiveDrawEntry(date: Date(), image: image)
|
||||
}
|
||||
}
|
||||
|
||||
struct LiveDrawWidgetEntryView: View {
|
||||
var entry: LiveDrawProvider.Entry
|
||||
|
||||
var body: some View {
|
||||
if let image = entry.image {
|
||||
Image(uiImage: image)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 16))
|
||||
} else {
|
||||
ZStack {
|
||||
Color(red: 26/255, green: 26/255, blue: 46/255)
|
||||
VStack(spacing: 8) {
|
||||
Image(systemName: "pencil.tip.crop.circle")
|
||||
.font(.system(size: 32))
|
||||
.foregroundColor(.white.opacity(0.5))
|
||||
Text("Draw together")
|
||||
.font(.caption)
|
||||
.foregroundColor(.white.opacity(0.5))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct LiveDrawWidget: Widget {
|
||||
let kind: String = "LiveDrawWidget"
|
||||
|
||||
var body: some WidgetConfiguration {
|
||||
StaticConfiguration(kind: kind, provider: LiveDrawProvider()) { entry in
|
||||
if #available(iOS 17.0, *) {
|
||||
LiveDrawWidgetEntryView(entry: entry)
|
||||
.widgetURL(URL(string: "app.sauci://live-draw"))
|
||||
.containerBackground(Color(red: 26/255, green: 26/255, blue: 46/255), for: .widget)
|
||||
} else {
|
||||
LiveDrawWidgetEntryView(entry: entry)
|
||||
.widgetURL(URL(string: "app.sauci://live-draw"))
|
||||
}
|
||||
}
|
||||
.configurationDisplayName("Live Draw")
|
||||
.description("See your shared drawing with your partner.")
|
||||
.supportedFamilies([.systemSmall, .systemMedium])
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user