summaryrefslogtreecommitdiff
path: root/Shared
diff options
context:
space:
mode:
Diffstat (limited to 'Shared')
-rw-r--r--Shared/DomainDigShareInbox.swift28
-rw-r--r--Shared/SweepActivityAttributes.swift25
2 files changed, 53 insertions, 0 deletions
diff --git a/Shared/DomainDigShareInbox.swift b/Shared/DomainDigShareInbox.swift
new file mode 100644
index 0000000..3a577e7
--- /dev/null
+++ b/Shared/DomainDigShareInbox.swift
@@ -0,0 +1,28 @@
+import Foundation
+
+/// App Group handoff from the share extension to the app.
+///
+/// Share extensions cannot reliably open their host app, so the extension
+/// drops the shared domain here and the app consumes it the next time it
+/// becomes active, routing it into an inspection.
+enum DomainDigShareInbox {
+ private static let key = "pendingInspectDomain"
+
+ private static var defaults: UserDefaults? {
+ UserDefaults(suiteName: DomainDigWidgetStore.appGroupID)
+ }
+
+ static func write(domain: String) {
+ defaults?.set(domain, forKey: key)
+ }
+
+ /// Returns and clears the pending domain, if any.
+ static func consume() -> String? {
+ guard let defaults,
+ let domain = defaults.string(forKey: key),
+ !domain.isEmpty
+ else { return nil }
+ defaults.removeObject(forKey: key)
+ return domain
+ }
+}
diff --git a/Shared/SweepActivityAttributes.swift b/Shared/SweepActivityAttributes.swift
new file mode 100644
index 0000000..ee03c2d
--- /dev/null
+++ b/Shared/SweepActivityAttributes.swift
@@ -0,0 +1,25 @@
+import ActivityKit
+import Foundation
+
+/// Live Activity contract for an in-flight watchlist sweep or batch lookup.
+///
+/// Lives in `Shared/` because the app starts/updates the activity and the
+/// widget extension renders it.
+struct SweepActivityAttributes: ActivityAttributes {
+ struct ContentState: Codable, Hashable {
+ var completed: Int
+ var total: Int
+ var currentDomain: String?
+ var changed: Int
+ var warnings: Int
+
+ var fractionComplete: Double {
+ guard total > 0 else { return 0 }
+ return Double(completed) / Double(total)
+ }
+ }
+
+ /// User-facing title for the run, e.g. "Watchlist Sweep" or "Batch Lookup".
+ var title: String
+ var startedAt: Date
+}