109 lines
3.2 KiB
Swift
109 lines
3.2 KiB
Swift
import Adwaita
|
|
import Foundation
|
|
import LuminateCore
|
|
import LuminateHome
|
|
import LuminateLibrary
|
|
import LuminatePlayer
|
|
|
|
@main
|
|
struct Luminate: App {
|
|
|
|
let app = AdwaitaApp(id: "dev.bscubed.Luminate")
|
|
@State private var client: JellyfinClient?
|
|
@State private var userId = ""
|
|
@State private var isLaunchLoading = true
|
|
|
|
init() {
|
|
if let store = try? SQLiteStore(dbURL: SQLiteStore.defaultDatabaseURL()) {
|
|
DIContainer.shared.register(\.persistence, value: store)
|
|
}
|
|
}
|
|
|
|
var scene: Scene {
|
|
Window(id: "main") { window in
|
|
if isLaunchLoading {
|
|
VStack {
|
|
Spinner()
|
|
}
|
|
.onAppear {
|
|
loadSavedSession()
|
|
}
|
|
} else if let client {
|
|
ContentView(
|
|
client: client,
|
|
userId: userId
|
|
)
|
|
} else {
|
|
ServerSetupView { client, id in
|
|
DIContainer.shared.register(\.client, value: client)
|
|
DIContainer.shared.register(\.userId, value: id)
|
|
DIContainer.shared.register(\.imageService, value: ImageService())
|
|
|
|
self.client = client
|
|
self.userId = id
|
|
}
|
|
}
|
|
}
|
|
.defaultSize(width: 1280, height: 800)
|
|
.quitShortcut()
|
|
.closeShortcut()
|
|
.keyboardShortcut("f".ctrl()) { _ in
|
|
}
|
|
.keyboardShortcut("r".ctrl()) { _ in
|
|
}
|
|
}
|
|
|
|
private func loadSavedSession() {
|
|
Task {
|
|
do {
|
|
defer { isLaunchLoading = false }
|
|
|
|
let store = try SQLiteStore(dbURL: SQLiteStore.defaultDatabaseURL())
|
|
let auth = try await store.loadAuth()
|
|
guard let serverURL = URL(string: auth.serverURL) else { return }
|
|
|
|
let client = JellyfinClient(
|
|
serverURL: serverURL, token: auth.token, userId: auth.userId)
|
|
let isValid = await client.validateToken()
|
|
guard isValid else { return }
|
|
|
|
DIContainer.shared.register(\.client, value: client)
|
|
DIContainer.shared.register(\.userId, value: auth.userId)
|
|
DIContainer.shared.register(\.imageService, value: ImageService())
|
|
|
|
self.client = client
|
|
self.userId = auth.userId
|
|
} catch {
|
|
isLaunchLoading = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ContentView: View {
|
|
|
|
var client: JellyfinClient
|
|
var userId: String
|
|
@State var stack: NavigationStack<Page> = .init()
|
|
|
|
var view: Body {
|
|
NavigationView($stack, "Luminate") { page in
|
|
switch page {
|
|
case .folder(let title, let items):
|
|
LibraryPage(title: title, items: items, navigation: $stack)
|
|
.topToolbar {
|
|
ToolbarView()
|
|
}
|
|
.navigationTitle(title)
|
|
case .library(let item):
|
|
Text("REPLACE ME")
|
|
}
|
|
} initialView: {
|
|
HomeView(navigation: $stack)
|
|
.topToolbar {
|
|
ToolbarView()
|
|
}
|
|
.navigationTitle("Luminate")
|
|
}
|
|
}
|
|
}
|