diff --git a/GooseSwift/CodexEmbeddedAuth.swift b/GooseSwift/CodexEmbeddedAuth.swift index a7ee42d1d..e8e3626d1 100644 --- a/GooseSwift/CodexEmbeddedAuth.swift +++ b/GooseSwift/CodexEmbeddedAuth.swift @@ -236,7 +236,7 @@ actor CodexSelfContainedAuthClient { try await Task.sleep(for: .seconds(max(deviceCode.interval, 1))) } } - throw CodexSelfContainedAuthError.invalidResponse("Device code login timed out after 15 minutes.") + throw CodexSelfContainedAuthError.invalidResponse("Device code login timed out after \(maxDeviceCodeWaitSeconds / 60) minutes.") } private func exchangeCodeForTokens(_ code: CodexDeviceTokenPollResponse) async throws -> CodexTokenExchangeResponse { diff --git a/GooseSwift/GooseAppModel.swift b/GooseSwift/GooseAppModel.swift index a1f9d71d2..cae915d3d 100644 --- a/GooseSwift/GooseAppModel.swift +++ b/GooseSwift/GooseAppModel.swift @@ -192,66 +192,26 @@ final class GooseAppModel: ObservableObject { return processInfo.arguments.contains("--goose-start-respiratory-packet-watch") || processInfo.environment["GOOSE_START_RESPIRATORY_PACKET_WATCH"] == "1" }() - let autoStartHealthPacketCaptureDuration: TimeInterval = { - let processInfo = ProcessInfo.processInfo - if let value = processInfo.environment["GOOSE_HEALTH_PACKET_CAPTURE_DURATION_SECONDS"], - let seconds = Double(value), - seconds > 0 { - return seconds - } - let prefix = "--goose-health-packet-capture-duration=" - if let argument = processInfo.arguments.first(where: { $0.hasPrefix(prefix) }), - let seconds = Double(argument.dropFirst(prefix.count)), - seconds > 0 { - return seconds - } - return 30 * 60 - }() - let autoStartTemperaturePacketCaptureDuration: TimeInterval = { - let processInfo = ProcessInfo.processInfo - if let value = processInfo.environment["GOOSE_TEMPERATURE_PACKET_CAPTURE_DURATION_SECONDS"], - let seconds = Double(value), - seconds > 0 { - return seconds - } - let prefix = "--goose-temperature-packet-capture-duration=" - if let argument = processInfo.arguments.first(where: { $0.hasPrefix(prefix) }), - let seconds = Double(argument.dropFirst(prefix.count)), - seconds > 0 { - return seconds - } - return 10 * 60 - }() - let autoStartPhysiologyPacketCaptureDuration: TimeInterval = { - let processInfo = ProcessInfo.processInfo - if let value = processInfo.environment["GOOSE_PHYSIOLOGY_PACKET_CAPTURE_DURATION_SECONDS"], - let seconds = Double(value), - seconds > 0 { - return seconds - } - let prefix = "--goose-physiology-packet-capture-duration=" - if let argument = processInfo.arguments.first(where: { $0.hasPrefix(prefix) }), - let seconds = Double(argument.dropFirst(prefix.count)), - seconds > 0 { - return seconds - } - return 30 * 60 - }() - let autoStartRespiratoryPacketWatchDuration: TimeInterval = { - let processInfo = ProcessInfo.processInfo - if let value = processInfo.environment["GOOSE_RESPIRATORY_PACKET_WATCH_DURATION_SECONDS"], - let seconds = Double(value), - seconds > 0 { - return seconds - } - let prefix = "--goose-respiratory-packet-watch-duration=" - if let argument = processInfo.arguments.first(where: { $0.hasPrefix(prefix) }), - let seconds = Double(argument.dropFirst(prefix.count)), - seconds > 0 { - return seconds - } - return 10 * 60 - }() + let autoStartHealthPacketCaptureDuration: TimeInterval = GooseAppModel.durationFromEnvironment( + envVar: "GOOSE_HEALTH_PACKET_CAPTURE_DURATION_SECONDS", + cliPrefix: "--goose-health-packet-capture-duration=", + fallback: 30 * 60 + ) + let autoStartTemperaturePacketCaptureDuration: TimeInterval = GooseAppModel.durationFromEnvironment( + envVar: "GOOSE_TEMPERATURE_PACKET_CAPTURE_DURATION_SECONDS", + cliPrefix: "--goose-temperature-packet-capture-duration=", + fallback: 10 * 60 + ) + let autoStartPhysiologyPacketCaptureDuration: TimeInterval = GooseAppModel.durationFromEnvironment( + envVar: "GOOSE_PHYSIOLOGY_PACKET_CAPTURE_DURATION_SECONDS", + cliPrefix: "--goose-physiology-packet-capture-duration=", + fallback: 30 * 60 + ) + let autoStartRespiratoryPacketWatchDuration: TimeInterval = GooseAppModel.durationFromEnvironment( + envVar: "GOOSE_RESPIRATORY_PACKET_WATCH_DURATION_SECONDS", + cliPrefix: "--goose-respiratory-packet-watch-duration=", + fallback: 10 * 60 + ) let autoSyncHistoryDuringPhysiologyCapture: Bool = { let processInfo = ProcessInfo.processInfo return processInfo.arguments.contains("--goose-sync-history-during-physiology-capture") @@ -440,4 +400,23 @@ final class GooseAppModel: ObservableObject { } } + private nonisolated static func durationFromEnvironment( + envVar: String, + cliPrefix: String, + fallback: TimeInterval + ) -> TimeInterval { + let processInfo = ProcessInfo.processInfo + if let value = processInfo.environment[envVar], + let seconds = Double(value), + seconds > 0 { + return seconds + } + if let argument = processInfo.arguments.first(where: { $0.hasPrefix(cliPrefix) }), + let seconds = Double(argument.dropFirst(cliPrefix.count)), + seconds > 0 { + return seconds + } + return fallback + } + }