Files
jarvis/Jarvis/Store/ServerSettings.swift
Robin Kutesa 27d0e22767 Initial commit: Jarvis iOS app
SwiftUI client for a self-hosted RSS news-correlation platform: signal feed,
story detail, article reader, feed manager, and LAN⇄Tailscale connectivity.
Project generated from project.yml via XcodeGen.

Includes CI build matrix (macOS 14/15 × Debug/Release), issue templates,
backlog, and API/backend handoff docs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-18 18:04:59 +03:00

49 lines
1.4 KiB
Swift

// ServerSettings.swift
// Jarvis persists the configured server host
import Foundation
@MainActor
final class ServerSettings: ObservableObject {
static let shared = ServerSettings()
private let key = "jarvis_server_host"
@Published var host: String? {
didSet { UserDefaults.standard.set(host, forKey: key) }
}
var isConfigured: Bool { host != nil }
private init() {
host = UserDefaults.standard.string(forKey: key)
}
func save(host: String) async throws {
try await APIClient.shared.configure(host: host)
_ = try await APIClient.shared.checkHealth()
self.host = host
WebSocketManager.shared.connect(host: host)
}
func reset() {
host = nil
WebSocketManager.shared.disconnect()
}
/// Re-establish REST + WebSocket from a previously saved host on app launch.
func reconnectIfConfigured() async {
guard let host else { return }
try? await APIClient.shared.configure(host: host)
WebSocketManager.shared.connect(host: host)
}
/// Point REST + WebSocket at a host the ConnectivityManager already verified
/// (skips the health check the probe just confirmed it).
func activate(host: String) async {
try? await APIClient.shared.configure(host: host)
self.host = host
WebSocketManager.shared.connect(host: host)
}
}