summaryrefslogtreecommitdiff
path: root/Shared/DomainDigShareInbox.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Shared/DomainDigShareInbox.swift')
-rw-r--r--Shared/DomainDigShareInbox.swift28
1 files changed, 28 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
+ }
+}