Make subscription config update optional

This commit is contained in:
2dust committed 2026-07-23 16:34:12 +08:00
1 parent 3ae13b0ba4
commit 3be230c024
6 files changed
+19 -8

No files matched your search

@@ -82,6 +82,7 @@ object AppConfig {
const val PREF_USE_HEV_TUNNEL = "pref_use_hev_tunnel_v2"
const val PREF_HEV_TUNNEL_LOGLEVEL = "pref_hev_tunnel_loglevel"
const val PREF_HEV_TUNNEL_RW_TIMEOUT = "pref_hev_tunnel_rw_timeout_v2"
const val PREF_UPDATE_SUBSCRIPTION = "pref_update_subscription"
const val PREF_AUTO_TEST_AFTER_UPDATE_SUBSCRIPTION = "pref_auto_test_after_update_subscription"
const val PREF_AUTO_REMOVE_INVALID_AFTER_TEST = "pref_auto_remove_invalid_after_test"
const val PREF_AUTO_SORT_AFTER_TEST = "pref_auto_sort_after_test"
@@ -4,5 +4,6 @@ import java.io.Serializable
data class SubscriptionUpdateMessage(
val key: Int,
val forcedUpdate: Boolean,
val subIds: List<String> = listOf()
) : Serializable
@@ -180,7 +180,7 @@ object SubscriptionUpdater {
MessageUtil.sendMsg2SubscriptionService(
applicationContext,
SubscriptionUpdateMessage(AppConfig.MSG_SUB_UPDATE_START, listOf(subId))
SubscriptionUpdateMessage(AppConfig.MSG_SUB_UPDATE_START, true, listOf(subId))
)
return Result.success()
@@ -93,7 +93,7 @@ class SubscriptionUpdateService : Service() {
updateSemaphore.withPermit {
try {
message.subIds.forEach { subId ->
updateSingle(subId)
updateSingle(subId, message.forcedUpdate)
}
} catch (e: Exception) {
LogUtil.e(AppConfig.TAG, "SubscriptionUpdateService update failed", e)
@@ -107,7 +107,7 @@ class SubscriptionUpdateService : Service() {
}
}
private suspend fun updateSingle(subId: String) {
private suspend fun updateSingle(subId: String, forcedUpdate: Boolean) {
val subItem = MmkvManager.decodeSubscription(subId) ?: return
if(!subItem.enabled || subItem.url.isEmpty()){
return
@@ -122,7 +122,9 @@ class SubscriptionUpdateService : Service() {
content = "Updating ${subItem.remarks}"
)
AngConfigManager.updateConfigViaSub(sub)
if (forcedUpdate || MmkvManager.decodeSettingsBool(AppConfig.PREF_UPDATE_SUBSCRIPTION, false)) {
AngConfigManager.updateConfigViaSub(sub)
}
if (MmkvManager.decodeSettingsBool(AppConfig.PREF_AUTO_TEST_AFTER_UPDATE_SUBSCRIPTION, false)) {
testSubscriptionServers(sub)
@@ -288,15 +288,20 @@ fun SubSettingScreen(
if (showUpdateDialog) {
var updateSubscription by rememberMmkvBool(AppConfig.PREF_UPDATE_SUBSCRIPTION, false)
var autoTestAfterUpdateSubscription by rememberMmkvBool(AppConfig.PREF_AUTO_TEST_AFTER_UPDATE_SUBSCRIPTION, false)
var autoRemoveInvalidAfterTest by rememberMmkvBool(AppConfig.PREF_AUTO_REMOVE_INVALID_AFTER_TEST, false)
var autoSortAfterTest by rememberMmkvBool(AppConfig.PREF_AUTO_SORT_AFTER_TEST, false)
AlertDialog(
onDismissRequest = { showUpdateDialog = false },
title = { Text(text = stringResource(R.string.title_sub_update)) },
text = {
Column {
SettingsSwitchItem(
title = stringResource(R.string.title_sub_update),
checked = updateSubscription,
onCheckedChange = { updateSubscription = it }
)
SettingsSwitchItem(
title = stringResource(R.string.title_pref_auto_test_after_update_subscription),
summary = stringResource(R.string.summary_pref_auto_test_after_update_subscription),
@@ -307,12 +312,14 @@ fun SubSettingScreen(
title = stringResource(R.string.title_pref_auto_remove_invalid_after_test),
summary = stringResource(R.string.summary_pref_auto_remove_invalid_after_test),
checked = autoRemoveInvalidAfterTest,
enabled = autoTestAfterUpdateSubscription,
onCheckedChange = { autoRemoveInvalidAfterTest = it }
)
SettingsSwitchItem(
title = stringResource(R.string.title_pref_auto_sort_after_test),
summary = stringResource(R.string.summary_pref_auto_sort_after_test),
checked = autoSortAfterTest,
enabled = autoTestAfterUpdateSubscription,
onCheckedChange = { autoSortAfterTest = it }
)
}
@@ -19,7 +19,7 @@ class SubscriptionsViewModel(application: Application) : BaseViewModel(applicati
private val subscriptions: MutableList<SubscriptionCache> =
MmkvManager.decodeSubscriptions().toMutableList()
private val _subsFlow = MutableStateFlow<List<SubscriptionCache>>(subscriptions.toList())
private val _subsFlow = MutableStateFlow(subscriptions.toList())
val subsFlow: StateFlow<List<SubscriptionCache>> = _subsFlow.asStateFlow()
fun getAll(): List<SubscriptionCache> = subscriptions.toList()
@@ -64,9 +64,9 @@ class SubscriptionsViewModel(application: Application) : BaseViewModel(applicati
val subIds = MmkvManager.decodeSubscriptions()
.filter { it.subscription.enabled && it.subscription.url.isNotEmpty() }
.map { it.guid }
if (subIds.isNotEmpty()) {
MessageUtil.sendMsg2SubscriptionService(app, SubscriptionUpdateMessage(AppConfig.MSG_SUB_UPDATE_START, subIds))
MessageUtil.sendMsg2SubscriptionService(app, SubscriptionUpdateMessage(AppConfig.MSG_SUB_UPDATE_START, false, subIds))
}
toast(R.string.subscription_updater_job_tips)