feat(modules/UpdaterModule): show update dialog when bundle is updated in background
This commit is contained in:
parent
da337dfd98
commit
87d4c78c67
2 changed files with 15 additions and 9 deletions
|
|
@ -86,12 +86,11 @@ object HookScriptLoaderModule : Module() {
|
|||
|
||||
if (mainScript.exists()) {
|
||||
Log.i("Main script exists, updating in background...")
|
||||
UpdaterModule.downloadScript()
|
||||
|
||||
UpdaterModule.downloadScript(showUpdateDialog = true)
|
||||
ready.await()
|
||||
} else {
|
||||
Log.i("Main script does not exist, downloading before load...")
|
||||
val download = async { UpdaterModule.downloadScript().join() }
|
||||
val download = async { UpdaterModule.downloadScript(showUpdateDialog = false).join() }
|
||||
awaitAll(ready, download)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ object UpdaterModule : Module() {
|
|||
}
|
||||
}
|
||||
|
||||
fun downloadScript(activity: Activity? = null): Job = scope.launch {
|
||||
fun downloadScript(activity: Activity? = null, showUpdateDialog: Boolean = true): Job = scope.launch {
|
||||
try {
|
||||
HttpClient(CIO) {
|
||||
expectSuccess = false
|
||||
|
|
@ -115,15 +115,22 @@ object UpdaterModule : Module() {
|
|||
|
||||
Log.i("Bundle updated (${bytes.size} bytes)")
|
||||
|
||||
// This is a retry, so we show a dialog
|
||||
if (activity != null) {
|
||||
withContext(Dispatchers.Main) {
|
||||
AlertDialog.Builder(activity).setTitle("Revenge Update Successful")
|
||||
if (showUpdateDialog) {
|
||||
val activity = activity ?: lastActivity?.get()
|
||||
|
||||
activity?.runOnUiThread {
|
||||
AlertDialog.Builder(activity)
|
||||
.setTitle("Revenge Update Downloaded")
|
||||
.setMessage("A reload is required for changes to take effect.")
|
||||
.setPositiveButton("Reload") { dialog, _ ->
|
||||
reloadApp()
|
||||
dialog.dismiss()
|
||||
}.setCancelable(false).show()
|
||||
}
|
||||
.setNegativeButton("Later") { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
}
|
||||
.setCancelable(false)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue