Repository Public
1// SP Drive iOS2// File: Core/AppGroup.swift3// Description: Shared configuration of the three processes (app, File Provider extension, share extension): group container, keychain group, base URL.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import Foundation89/// Static configuration read from the bundle's Info.plist, so the app and its extensions agree by construction.10public enum AppGroup {11 public static let identifier: String = info("SPDriveAppGroup") ?? "group.ai.spboucher.spdrive.ios"12 public static let keychainGroup: String = info("SPDriveKeychainGroup") ?? "3YM54G49SN.ai.spboucher.spdrive.ios.shared"13 public static let productionURL = URL(string: "https://drive.spboucher.ai")!14 public static let relyingParty = "drive.spboucher.ai"1516 /// Base URL of the backend. Debug builds accept an override (disposable test server through an SSH tunnel);17 /// Release builds always talk to production over HTTPS.18 public static var baseURL: URL {19 #if DEBUG20 if let s = ProcessInfo.processInfo.environment["SPDRIVE_BASE_URL"] ?? sharedDefaults.string(forKey: "debug.baseURL"), let u = URL(string: s) { return u }21 #endif22 return productionURL23 }2425 public static var sharedDefaults: UserDefaults { UserDefaults(suiteName: identifier) ?? .standard }2627 /// Root of the group container (falls back to the process's own Application Support when the group is unavailable, e.g. unit tests on the host).28 public static var container: URL {29 if let u = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: identifier) { return u }30 return FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0].appendingPathComponent("SPDriveGroup", isDirectory: true)31 }3233 /// Files handed over by the share extension when it could not upload them itself (offline, extension killed).34 public static var inbox: URL { directory(container.appendingPathComponent("Inbox", isDirectory: true)) }35 /// State private to the File Provider extension (its own metadata mirror; the app never opens it).36 public static var fileProviderState: URL { directory(container.appendingPathComponent("FileProvider", isDirectory: true)) }3738 /// State private to the app: metadata mirror, journal, offline copies. Lives in Application Support (backed up, never purged by the system).39 public static var appSupport: URL {40 directory(FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0].appendingPathComponent("SPDrive", isDirectory: true))41 }4243 @discardableResult44 public static func directory(_ url: URL) -> URL {45 try? FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: [.protectionKey: FileProtectionType.completeUntilFirstUserAuthentication])46 return url47 }4849 private static func info(_ key: String) -> String? {50 guard let s = Bundle.main.object(forInfoDictionaryKey: key) as? String, !s.isEmpty, !s.contains("$(") else { return nil }51 return s52 }53}54