mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-11 07:29:14 +01:00
probe whenever the active source changes
Track the active source id and probe when it changes, instead of a remembered probed id. The behaviour is the same for switching sources, but the intent is now explicit: switch source, probe it.
This commit is contained in:
@@ -31,7 +31,7 @@ class SourceRepository(
|
|||||||
|
|
||||||
@Volatile
|
@Volatile
|
||||||
private var active: SubsonicMusicSource? = null
|
private var active: SubsonicMusicSource? = null
|
||||||
private var probedTokenAuthId: Long? = null
|
private var activeSourceId: Long? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
@@ -42,12 +42,11 @@ class SourceRepository(
|
|||||||
) { config, maxBitrate, streamFormat -> Triple(config, maxBitrate, streamFormat) }
|
) { config, maxBitrate, streamFormat -> Triple(config, maxBitrate, streamFormat) }
|
||||||
.collect { (config, maxBitrate, streamFormat) ->
|
.collect { (config, maxBitrate, streamFormat) ->
|
||||||
active = config?.toMusicSource(maxBitrate, streamFormat)
|
active = config?.toMusicSource(maxBitrate, streamFormat)
|
||||||
config
|
val sourceChanged = config?.id != activeSourceId
|
||||||
?.takeIf { it.useTokenAuth && it.id != probedTokenAuthId }
|
activeSourceId = config?.id
|
||||||
?.let { source ->
|
if (sourceChanged && config != null && config.useTokenAuth) {
|
||||||
probedTokenAuthId = source.id
|
scope.launch { runCatching { config.toClient().check("ping") } }
|
||||||
scope.launch { runCatching { source.toClient().check("ping") } }
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user