krz/domain-dig

an ios app for DNS & SSL analysis

clone: git clone https://gitbay.org/krz/domain-dig.git

v5.0.0: Shared/DomainDigShareInbox.swift · raw

 1import Foundation
 2
 3/// App Group handoff from the share extension to the app.
 4///
 5/// Share extensions cannot reliably open their host app, so the extension
 6/// drops the shared domain here and the app consumes it the next time it
 7/// becomes active, routing it into an inspection.
 8enum DomainDigShareInbox {
 9    private static let key = "pendingInspectDomain"
10
11    private static var defaults: UserDefaults? {
12        UserDefaults(suiteName: DomainDigWidgetStore.appGroupID)
13    }
14
15    static func write(domain: String) {
16        defaults?.set(domain, forKey: key)
17    }
18
19    /// Returns and clears the pending domain, if any.
20    static func consume() -> String? {
21        guard let defaults,
22              let domain = defaults.string(forKey: key),
23              !domain.isEmpty
24        else { return nil }
25        defaults.removeObject(forKey: key)
26        return domain
27    }
28}