mirror of
https://github.com/MaintainTeam/LastPipeBender.git
synced 2025-02-28 21:38:20 +03:00
Unify running on main thread
This commit is contained in:
parent
3bdae81c0a
commit
0066b322e1
1 changed files with 19 additions and 5 deletions
|
@ -170,8 +170,8 @@ class PoTokenWebView private constructor(
|
||||||
|
|
||||||
override fun generatePoToken(identifier: String): Single<String> =
|
override fun generatePoToken(identifier: String): Single<String> =
|
||||||
Single.create { emitter ->
|
Single.create { emitter ->
|
||||||
|
runOnMainThread(emitter) {
|
||||||
addPoTokenEmitter(identifier, emitter)
|
addPoTokenEmitter(identifier, emitter)
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
webView.evaluateJavascript(
|
webView.evaluateJavascript(
|
||||||
"""(async function() {
|
"""(async function() {
|
||||||
identifier = String.raw`$identifier`
|
identifier = String.raw`$identifier`
|
||||||
|
@ -266,7 +266,7 @@ class PoTokenWebView private constructor(
|
||||||
* to [generatorEmitter].
|
* to [generatorEmitter].
|
||||||
*/
|
*/
|
||||||
private fun onInitializationErrorCloseAndCancel(error: Throwable) {
|
private fun onInitializationErrorCloseAndCancel(error: Throwable) {
|
||||||
Handler(Looper.getMainLooper()).post {
|
runOnMainThread(generatorEmitter) {
|
||||||
close()
|
close()
|
||||||
generatorEmitter.onError(error)
|
generatorEmitter.onError(error)
|
||||||
}
|
}
|
||||||
|
@ -295,15 +295,29 @@ class PoTokenWebView private constructor(
|
||||||
private val TAG = PoTokenWebView::class.simpleName
|
private val TAG = PoTokenWebView::class.simpleName
|
||||||
private const val GOOGLE_API_KEY = "AIzaSyDyT5W0Jh49F30Pqqtyfdf7pDLFKLJoAnw"
|
private const val GOOGLE_API_KEY = "AIzaSyDyT5W0Jh49F30Pqqtyfdf7pDLFKLJoAnw"
|
||||||
private const val REQUEST_KEY = "O43z0dpjhgX20SCx4KAo"
|
private const val REQUEST_KEY = "O43z0dpjhgX20SCx4KAo"
|
||||||
private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.3"
|
private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " +
|
||||||
|
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.3"
|
||||||
|
|
||||||
override fun newPoTokenGenerator(context: Context): Single<PoTokenGenerator> =
|
override fun newPoTokenGenerator(context: Context): Single<PoTokenGenerator> =
|
||||||
Single.create { emitter ->
|
Single.create { emitter ->
|
||||||
Handler(Looper.getMainLooper()).post {
|
runOnMainThread(emitter) {
|
||||||
val potWv = PoTokenWebView(context, emitter)
|
val potWv = PoTokenWebView(context, emitter)
|
||||||
potWv.loadHtmlAndObtainBotguard(context)
|
potWv.loadHtmlAndObtainBotguard(context)
|
||||||
emitter.setDisposable(potWv.disposables)
|
emitter.setDisposable(potWv.disposables)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs [runnable] on the main thread using `Handler(Looper.getMainLooper()).post()`, and
|
||||||
|
* if the `post` fails emits an error on [emitterIfPostFails].
|
||||||
|
*/
|
||||||
|
private fun runOnMainThread(
|
||||||
|
emitterIfPostFails: SingleEmitter<out Any>,
|
||||||
|
runnable: () -> Unit,
|
||||||
|
) {
|
||||||
|
if (!Handler(Looper.getMainLooper()).post(runnable)) {
|
||||||
|
emitterIfPostFails.onError(PoTokenException("Could not run on main thread"))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue