Skip to content

Commit 507b7b5

Browse files
committed
perf: toast delayMillis
1 parent 4c36cf2 commit 507b7b5

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ class App : Application() {
9898
}
9999

100100
val startTime = System.currentTimeMillis()
101+
var justStarted: Boolean = true
102+
get() {
103+
if (field) {
104+
field = System.currentTimeMillis() - startTime < 3_000
105+
}
106+
return field
107+
}
101108

102109
val activityManager by lazy { app.getSystemService(ACTIVITY_SERVICE) as ActivityManager }
103110
val appOpsManager by lazy { app.getSystemService(APP_OPS_SERVICE) as AppOpsManager }

app/src/main/kotlin/li/songe/gkd/service/GkdTileService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class GkdTileService : BaseTileService() {
2424
}
2525

2626
private val modifyA11yMutex by lazy { Mutex() }
27-
private const val A11Y_AWAIT_START_TIME = 1000L
27+
private const val A11Y_AWAIT_START_TIME = 2000L
2828
private const val A11Y_AWAIT_FIX_TIME = 500L
2929

3030
fun switchA11yService() = appScope.launchTry(Dispatchers.IO) {

app/src/main/kotlin/li/songe/gkd/service/StatusService.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import kotlinx.coroutines.flow.debounce
99
import kotlinx.coroutines.flow.stateIn
1010
import kotlinx.coroutines.launch
1111
import li.songe.gkd.META
12+
import li.songe.gkd.app
1213
import li.songe.gkd.notif.abNotif
1314
import li.songe.gkd.permission.foregroundServiceSpecialUseState
1415
import li.songe.gkd.permission.notificationState
@@ -29,7 +30,11 @@ class StatusService : Service(), OnSimpleLife {
2930

3031
init {
3132
useAliveFlow(isRunning)
32-
useAliveToast("常驻通知", onlyWhenVisible = true)
33+
useAliveToast(
34+
name = "常驻通知",
35+
onlyWhenVisible = true,
36+
delayMillis = if (app.justStarted) 1000 else 0
37+
)
3338
onCreated {
3439
abNotif.notifyService()
3540
scope.launch {

app/src/main/kotlin/li/songe/gkd/shizuku/ShizukuApi.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import kotlinx.coroutines.flow.debounce
1414
import kotlinx.coroutines.flow.map
1515
import kotlinx.coroutines.flow.stateIn
1616
import li.songe.gkd.META
17+
import li.songe.gkd.app
1718
import li.songe.gkd.appScope
1819
import li.songe.gkd.data.AppInfo
1920
import li.songe.gkd.data.otherUserMapFlow
@@ -119,7 +120,7 @@ val updateBinderMutex = MutexState()
119120
private fun updateShizukuBinder() = appScope.launchTry(Dispatchers.IO) {
120121
updateBinderMutex.withStateLock {
121122
if (shizukuUsedFlow.value) {
122-
if (isActivityVisible()) {
123+
if (!app.justStarted && isActivityVisible()) {
123124
toast("正在连接 Shizuku 服务...")
124125
}
125126
shizukuContextFlow.value = ShizukuContext(
@@ -132,10 +133,11 @@ private fun updateShizukuBinder() = appScope.launchTry(Dispatchers.IO) {
132133
},
133134
)
134135
if (isActivityVisible()) {
136+
val delayMillis = if (app.justStarted) 1200L else 0L
135137
if (shizukuContextFlow.value.serviceWrapper == null) {
136-
toast("Shizuku 服务连接失败")
138+
toast("Shizuku 服务连接失败", delayMillis)
137139
} else {
138-
toast("Shizuku 服务连接成功")
140+
toast("Shizuku 服务连接成功", delayMillis)
139141
}
140142
}
141143
} else if (shizukuContextFlow.value != defaultShizukuContext) {

app/src/main/kotlin/li/songe/gkd/util/LifecycleCallbacks.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ interface OnSimpleLife {
4646
onDestroyed { stateFlow.value = false }
4747
}
4848

49-
fun useAliveToast(name: String, onlyWhenVisible: Boolean = false) {
49+
fun useAliveToast(name: String, onlyWhenVisible: Boolean = false, delayMillis: Long = 0L) {
5050
onCreated {
5151
if (isActivityVisible() || !onlyWhenVisible) {
52-
toast("${name}已启动")
52+
toast("${name}已启动", delayMillis)
5353
}
5454
}
5555
onDestroyed {

app/src/main/kotlin/li/songe/gkd/util/Toast.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ import li.songe.gkd.appScope
2929
import li.songe.gkd.service.A11yService
3030
import li.songe.gkd.store.storeFlow
3131

32-
33-
fun toast(text: CharSequence) {
34-
Toaster.show(text)
32+
fun toast(text: CharSequence, delayMillis: Long = 0L) {
33+
if (delayMillis > 0) {
34+
Toaster.delayedShow(text, delayMillis)
35+
} else {
36+
Toaster.show(text)
37+
}
3538
}
3639

3740
private val darkTheme: Boolean

0 commit comments

Comments
 (0)