Files
MobileMusicAssistant/Mobile Music Assistant/ViewsRootView.swift
T
2026-03-27 09:21:41 +01:00

57 lines
1.4 KiB
Swift

//
// RootView.swift
// Mobile Music Assistant
//
// Created by Sven Hanold on 26.03.26.
//
import SwiftUI
struct RootView: View {
@Environment(MAService.self) private var service
@State private var isInitializing = true
var body: some View {
Group {
if isInitializing {
// Loading screen while checking for saved credentials
VStack(spacing: 20) {
ProgressView()
Text("Connecting...")
.foregroundStyle(.secondary)
}
} else if service.isConnected {
// Main app view when connected
MainTabView()
} else {
// Login view when not connected
LoginView()
}
}
.task {
await initializeConnection()
}
}
// MARK: - Initialization
private func initializeConnection() async {
// Try to connect with saved credentials
if service.authManager.isAuthenticated {
do {
try await service.connectWithSavedCredentials()
} catch {
print("Auto-connect failed: \(error.localizedDescription)")
}
}
isInitializing = false
}
}
#Preview {
RootView()
.environment(MAService())
}