Skip to content

Commit 5fb7ae1

Browse files
committed
perf: rm toast, add route log
1 parent 6a72e9c commit 5fb7ae1

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

app/src/main/kotlin/li/songe/gkd/MainViewModel.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import li.songe.gkd.util.subsItemsFlow
6767
import li.songe.gkd.util.toast
6868
import li.songe.gkd.util.updateSubsMutex
6969
import li.songe.gkd.util.updateSubscription
70+
import li.songe.loc.Loc
7071
import rikka.shizuku.Shizuku
7172
import java.nio.file.Files
7273
import kotlin.reflect.jvm.jvmName
@@ -80,8 +81,10 @@ class MainViewModel : BaseViewModel(), OnSimpleLife {
8081
}
8182

8283
init {
84+
LogUtils.d("MainViewModel:init")
8385
_instance = this
8486
addCloseable {
87+
LogUtils.d("MainViewModel:close")
8588
if (_instance == this) { // 可能同时存在 2 个 MainViewModel 实例
8689
_instance = null
8790
}
@@ -94,19 +97,30 @@ class MainViewModel : BaseViewModel(), OnSimpleLife {
9497
val topRoute get() = backStack.last()
9598

9699
private val backThrottleTimer = ThrottleTimer()
97-
fun popPage() = runMainPost {
100+
101+
@Loc
102+
fun popPage(@Loc loc: String = "") = runMainPost {
98103
if (backThrottleTimer.expired() && backStack.size > 1) {
104+
val old = backStack.last()
99105
backStack.removeAt(backStack.lastIndex)
106+
LogUtils.d("popPage", "$old -> ${backStack.last()}", loc = loc)
100107
}
101108
}
102109

103-
fun navigatePage(navKey: NavKey, replaced: Boolean = false) = runMainPost {
110+
@Loc
111+
fun navigatePage(
112+
navKey: NavKey,
113+
replaced: Boolean = false,
114+
@Loc loc: String = "",
115+
) = runMainPost {
104116
if (navKey != backStack.last()) {
117+
val old = backStack.last()
105118
if (replaced) {
106119
backStack[backStack.lastIndex] = navKey
107120
} else {
108121
backStack.add(navKey)
109122
}
123+
LogUtils.d("navigatePage", "$old -> ${backStack.last()}", loc = loc)
110124
}
111125
}
112126

@@ -393,6 +407,5 @@ class MainViewModel : BaseViewModel(), OnSimpleLife {
393407
// for OnSimpleLife
394408
onCreated()
395409
addCloseable { onDestroyed() }
396-
toast("MainViewModel:init")
397410
}
398411
}

0 commit comments

Comments
 (0)