Add SettingsChangeManager and centralize restart logic

This commit is contained in:
2dust
2026-01-05 10:40:55 +08:00
parent 37bd57ffc5
commit 71f0d98e68
10 changed files with 60 additions and 28 deletions
@@ -567,10 +567,6 @@ object MmkvManager {
return settingsStorage.decodeStringSet(key)
}
//endregion
//region Others
/**
* Encodes the start on boot setting.
*
@@ -594,17 +590,17 @@ object MmkvManager {
//region WebDAV
/**
* Encodes the WebDAV config as JSON into settings storage.
* Encodes the WebDAV config as JSON into storage.
*/
fun encodeWebDavConfig(config: WebDavConfig): Boolean {
return settingsStorage.encode(KEY_WEBDAV_CONFIG, JsonUtil.toJson(config))
return mainStorage.encode(KEY_WEBDAV_CONFIG, JsonUtil.toJson(config))
}
/**
* Decodes the WebDAV config from settings storage.
* Decodes the WebDAV config from storage.
*/
fun decodeWebDavConfig(): WebDavConfig? {
val json = settingsStorage.decodeString(KEY_WEBDAV_CONFIG) ?: return null
val json = mainStorage.decodeString(KEY_WEBDAV_CONFIG) ?: return null
return JsonUtil.fromJson(json, WebDavConfig::class.java)
}
@@ -0,0 +1,32 @@
package com.v2ray.ang.handler
import kotlinx.coroutines.flow.MutableStateFlow
object SettingsChangeManager {
private val _restartService = MutableStateFlow(false)
private val _reinitGroupTab = MutableStateFlow(false)
// Mark restartService as requiring a restart
fun makeRestartService() {
_restartService.value = true
}
// Read and clear the restartService flag
fun consumeRestartService(): Boolean {
val v = _restartService.value
_restartService.value = false
return v
}
// Mark reinitGroupTab as requiring tab reinitialization
fun makeReinitGroupTab() {
_reinitGroupTab.value = true
}
// Read and clear the reinitGroupTab flag
fun consumeReinitGroupTab(): Boolean {
val v = _reinitGroupTab.value
_reinitGroupTab.value = false
return v
}
}
@@ -70,7 +70,7 @@ object V2RayServiceManager {
* @param context The context from which the service is stopped.
*/
fun stopVService(context: Context) {
context.toast(R.string.toast_services_stop)
//context.toast(R.string.toast_services_stop)
MessageUtil.sendMsg2Service(context, AppConfig.MSG_STATE_STOP, "")
}