Watch: what changed on Recent cards and the thread screen, search in All threads, a switching complication with Allow and Deny in the Smart Stack, and question options on notifications
This commit is contained in:
1 parent
f8241e42bb
commit
bfcbb69550
29 files changed
+1100
-137
No files matched your search
@@ -1,6 +1,7 @@
|
||||
// The watch face complication: how many threads are waiting on you, from `GET /v1/summary`. It
|
||||
// reads the device token and the demo flag from the shared Keychain group, and the app reloads it
|
||||
// whenever its own feed or a notification changes the counts.
|
||||
// The watch face complication and Smart Stack widget: what waits on you or what is working, from
|
||||
// `GET /v1/summary`. For the rectangular family it also reads the waiting thread, so the Smart Stack
|
||||
// can offer Allow and Deny. It reads the device token and the demo flag from the shared Keychain
|
||||
// group, and the app reloads it whenever its own feed or a notification changes the counts.
|
||||
|
||||
import SwiftUI
|
||||
import WidgetKit
|
||||
@@ -18,7 +19,7 @@ struct WaitingWidget: Widget {
|
||||
WaitingView(entry: entry)
|
||||
}
|
||||
.configurationDisplayName("Waiting on you")
|
||||
.description("Threads waiting for your approval or answer.")
|
||||
.description("Threads waiting for your approval or answer, or what is working now.")
|
||||
.supportedFamilies([.accessoryCircular, .accessoryRectangular, .accessoryInline, .accessoryCorner])
|
||||
}
|
||||
}
|
||||
@@ -36,29 +37,26 @@ struct WaitingProvider: TimelineProvider {
|
||||
completion(.sample)
|
||||
return
|
||||
}
|
||||
Task { completion(await Self.load()) }
|
||||
let family = context.family
|
||||
Task { completion(await Self.load(family)) }
|
||||
}
|
||||
|
||||
func getTimeline(in context: Context, completion: @escaping @Sendable (Timeline<WaitingEntry>) -> Void) {
|
||||
let family = context.family
|
||||
Task {
|
||||
let entry = await Self.load()
|
||||
let entry = await Self.load(family)
|
||||
completion(Timeline(entries: [entry], policy: .after(entry.date.addingTimeInterval(Self.refreshInterval))))
|
||||
}
|
||||
}
|
||||
|
||||
static func load() async -> WaitingEntry {
|
||||
let api: any GatewayAPI
|
||||
if SharedState.demo {
|
||||
api = DemoGateway.shared
|
||||
} else if let credentials = DeviceStore.load() {
|
||||
api = GatewayClient(baseURL: credentials.gatewayURL, token: credentials.token)
|
||||
} else {
|
||||
return WaitingEntry(date: .now, content: .notPaired)
|
||||
}
|
||||
/// The summary, and for the rectangular family the waiting approval's Allow and Deny.
|
||||
static func load(_ family: WidgetFamily) async -> WaitingEntry {
|
||||
guard let api = SharedState.api else { return WaitingEntry(date: .now, content: .notPaired) }
|
||||
do {
|
||||
let summary = try await api.summary()
|
||||
SharedState.lastSummary = summary
|
||||
return WaitingEntry(date: .now, content: .counts(summary, stale: false))
|
||||
let approval = family == .accessoryRectangular ? await WaitingEntry.Approval.load(for: summary, api: api) : nil
|
||||
return WaitingEntry(date: .now, content: .counts(summary, stale: false), approval: approval)
|
||||
} catch GatewayError.unauthorized {
|
||||
return WaitingEntry(date: .now, content: .notPaired)
|
||||
} catch {
|
||||
@@ -69,9 +67,12 @@ struct WaitingProvider: TimelineProvider {
|
||||
}
|
||||
|
||||
private func entry(_ needsYou: Int, _ working: Int, next: Bool = true) -> WaitingEntry {
|
||||
let thread = Summary.Next(hostId: "mac-mini", threadId: "t-ocr", title: "Receipt OCR", hostLabel: "Mac mini")
|
||||
let thread = Summary.Next(hostId: "mac-mini", threadId: "t-ocr", title: "Receipt OCR", hostLabel: "Mac mini", request: "bun test --filter ocr")
|
||||
let current = Summary.Current(
|
||||
hostId: "mac-mini", threadId: "t-scaffold", title: "Watch app scaffold",
|
||||
activity: Activity(kind: .command, text: "bun test", startedAt: .now.addingTimeInterval(-42)))
|
||||
return WaitingEntry(date: .now, content: .counts(
|
||||
Summary(needsYou: needsYou, working: working, next: needsYou > 0 && next ? thread : nil, hostsOffline: 1),
|
||||
Summary(needsYou: needsYou, working: working, next: needsYou > 0 && next ? thread : nil, current: working > 0 ? current : nil, hostsOffline: 1),
|
||||
stale: false))
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user