43 lines
1.1 KiB
Kotlin
43 lines
1.1 KiB
Kotlin
|
|
/*
|
||
|
|
* Created by sweetbread on 21.02.2025, 12:01
|
||
|
|
* Copyright (c) 2025. All rights reserved.
|
||
|
|
* Last modified 21.02.2025, 12:01
|
||
|
|
*/
|
||
|
|
|
||
|
|
package ru.risdeveau.pixeldragon
|
||
|
|
|
||
|
|
import android.content.Context
|
||
|
|
import io.ktor.client.HttpClient
|
||
|
|
import io.ktor.client.engine.cio.CIO
|
||
|
|
import io.ktor.client.engine.cio.endpoint
|
||
|
|
import io.ktor.client.plugins.cache.HttpCache
|
||
|
|
import ru.risdeveau.pixeldragon.api.getMe
|
||
|
|
import splitties.init.appCtx
|
||
|
|
|
||
|
|
val client = HttpClient(CIO) {
|
||
|
|
engine {
|
||
|
|
endpoint {
|
||
|
|
maxConnectionsPerRoute = 100
|
||
|
|
pipelineMaxSize = 20
|
||
|
|
keepAliveTime = 30000
|
||
|
|
connectTimeout = 15000
|
||
|
|
connectAttempts = 5
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
install(HttpCache)
|
||
|
|
}
|
||
|
|
|
||
|
|
val accountData = appCtx.getSharedPreferences("settings", Context.MODE_PRIVATE)
|
||
|
|
lateinit var urlBase: String
|
||
|
|
lateinit var token: String
|
||
|
|
|
||
|
|
suspend fun initCheck(): Boolean {
|
||
|
|
if (!accountData.contains("token")) return false
|
||
|
|
if (!accountData.contains("homeserver")) return false
|
||
|
|
|
||
|
|
token = accountData.getString("token", "").toString()
|
||
|
|
urlBase = "https://${accountData.getString("homeserver", "")}/_matrix/client/v3"
|
||
|
|
|
||
|
|
return getMe() != null
|
||
|
|
}
|