From 90ecc5fd2e6934b168997cbd6b9ce7450b217571 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Sun, 12 Oct 2025 03:00:15 +0700 Subject: [PATCH] fix(modules/UpdaterModule): actually fix memory leak correctly --- .../github/revenge/xposed/modules/UpdaterModule.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/io/github/revenge/xposed/modules/UpdaterModule.kt b/app/src/main/kotlin/io/github/revenge/xposed/modules/UpdaterModule.kt index 6353c5b..27d274e 100644 --- a/app/src/main/kotlin/io/github/revenge/xposed/modules/UpdaterModule.kt +++ b/app/src/main/kotlin/io/github/revenge/xposed/modules/UpdaterModule.kt @@ -21,6 +21,7 @@ import io.ktor.http.* import kotlinx.coroutines.* import kotlinx.serialization.Serializable import java.io.File +import java.lang.ref.WeakReference @Serializable data class CustomLoadUrl( @@ -40,6 +41,7 @@ data class LoaderConfig( object UpdaterModule : Module() { private lateinit var config: LoaderConfig private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO) + private var lastActivity: WeakReference? = null private lateinit var cacheDir: File private lateinit var bundle: File @@ -128,11 +130,17 @@ object UpdaterModule : Module() { } } catch (e: Throwable) { Log.e("Failed to download script", e) - if (activity != null) showErrorDialog(e, activity) + showErrorDialog(e) } } - fun showErrorDialog(e: Throwable, activity: Activity) { + override fun onActivity(activity: Activity) { + lastActivity = WeakReference(activity) + } + + fun showErrorDialog(e: Throwable) { + val activity = lastActivity?.get() ?: return + activity.runOnUiThread { AlertDialog.Builder(activity).setTitle("Revenge Update Failed").setMessage( """