Skip to content

Commit

Permalink
Refresh Server Info (#1402)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
chickdan and LePips authored Jan 23, 2025
1 parent baf9116 commit b4c07bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Shared/SwiftfinStore/SwiftfinStore+ServerState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
4 changes: 4 additions & 0 deletions Shared/ViewModels/ServerCheckViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Combine
import Factory
import Foundation
import JellyfinAPI

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b4c07bd

Please sign in to comment.