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>
This commit is contained in:
48
Jarvis/Store/ServerSettings.swift
Normal file
48
Jarvis/Store/ServerSettings.swift
Normal file
@@ -0,0 +1,48 @@
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user