Skip to content

Commit a768ebf

Browse files
committed
refactor(UpdateChecker): Delay update check until first activity is created
1 parent d9c008b commit a768ebf

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

app/src/main/java/io/github/chsbuffer/revancedxposed/MainHook.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ fun inContext(lpparam: LoadPackageParam, f: (Application) -> Unit) {
7979
val app = param.thisObject as Application
8080
Utils.setContext(app)
8181
f(app)
82-
UpdateChecker(app).apply {
83-
hookNewActivity()
84-
autoCheckUpdate()
85-
}
82+
UpdateChecker(app).hookNewActivity()
8683
}
8784
})
8885
}

app/src/main/java/io/github/chsbuffer/revancedxposed/common/UpdateChecker.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ class UpdateChecker(private val context: Context) : CoroutineScope {
6666
private lateinit var latestVersionInfo: VersionInfo
6767
private lateinit var latestRelease: ReleaseInfo
6868

69+
lateinit var unhook: XC_MethodHook.Unhook
6970
fun hookNewActivity() {
70-
XposedHelpers.findAndHookMethod(
71+
unhook = XposedHelpers.findAndHookMethod(
7172
Instrumentation::class.java,
7273
"newActivity",
7374
ClassLoader::class.java,
@@ -76,6 +77,8 @@ class UpdateChecker(private val context: Context) : CoroutineScope {
7677
object : XC_MethodHook() {
7778
override fun afterHookedMethod(param: MethodHookParam) {
7879
currentActivity = WeakReference(param.result as Activity)
80+
autoCheckUpdate()
81+
unhook.unhook()
7982
}
8083
})
8184
}

0 commit comments

Comments
 (0)