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()) {
|
if (mainScript.exists()) {
|
||||||
Log.i("Main script exists, updating in background...")
|
Log.i("Main script exists, updating in background...")
|
||||||
UpdaterModule.downloadScript()
|
UpdaterModule.downloadScript(showUpdateDialog = true)
|
||||||
|
|
||||||
ready.await()
|
ready.await()
|
||||||
} else {
|
} else {
|
||||||
Log.i("Main script does not exist, downloading before load...")
|
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)
|
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 {
|
try {
|
||||||
HttpClient(CIO) {
|
HttpClient(CIO) {
|
||||||
expectSuccess = false
|
expectSuccess = false
|
||||||
|
|
@ -115,15 +115,22 @@ object UpdaterModule : Module() {
|
||||||
|
|
||||||
Log.i("Bundle updated (${bytes.size} bytes)")
|
Log.i("Bundle updated (${bytes.size} bytes)")
|
||||||
|
|
||||||
// This is a retry, so we show a dialog
|
if (showUpdateDialog) {
|
||||||
if (activity != null) {
|
val activity = activity ?: lastActivity?.get()
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
AlertDialog.Builder(activity).setTitle("Revenge Update Successful")
|
activity?.runOnUiThread {
|
||||||
|
AlertDialog.Builder(activity)
|
||||||
|
.setTitle("Revenge Update Downloaded")
|
||||||
.setMessage("A reload is required for changes to take effect.")
|
.setMessage("A reload is required for changes to take effect.")
|
||||||
.setPositiveButton("Reload") { dialog, _ ->
|
.setPositiveButton("Reload") { dialog, _ ->
|
||||||
reloadApp()
|
reloadApp()
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}.setCancelable(false).show()
|
}
|
||||||
|
.setNegativeButton("Later") { dialog, _ ->
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
.setCancelable(false)
|
||||||
|
.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue