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:
Daniel Chick 2025-01-22 18:07:00 -06:00 committed by GitHub
parent baf91164a9
commit b4c07bddfa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View File

@ -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
}
}

View File

@ -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 {