feat: add macOS task board widget app
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>UTrello Widget</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>XPC!</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionPointIdentifier</key>
|
||||
<string>com.apple.widgetkit-extension</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.app-sandbox</key>
|
||||
<true/>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array>
|
||||
<string>group.com.example.utrello</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,67 @@
|
||||
import WidgetKit
|
||||
import SwiftUI
|
||||
|
||||
struct TaskEntry: TimelineEntry {
|
||||
let date: Date
|
||||
let tasks: [TaskItem]
|
||||
}
|
||||
|
||||
struct TaskProvider: TimelineProvider {
|
||||
func placeholder(in context: Context) -> TaskEntry {
|
||||
TaskEntry(date: .now, tasks: [TaskItem(title: "Plan the next task")])
|
||||
}
|
||||
|
||||
func getSnapshot(in context: Context, completion: @escaping (TaskEntry) -> Void) {
|
||||
completion(TaskEntry(date: .now, tasks: openTasks()))
|
||||
}
|
||||
|
||||
func getTimeline(in context: Context, completion: @escaping (Timeline<TaskEntry>) -> Void) {
|
||||
let entry = TaskEntry(date: .now, tasks: openTasks())
|
||||
let refresh = Calendar.current.date(byAdding: .minute, value: 15, to: .now)!
|
||||
completion(Timeline(entries: [entry], policy: .after(refresh)))
|
||||
}
|
||||
|
||||
private func openTasks() -> [TaskItem] {
|
||||
TaskStore.loadTasks().filter { $0.list != .done }
|
||||
}
|
||||
}
|
||||
|
||||
struct UTrelloTasksWidget: Widget {
|
||||
let kind = "UTrelloTasksWidget"
|
||||
|
||||
var body: some WidgetConfiguration {
|
||||
StaticConfiguration(kind: kind, provider: TaskProvider()) { entry in
|
||||
TaskWidgetView(entry: entry)
|
||||
}
|
||||
.configurationDisplayName("UTrello Tasks")
|
||||
.description("Your unfinished tasks at a glance.")
|
||||
.supportedFamilies([.systemSmall, .systemMedium, .systemLarge])
|
||||
}
|
||||
}
|
||||
|
||||
private struct TaskWidgetView: View {
|
||||
let entry: TaskEntry
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("My tasks")
|
||||
.font(.headline)
|
||||
if entry.tasks.isEmpty {
|
||||
Spacer()
|
||||
Text("All caught up")
|
||||
.foregroundStyle(.secondary)
|
||||
Spacer()
|
||||
} else {
|
||||
ForEach(entry.tasks.prefix(4)) { task in
|
||||
Label(task.title, systemImage: task.list == .doing ? "play.circle" : "circle")
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
Text("\(entry.tasks.count) open")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.containerBackground(for: .widget) { Color.clear }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import WidgetKit
|
||||
import SwiftUI
|
||||
|
||||
@main
|
||||
struct UTrelloWidgetBundle: WidgetBundle {
|
||||
var body: some Widget {
|
||||
UTrelloTasksWidget()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user