Leave the server when the app is swiped away
The process lived on without a screen, or was killed without a word, and the server held our identity as a ghost until it timed out, refusing a reconnect in the meantime as a clone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import android.net.wifi.WifiManager
|
|||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import androidx.lifecycle.LifecycleService
|
import androidx.lifecycle.LifecycleService
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -66,6 +67,18 @@ class ConnectionService : LifecycleService() {
|
|||||||
return START_NOT_STICKY
|
return START_NOT_STICKY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The user swiped the app away: they are done with it, connection included. Leaving
|
||||||
|
* properly spares the server a ghost that would hold our identity until it times out.
|
||||||
|
*/
|
||||||
|
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||||
|
super.onTaskRemoved(rootIntent)
|
||||||
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
sessions.leave()
|
||||||
|
stopSelf()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
wifiLock.release()
|
wifiLock.release()
|
||||||
wakeLock.release()
|
wakeLock.release()
|
||||||
|
|||||||
@@ -162,6 +162,12 @@ class SessionController(private val context: Context) {
|
|||||||
session.disconnect()
|
session.disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Leaves the server before returning, for when the app goes away with the connection. */
|
||||||
|
fun leave() {
|
||||||
|
network.leaving()
|
||||||
|
session.shutdown()
|
||||||
|
}
|
||||||
|
|
||||||
// ---- bookmarks ----
|
// ---- bookmarks ----
|
||||||
|
|
||||||
fun addBookmark(label: String, address: String, nickname: String, password: String) {
|
fun addBookmark(label: String, address: String, nickname: String, password: String) {
|
||||||
|
|||||||
Reference in New Issue
Block a user