fix: watchdog debounce

This commit is contained in:
samosvalishe committed 2026-04-03 02:19:04 +03:00
1 parent a80855c8c9
commit 709a0cd5e0
1 file changed
+13 -6
@@ -259,6 +259,8 @@ class ProxyService : Service() {
// ── Network Handover ────────────────────────────────────────────────────── // ── Network Handover ──────────────────────────────────────────────────────
private var networkDebounceJob: kotlinx.coroutines.Job? = null
private fun registerNetworkCallback() { private fun registerNetworkCallback() {
networkInitialized = false networkInitialized = false
val cm = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val cm = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
@@ -268,12 +270,17 @@ class ProxyService : Service() {
networkInitialized = true networkInitialized = true
return return
} }
if (!userStopped.get() && process.get() != null) {
addLog("=== СМЕНА СЕТИ — ПЕРЕЗАПУСК ===") // Дебаунс: отменяем предыдущий ждущий перезапуск, если он был
updateNotification("VK TURN Proxy", "Смена сети, переподключение...") networkDebounceJob?.cancel()
restartCount = 0 networkDebounceJob = serviceScope.launch {
// P2-5: destroyForcibly() kotlinx.coroutines.delay(2000)
process.get()?.destroyForcibly() if (!userStopped.get() && process.get() != null) {
addLog("=== СМЕНА СЕТИ — ПЕРЕЗАПУСК ===")
updateNotification("VK TURN Proxy", "Смена сети, переподключение...")
restartCount = 0
process.get()?.destroyForcibly()
}
} }
} }
} }