-
Notifications
You must be signed in to change notification settings - Fork 0
/
JellyMusicApp.swift
53 lines (45 loc) · 1.75 KB
/
JellyMusicApp.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import Defaults
import Kingfisher
import OSLog
import SwiftUI
@main
struct JellyMusicApp: App {
@Default(.appColorScheme)
private var appColorScheme
init() {
// Memory image never expires.
Kingfisher.ImageCache.default.memoryStorage.config.expiration = .never
// Disk image expires in a week.
Kingfisher.ImageCache.default.diskStorage.config.expiration = .days(7)
// Limit disk cache size to 3 GB.
Kingfisher.ImageCache.default.diskStorage.config.sizeLimit = 3000 * 1024 * 1024
// Set values for the Jellyfin API client
Defaults[.deviceName] = UIDevice.current.model
Defaults[.deviceId] = UIDevice.current.identifierForVendor?.uuidString ?? "no_device_id_available"
}
var body: some Scene {
WindowGroup {
MainScreen()
.preferredColorScheme(appColorScheme.asColorScheme)
.task { await authorizeClient() }
.environmentObject(MusicPlayer.shared)
.environmentObject(ApiClient.shared)
.environmentObject(SongRepository(store: .songs))
.environmentObject(ApiClient.shared)
.environmentObject(LibraryRepository.shared)
}
}
private func authorizeClient() async {
guard isConfigured() else { return }
do {
try await ApiClient.shared.performAuth()
Logger.library.debug("API client successfully authorized")
} catch {
Logger.library.warning("Server authentication failed: \(error.localizedDescription)")
Alerts.info("Failed to log in to server")
}
}
private func isConfigured() -> Bool {
Defaults[.serverUrl].isNotEmpty && Defaults[.username].isNotEmpty
}
}