Refresh Server Info (#1402)
* Add function to update basic server info * Add server info update in server check view model * Update ServerCheckViewModel.swift --------- Co-authored-by: chickdan <=> Co-authored-by: Ethan Pippin <ethanpippin2343@gmail.com>
This commit is contained in:
parent
baf91164a9
commit
b4c07bddfa
|
@ -78,4 +78,21 @@ extension ServerState {
|
|||
let request = Paths.getSplashscreen()
|
||||
return ImageSource(url: client.fullURL(with: request))
|
||||
}
|
||||
|
||||
func updateServerInfo() async throws {
|
||||
guard let server = try? SwiftfinStore.dataStack.fetchOne(
|
||||
From<ServerModel>()
|
||||
) else { return }
|
||||
|
||||
let publicInfo = try await getPublicSystemInfo()
|
||||
|
||||
try SwiftfinStore.dataStack.perform { transaction in
|
||||
guard let newServer = transaction.edit(server) else { return }
|
||||
|
||||
newServer.name = publicInfo.serverName ?? newServer.name
|
||||
newServer.id = publicInfo.id ?? newServer.id
|
||||
}
|
||||
|
||||
StoredValues[.Server.publicInfo(id: server.id)] = publicInfo
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
//
|
||||
|
||||
import Combine
|
||||
import Factory
|
||||
import Foundation
|
||||
import JellyfinAPI
|
||||
|
||||
|
@ -36,12 +37,15 @@ class ServerCheckViewModel: ViewModel, Stateful {
|
|||
// TODO: also server stuff
|
||||
connectCancellable = Task {
|
||||
do {
|
||||
try await userSession.server.updateServerInfo()
|
||||
|
||||
let request = Paths.getCurrentUser
|
||||
let response = try await userSession.client.send(request)
|
||||
|
||||
await MainActor.run {
|
||||
userSession.user.data = response.value
|
||||
self.state = .connected
|
||||
Container.shared.currentUserSession.reset()
|
||||
}
|
||||
} catch {
|
||||
await MainActor.run {
|
||||
|
|
Loading…
Reference in New Issue