fix: watchdog debounce
This commit is contained in:
1 parent
a80855c8c9
commit
709a0cd5e0
1 file changed
+8
-1
@@ -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,15 +270,20 @@ class ProxyService : Service() {
|
|||||||
networkInitialized = true
|
networkInitialized = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Дебаунс: отменяем предыдущий ждущий перезапуск, если он был
|
||||||
|
networkDebounceJob?.cancel()
|
||||||
|
networkDebounceJob = serviceScope.launch {
|
||||||
|
kotlinx.coroutines.delay(2000)
|
||||||
if (!userStopped.get() && process.get() != null) {
|
if (!userStopped.get() && process.get() != null) {
|
||||||
addLog("=== СМЕНА СЕТИ — ПЕРЕЗАПУСК ===")
|
addLog("=== СМЕНА СЕТИ — ПЕРЕЗАПУСК ===")
|
||||||
updateNotification("VK TURN Proxy", "Смена сети, переподключение...")
|
updateNotification("VK TURN Proxy", "Смена сети, переподключение...")
|
||||||
restartCount = 0
|
restartCount = 0
|
||||||
// P2-5: destroyForcibly()
|
|
||||||
process.get()?.destroyForcibly()
|
process.get()?.destroyForcibly()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
networkCallback = cb
|
networkCallback = cb
|
||||||
cm.registerDefaultNetworkCallback(cb)
|
cm.registerDefaultNetworkCallback(cb)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user