version 1.0.0 #67

Merged
Seil0 merged 137 commits from develop into master 2022-10-12 15:36:39 +02:00
2 changed files with 6 additions and 5 deletions
Showing only changes of commit bc5509cf93 - Show all commits

View File

@ -38,6 +38,9 @@ android {
} }
kotlinOptions { kotlinOptions {
jvmTarget = '1.8' jvmTarget = '1.8'
kotlin.sourceSets.all {
languageSettings.optIn("kotlin.RequiresOptIn")
}
} }
namespace 'org.mosad.teapod' namespace 'org.mosad.teapod'
} }

View File

@ -33,8 +33,6 @@ import io.ktor.client.request.forms.*
import io.ktor.client.statement.* import io.ktor.client.statement.*
import io.ktor.http.* import io.ktor.http.*
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.serialization.SerializationException import kotlinx.serialization.SerializationException
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonObject
@ -59,7 +57,8 @@ object Crunchyroll {
private lateinit var token: Token private lateinit var token: Token
private var tokenValidUntil: Long = 0 private var tokenValidUntil: Long = 0
private val tokeRefreshMutex = Mutex() @OptIn(DelicateCoroutinesApi::class)
private val tokenRefreshContext = newSingleThreadContext("TokenRefreshContext")
private var accountID = "" private var accountID = ""
@ -141,8 +140,7 @@ object Crunchyroll {
params: List<Pair<String, Any?>> = listOf(), params: List<Pair<String, Any?>> = listOf(),
bodyObject: Any = Any() bodyObject: Any = Any()
): T = coroutineScope { ): T = coroutineScope {
// TODO find a better way to make token refresh thread safe, currently it's blocking withContext(tokenRefreshContext) {
tokeRefreshMutex.withLock {
if (System.currentTimeMillis() > tokenValidUntil) refreshToken() if (System.currentTimeMillis() > tokenValidUntil) refreshToken()
} }