Improved connect logging (#205)

* Add additional log statements to connect code
* Improve version check
* Fix wrong variable used
This commit is contained in:
Niels van Velzen authored and GitHub committed 2020-10-23 13:59:49 +02:00
1 parent 8143486ab8
commit 867d657f79
3 files changed
+20 -3

No files matched your search

@@ -35,6 +35,7 @@ import org.jellyfin.mobile.R
import org.jellyfin.mobile.databinding.FragmentConnectBinding
import org.jellyfin.mobile.utils.*
import org.koin.android.ext.android.inject
import timber.log.Timber
class ConnectFragment : Fragment() {
private val jellyfin: Jellyfin by inject()
@@ -155,11 +156,14 @@ class ConnectFragment : Fragment() {
}
private suspend fun checkServerUrlAndConnection(enteredUrl: String): HttpUrl? {
Timber.i("checkServerUrlAndConnection $enteredUrl")
val normalizedUrl = enteredUrl.run {
if (lastOrNull() == '/') this
else "$this/"
}
val urls = jellyfin.discovery.addressCandidates(normalizedUrl)
Timber.i("Address candidates are $urls")
var httpUrl: HttpUrl? = null
var serverInfo: PublicSystemInfo? = null
@@ -180,6 +184,8 @@ class ConnectFragment : Fragment() {
}
if (httpUrl == null || serverInfo == null) {
Timber.w("Failed to find server info, url was $httpUrl")
showConnectionError()
return null
}
@@ -190,10 +196,20 @@ class ConnectFragment : Fragment() {
val isValidInstance = when {
version.size != 3 -> false
version[0] == PRODUCT_NAME_SUPPORTED_SINCE.first && version[1] < PRODUCT_NAME_SUPPORTED_SINCE.second -> true // Valid old version
// Major version is invalid
version[0] != PRODUCT_NAME_SUPPORTED_SINCE.first -> false
// Minor version is too old
version[1] < PRODUCT_NAME_SUPPORTED_SINCE.second -> false
else -> true // FIXME: check ProductName once API client supports it
}
return if (isValidInstance) httpUrl else null
Timber.i("Server at $httpUrl with version ${serverInfo.version} valid: $isValidInstance")
if (!isValidInstance) {
showConnectionError(R.string.connection_error_invalid_version)
return null
}
return httpUrl
}
}
@@ -18,7 +18,7 @@ import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
val PRODUCT_NAME_SUPPORTED_SINCE: Pair<Int, Int> = 10 to 3
val PRODUCT_NAME_SUPPORTED_SINCE: Pair<Int, Int> = 10 to 6
// Can be removed/replaced once the api client supports coroutines natively
suspend fun ApiClient.getPublicSystemInfo(): PublicSystemInfo? = suspendCoroutine { continuation ->
+1
View File
@@ -3,6 +3,7 @@
<string name="host_input_hint">Host</string>
<string name="connection_error_invalid_format">Host has an invalid format</string>
<string name="connection_error_cannot_connect">Connection cannot be established.\nPlease check the hostname and your network connection.</string>
<string name="connection_error_invalid_version">The server uses an unsupported version. Upgrade to the latest version available at jellyfin.org.</string>
<string name="connect_button_text">Connect</string>
<string name="choose_server_button_text">Choose server</string>
<string name="available_servers_title">Available servers</string>