Skip to content

Commit

Permalink
🐛 修复了部分手机WebView显示问题和优化协程处理流程
Browse files Browse the repository at this point in the history
  • Loading branch information
18445 committed Mar 9, 2023
1 parent 808c1ad commit 11a0df9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
6 changes: 6 additions & 0 deletions sso/src/main/java/com/redrock/sso/SSOUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ object SSOUtils {
return super.shouldOverrideUrlLoading(view, request)
}
}
// 支持JS
true.also { settings.javaScriptEnabled = it }

// 开启Dom存储功能
settings.domStorageEnabled = true

// 自适应屏幕
settings.useWideViewPort = true
settings.loadWithOverviewMode = true
Expand Down
34 changes: 21 additions & 13 deletions sso/src/main/java/com/redrock/sso/Server.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext
import java.net.ServerSocket
import java.net.Socket
import java.net.SocketException

/**
* .
Expand All @@ -16,24 +18,30 @@ internal object Server {
return withContext(Dispatchers.IO) {
suspendCancellableCoroutine { continuation ->
val serverSocket = ServerSocket(53456)
val socket = serverSocket.accept()
val request = Http.parse2request(socket.getInputStream())
socket.close()
serverSocket.close()
val uriParam = request.uri
.substring(2, request.uri.length) // 去掉前面的 /?
.split("&")
.associate {
val index = it.indexOf("=") // 等号的索引
it.substring(0, index) to it.substring(index + 1, it.length)
}
val data = SSOUtils.Data(uriParam.getValue("session_state"), uriParam.getValue("code"))
continuation.resumeWith(Result.success(data))
continuation.invokeOnCancellation {
serverSocket.close()
}
try {
val socket = serverSocket.accept()
socket.close()
serverSocket.close()
continuation.resumeWith(Result.success(getData(socket)))
} catch (_: SocketException) {
// socket 被 serverSocket cancel 时抛出的异常
}
}
}
}

private fun getData(socket: Socket): SSOUtils.Data {
val request = Http.parse2request(socket.getInputStream())
val uriParam = request.uri
.substring(2, request.uri.length) // 去掉前面的 [表情]
.split("&")
.associate {
val index = it.indexOf("=") // 等号的索引
it.substring(0, index) to it.substring(index + 1, it.length)
}
return SSOUtils.Data(uriParam.getValue("session_state"), uriParam.getValue("code"))
}
}

0 comments on commit 11a0df9

Please sign in to comment.