Initial Commit
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// 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())
|
||||
}
|
||||
Reference in New Issue
Block a user