diff --git a/app/src/main/kotlin/li/songe/gkd/service/GkdAbService.kt b/app/src/main/kotlin/li/songe/gkd/service/GkdAbService.kt index fd20a33..908ce75 100644 --- a/app/src/main/kotlin/li/songe/gkd/service/GkdAbService.kt +++ b/app/src/main/kotlin/li/songe/gkd/service/GkdAbService.kt @@ -14,6 +14,7 @@ import android.view.View import android.view.WindowManager import android.view.accessibility.AccessibilityEvent import android.view.accessibility.AccessibilityNodeInfo +import androidx.core.app.NotificationManagerCompat import com.blankj.utilcode.util.LogUtils import com.blankj.utilcode.util.ScreenUtils import com.blankj.utilcode.util.ToastUtils @@ -450,6 +451,19 @@ class GkdAbService : CompositionAbService({ onDestroy { isRunning.value = false } + + // 在[系统重启]/[被其它高权限应用重启]时自动打开通知栏状态服务 + if (storeFlow.value.enableStatusService && + NotificationManagerCompat.from(context).areNotificationsEnabled() && + !ManageService.isRunning.value + ) { + ManageService.start(context) + } + onDestroy { + if (!storeFlow.value.enableStatusService && ManageService.isRunning.value) { + ManageService.stop() + } + } }) { companion object { diff --git a/app/src/main/kotlin/li/songe/gkd/ui/ControlPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/ControlPage.kt index 0c67211..ab754de 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/ControlPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/ControlPage.kt @@ -91,14 +91,24 @@ fun ControlPage() { TextSwitch( name = "常驻通知栏", desc = "在通知栏显示服务运行状态,避免被某些系统回收", - checked = manageRunning, + checked = manageRunning && store.enableStatusService, onCheckedChange = { if (it) { if (!checkOrRequestNotifPermission(context)) { return@TextSwitch } + updateStorage( + storeFlow, store.copy( + enableStatusService = true + ) + ) ManageService.start(context) } else { + updateStorage( + storeFlow, store.copy( + enableStatusService = false + ) + ) ManageService.stop(context) } }) diff --git a/app/src/main/kotlin/li/songe/gkd/util/Store.kt b/app/src/main/kotlin/li/songe/gkd/util/Store.kt index 549d042..df74cd8 100644 --- a/app/src/main/kotlin/li/songe/gkd/util/Store.kt +++ b/app/src/main/kotlin/li/songe/gkd/util/Store.kt @@ -45,6 +45,7 @@ fun updateStorage(stateFlow: StateFlow, newState: T) { @Serializable data class Store( val enableService: Boolean = true, + val enableStatusService: Boolean = true, val excludeFromRecents: Boolean = false, val captureScreenshot: Boolean = false, val httpServerPort: Int = 8888,