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()
|
let request = Paths.getSplashscreen()
|
||||||
return ImageSource(url: client.fullURL(with: request))
|
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 Combine
|
||||||
|
import Factory
|
||||||
import Foundation
|
import Foundation
|
||||||
import JellyfinAPI
|
import JellyfinAPI
|
||||||
|
|
||||||
|
@ -36,12 +37,15 @@ class ServerCheckViewModel: ViewModel, Stateful {
|
||||||
// TODO: also server stuff
|
// TODO: also server stuff
|
||||||
connectCancellable = Task {
|
connectCancellable = Task {
|
||||||
do {
|
do {
|
||||||
|
try await userSession.server.updateServerInfo()
|
||||||
|
|
||||||
let request = Paths.getCurrentUser
|
let request = Paths.getCurrentUser
|
||||||
let response = try await userSession.client.send(request)
|
let response = try await userSession.client.send(request)
|
||||||
|
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
userSession.user.data = response.value
|
userSession.user.data = response.value
|
||||||
self.state = .connected
|
self.state = .connected
|
||||||
|
Container.shared.currentUserSession.reset()
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
|
|
Loading…
Reference in New Issue