Commit 8286a5df authored by liusheng's avatar liusheng

修复加速AuthToken重新登录不刷新的问题

parent 3f146744
......@@ -137,12 +137,6 @@ class AccelertorFragment : XPageFragment() {
binding.progressArea.visibility = View.GONE
binding.btnQuick.isEnabled = true
binding.progressViewCircleSmall.progress = 0F
binding.progressViewCircleSmall.postDelayed({
Log.e("onCircleProgressFinished","====="+state.toString())
if (state != BaseService.State.Connected) {
ToastUtils.show("加速失败")
}
}, 3000)
AcceleratorUtils.startAccelerator(this@AccelertorFragment)
}
})
......
......@@ -98,7 +98,7 @@ object AcceleratorUtils {
val delay =
NetUtils.tcpPing(split[0], split[1].toInt(), DataStore.portProxy)
.toInt()
net.accNetDelay = (delay * 0.5).toInt()
net.accNetDelay = delay
LoginUtils.getUserHasTimer {
if (!it) { //没有加速时长关闭服务
stopAccelerator()
......@@ -171,7 +171,6 @@ object AcceleratorUtils {
proxyGames.add(it)
}
}
proxyGames.addAll(profile.individual.split("\n"))
profile.individual = proxyGames.joinToString("\n")
profile.route = Acl.BYPASS_LAN
profile.password = "barfoo!"
......
......@@ -101,7 +101,7 @@ object LoginUtils {
timer?.schedule(timerTask, 0, 1000);
}
fun stopTimer(){
fun stopTimer() {
_phone = ""
timer?.cancel()
}
......@@ -136,7 +136,7 @@ object LoginUtils {
context,
PhoneLoginActivity::class.java
)
intent.addFlags(FLAG_ACTIVITY_NEW_TASK )
intent.addFlags(FLAG_ACTIVITY_NEW_TASK)
context.startActivity(
intent
)
......@@ -148,21 +148,17 @@ object LoginUtils {
fun clearToken() {
Core.stopService()
MMKV.defaultMMKV().remove(KEY_TOKEN)
token = null
}
var token: String?
get() = MMKV.defaultMMKV().decodeString(KEY_TOKEN, null)
get() = AuthManager.authToken
set(token) {
MMKV.defaultMMKV().putString(KEY_TOKEN, token)
if (token != null) {
AuthManager.loginAuthToken=token
Log.e("LoginUtils","===loginAuthToken:"+ AuthManager.loginAuthToken)
}
AuthManager.authToken = token
}
fun hasToken(): Boolean {
return MMKV.defaultMMKV().containsKey(KEY_TOKEN)
return !AuthManager.authToken.isNullOrBlank()
}
fun logout() {
......
......@@ -64,9 +64,9 @@ object AuthManager {
}
var authToken: String?
get() = MMKV.defaultMMKV().decodeString(KEY_TOKEN, null)
get() = MMKV.mmkvWithID("InterProcessKV", MMKV.MULTI_PROCESS_MODE).decodeString(KEY_TOKEN, null)
set(token) {
MMKV.defaultMMKV().putString(KEY_TOKEN, token)
MMKV.mmkvWithID("InterProcessKV", MMKV.MULTI_PROCESS_MODE).putString(KEY_TOKEN, token)
}
// 加速时长
......@@ -87,7 +87,7 @@ object AuthManager {
suspend fun initAuthProfile(profile: Profile) {
withContext(Dispatchers.IO) {
val gameId: Int = gameId?.toInt() ?: throw AuthException("游戏不存在")
val lineConfigResult = postSync<LineConfig>("/api/acc/line", LineConfigReq(gameId, area))
val lineConfigResult = postSync<LineConfig>("/api/acc/line",authToken, LineConfigReq(gameId, area))
if (lineConfigResult.isSuccessful()) {
val lineConfig = lineConfigResult.unwrapData()
profile.host = lineConfig.host
......@@ -119,7 +119,7 @@ object AuthManager {
if (data.state == BaseService.State.Connected) {
data.proxy?.let { proxyInstance ->
val refreshTokenResult = postSync<RefreshTokenRes>(
"/api/acc/line/refresh",
"/api/acc/line/refresh",authToken,
RefreshTokenReq(proxyInstance.profile.token ?: "")
)
Timber.d("refreshTokenResult: $refreshTokenResult")
......@@ -151,13 +151,14 @@ object AuthManager {
inline fun <reified T> postSync(
url: String,
token: String?,
params: Any
): ApiResult<T> {
val body: RequestBody = gson.toJson(params).toString().toRequestBody(jsonType)
val request = Request.Builder()
.url(HttpConfig.baseUrl + url)
.post(body)
authToken?.let {
token?.let {
request.addHeader("Authorization", it)
}
Log.e("postSync","===authToken:"+authToken)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment