SPB Git

Repository Public

AppConfiguration.swift 2.5 KB 68 lines swift

1// SP Drive iOS2// File: App/AppConfiguration.swift3// Description: Identifiers and tunables of the app, and the debug-only switches used by the automated tests.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import Foundation8import SwiftUI9import UIKit1011enum AppConfiguration {12    static let backgroundSessionID = "ai.spboucher.spdrive.ios.transfers"13    static let refreshTaskID = "ai.spboucher.spdrive.ios.refresh"14    static let syncTaskID = "ai.spboucher.spdrive.ios.sync"15    /// While the app is in front, remote changes are looked for at this interval (the change feed makes an empty check cheap).16    static var foregroundSyncInterval: Duration {17        #if DEBUG18        // UI tests that stage a conflict keep the app from looking at the change feed on its own19        if let s = ProcessInfo.processInfo.environment["SPDRIVE_POLL_SECONDS"].flatMap(Int.init) { return .seconds(s) }20        #endif21        return .seconds(30)22    }2324    @MainActor static var deviceName: String {25        let d = UIDevice.current26        return d.name.isEmpty ? d.model : d.name27    }2829    /// Debug builds only: a session token and a start-from-scratch flag handed in by the UI tests. Compiled out of Release.30    static var injectedToken: String? {31        #if DEBUG32        return ProcessInfo.processInfo.environment["SPDRIVE_TEST_TOKEN"].flatMap { $0.isEmpty ? nil : $0 }33        #else34        return nil35        #endif36    }37    static var resetOnLaunch: Bool {38        #if DEBUG39        return ProcessInfo.processInfo.environment["SPDRIVE_RESET"] == "1"40        #else41        return false42        #endif43    }44    /// Debug builds only: the screenshot tests render the app in a given appearance (the simulator's own setting is not theirs to change).45    static var forcedScheme: ColorScheme? {46        #if DEBUG47        switch ProcessInfo.processInfo.environment["SPDRIVE_FORCE_SCHEME"] { case "dark": return .dark; case "light": return .light; default: return nil }48        #else49        return nil50        #endif51    }52    /// Debug builds only: a UI test that stages a conflict keeps the app deaf to the server's events.53    static var eventsDisabled: Bool {54        #if DEBUG55        return ProcessInfo.processInfo.environment["SPDRIVE_NO_EVENTS"] == "1"56        #else57        return false58        #endif59    }60    static var isUITest: Bool {61        #if DEBUG62        return ProcessInfo.processInfo.environment["SPDRIVE_UITEST"] == "1"63        #else64        return false65        #endif66    }67}68
Files main
Menu

Theme