|
1 | 1 | package org.jellyfin.androidtv.auth.repository
|
2 | 2 |
|
| 3 | +import kotlinx.coroutines.Dispatchers |
3 | 4 | import kotlinx.coroutines.flow.Flow
|
4 | 5 | import kotlinx.coroutines.flow.MutableStateFlow
|
5 | 6 | import kotlinx.coroutines.flow.StateFlow
|
6 | 7 | import kotlinx.coroutines.flow.asStateFlow
|
7 | 8 | import kotlinx.coroutines.flow.flow
|
| 9 | +import kotlinx.coroutines.flow.flowOn |
8 | 10 | import kotlinx.coroutines.flow.map
|
| 11 | +import kotlinx.coroutines.withContext |
9 | 12 | import org.jellyfin.androidtv.auth.model.AuthenticationStoreServer
|
10 | 13 | import org.jellyfin.androidtv.auth.model.ConnectedState
|
11 | 14 | import org.jellyfin.androidtv.auth.model.ConnectingState
|
@@ -159,7 +162,7 @@ class ServerRepositoryImpl(
|
159 | 162 | .mapValues { (_, entry) -> entry.flatMap { server -> server.issues } }
|
160 | 163 | emit(UnableToConnectState(addressCandidatesWithIssues))
|
161 | 164 | }
|
162 |
| - } |
| 165 | + }.flowOn(Dispatchers.IO) |
163 | 166 |
|
164 | 167 | override suspend fun getServer(id: UUID): Server? {
|
165 | 168 | val server = authenticationStore.getServer(id) ?: return null
|
@@ -193,19 +196,22 @@ class ServerRepositoryImpl(
|
193 | 196 | // Only update every 10 minutes
|
194 | 197 | if (now - server.lastRefreshed < 600000 && server.version != null) return null
|
195 | 198 |
|
196 |
| - val api = jellyfin.createApi(server.address) |
197 |
| - // Get login disclaimer |
198 |
| - val branding = api.getBrandingOptionsOrDefault() |
199 |
| - val systemInfo by api.systemApi.getPublicSystemInfo() |
200 |
| - |
201 |
| - val newServer = server.copy( |
202 |
| - name = systemInfo.serverName ?: server.name, |
203 |
| - version = systemInfo.version ?: server.version, |
204 |
| - loginDisclaimer = branding.loginDisclaimer ?: server.loginDisclaimer, |
205 |
| - splashscreenEnabled = branding.splashscreenEnabled, |
206 |
| - setupCompleted = systemInfo.startupWizardCompleted ?: server.setupCompleted, |
207 |
| - lastRefreshed = now |
208 |
| - ) |
| 199 | + val newServer = withContext(Dispatchers.IO) { |
| 200 | + val api = jellyfin.createApi(server.address) |
| 201 | + |
| 202 | + // Get login disclaimer |
| 203 | + val branding = api.getBrandingOptionsOrDefault() |
| 204 | + val systemInfo by api.systemApi.getPublicSystemInfo() |
| 205 | + |
| 206 | + server.copy( |
| 207 | + name = systemInfo.serverName ?: server.name, |
| 208 | + version = systemInfo.version ?: server.version, |
| 209 | + loginDisclaimer = branding.loginDisclaimer ?: server.loginDisclaimer, |
| 210 | + splashscreenEnabled = branding.splashscreenEnabled, |
| 211 | + setupCompleted = systemInfo.startupWizardCompleted ?: server.setupCompleted, |
| 212 | + lastRefreshed = now |
| 213 | + ) |
| 214 | + } |
209 | 215 | authenticationStore.putServer(id, newServer)
|
210 | 216 |
|
211 | 217 | return newServer
|
|
0 commit comments