SPB Git

Repository Public

AppConfiguration.swift 2.4 KB 48 lines swift

1// SP Notes iOS2// File: App/AppConfiguration.swift3// Description: Where the app talks to and where it stores its data. Production values come from Info.plist; Debug builds accept4//              overrides from the environment so tests can use the development server and throw-away storage, never production.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import Foundation9import SPNotesCore1011struct AppConfiguration: Sendable {12    var api: APIConfiguration13    /// Directory of the database and attachment files (the App Group container, shared with the widgets and the share extension).14    var dataDirectory: URL15    var inMemoryStore = false16    /// Debug only: a development-server session token, to test without a passkey ceremony.17    var injectedToken: String?18    /// Debug only: start with sample notes (UI tests).19    var seedSampleNotes = false2021    static var appVersion: String { Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "1.0.0" }2223    static var current: AppConfiguration {24        var api = APIConfiguration.production(appVersion: appVersion)25        if let text = Bundle.main.object(forInfoDictionaryKey: "SPNotesBaseURL") as? String, let url = URL(string: text), url != api.baseURL {26            api.baseURL = url27            api.origin = APIConfiguration.origin(of: url)28        }29        var configuration = AppConfiguration(api: api, dataDirectory: AppGroup.containerURL.appendingPathComponent("SPNotes", isDirectory: true))30        #if DEBUG31        let environment = ProcessInfo.processInfo.environment32        if let text = environment["SPNOTES_BASE_URL"], let url = URL(string: text) {33            configuration.api.baseURL = url34            configuration.api.origin = APIConfiguration.origin(of: url)35        }36        if let token = environment["SPNOTES_TOKEN"], !token.isEmpty { configuration.injectedToken = token }37        if let directory = environment["SPNOTES_DATA_DIR"] {38            configuration.dataDirectory = directory == "temp"39                ? FileManager.default.temporaryDirectory.appendingPathComponent("spnotes-\(UUID().uuidString)", isDirectory: true)40                : URL(fileURLWithPath: directory, isDirectory: true)41        }42        if environment["SPNOTES_STORE"] == "memory" { configuration.inMemoryStore = true }43        if environment["SPNOTES_SEED"] == "1" { configuration.seedSampleNotes = true }44        #endif45        return configuration46    }47}48
Files main
Menu

Theme