mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 21:06:09 +00:00
fix(stores): guard sign-in and local fixtures
This commit is contained in:
1 parent
2770a481c2
commit
48fa1df3ba
2 files changed
+40
-15
No files matched your search
@@ -2,6 +2,7 @@ package com.droiddeck.launcher.stores.amazon
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.InstalledStoreGame
|
||||
@@ -17,31 +18,53 @@ import org.json.JSONObject
|
||||
|
||||
object AmazonBackend : StoreBackend {
|
||||
override val store: Store = Store.AMAZON
|
||||
private val signingIn = java.util.concurrent.atomic.AtomicBoolean(false)
|
||||
|
||||
init {
|
||||
LoginFlows.amazonFlow = { AmazonLogin.create() }
|
||||
}
|
||||
|
||||
override fun signIn(context: Context) {
|
||||
if (!signingIn.compareAndSet(false, true)) return
|
||||
val app = context.applicationContext
|
||||
Thread({
|
||||
val available = AmazonNative.prepare(app) { state ->
|
||||
if (state is com.droiddeck.launcher.core.AddonPack.State.Downloading) {
|
||||
StoresState.post { StoresState.status[store] = app.getString(R.string.stores_engine_downloading, store.label, (state.progress * 100).toInt()) }
|
||||
try {
|
||||
Thread({
|
||||
try {
|
||||
val available = runCatching {
|
||||
AmazonNative.prepare(app) { state ->
|
||||
if (state is com.droiddeck.launcher.core.AddonPack.State.Downloading) {
|
||||
StoresState.post { StoresState.status[store] = app.getString(R.string.stores_engine_downloading, store.label, (state.progress * 100).toInt()) }
|
||||
}
|
||||
}
|
||||
}.onFailure { Log.w("AmazonBackend", "Engine preparation failed", it) }.getOrDefault(false)
|
||||
StoresState.post {
|
||||
try {
|
||||
StoresState.status.remove(store)
|
||||
if (available) {
|
||||
StoresState.problems.remove(store)
|
||||
app.startActivity(Intent(app, StoreLoginActivity::class.java)
|
||||
.putExtra(StoreLoginActivity.EXTRA_STORE, store.id)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
} else {
|
||||
StoresState.problems[store] = app.getString(R.string.stores_engine_failed, store.label)
|
||||
}
|
||||
} finally {
|
||||
signingIn.set(false)
|
||||
}
|
||||
}
|
||||
} catch (error: Exception) {
|
||||
signingIn.set(false)
|
||||
Log.w("AmazonBackend", "Could not finish engine preparation", error)
|
||||
}
|
||||
}
|
||||
}, "amazon-engine").start()
|
||||
} catch (error: Exception) {
|
||||
signingIn.set(false)
|
||||
StoresState.post {
|
||||
StoresState.status.remove(store)
|
||||
if (available) {
|
||||
StoresState.problems.remove(store)
|
||||
app.startActivity(Intent(app, StoreLoginActivity::class.java)
|
||||
.putExtra(StoreLoginActivity.EXTRA_STORE, store.id)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
} else {
|
||||
StoresState.problems[store] = app.getString(R.string.stores_engine_failed, store.label)
|
||||
}
|
||||
StoresState.problems[store] = app.getString(R.string.stores_engine_failed, store.label)
|
||||
}
|
||||
}, "amazon-engine").start()
|
||||
Log.w("AmazonBackend", "Could not start engine preparation", error)
|
||||
}
|
||||
}
|
||||
|
||||
override fun signOut(context: Context) {
|
||||
|
||||
Reference in new issue
Block a user