mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +00:00
fix(dual-screen): the bottom-screen terminal keeps its shell when another app covers that screen (#2366)
* fix(dual-screen): the bottom-screen terminal keeps its shell when another app covers that screen * fix(session): sweep the kept terminal shell's process tree when the session ends
This commit is contained in:
1 parent
4e3eeea5e2
commit
d0398fd853
5 files changed
+128
-8
No files matched your search
@@ -2264,10 +2264,11 @@ class SessionService : Service() {
|
||||
syncWatcher = null
|
||||
val prootPid = sessionPid
|
||||
sessionPid = -1
|
||||
// The kept shell goes through the same teardown, which reads its descendants before signalling it.
|
||||
val shell = SessionTerminal.detach(sessionGen)?.let { pid -> readStat(pid)?.second?.let { pid to it } }
|
||||
val auxiliary = synchronized(auxiliaryProcessesLock) {
|
||||
auxiliaryProcesses.toMap().also { auxiliaryProcesses.clear() }
|
||||
}
|
||||
SessionTerminal.clear(sessionGen)
|
||||
} + listOfNotNull(shell)
|
||||
BottomDesktop.stop(this, stoppedGen)
|
||||
val controller = suspendController
|
||||
suspendController = null
|
||||
|
||||
@@ -14,6 +14,12 @@ object SessionTerminal {
|
||||
|
||||
@Volatile private var launch: Launch? = null
|
||||
|
||||
private class Kept(val session: TerminalSession, val generation: Int)
|
||||
|
||||
// The bottom screen's presentation is dismissed whenever another app covers that display
|
||||
// (a browser opened for a sign-in), so its shell is kept for the next panel.
|
||||
@Volatile private var kept: Kept? = null
|
||||
|
||||
fun prepare(
|
||||
command: List<String>,
|
||||
hostEnvironment: Array<String>,
|
||||
@@ -32,8 +38,41 @@ object SessionTerminal {
|
||||
).also { it.mSessionName = "DroidDeck Linux shell" }
|
||||
}
|
||||
|
||||
fun reuse(client: TerminalSessionClient): TerminalSession? {
|
||||
val current = kept ?: return null
|
||||
if (current.generation != launch?.generation || !current.session.isRunning) {
|
||||
kept = null
|
||||
return null
|
||||
}
|
||||
current.session.updateTerminalSessionClient(client)
|
||||
return current.session
|
||||
}
|
||||
|
||||
fun keep(session: TerminalSession) {
|
||||
val generation = launch?.generation ?: return
|
||||
kept = Kept(session, generation)
|
||||
}
|
||||
|
||||
fun release(session: TerminalSession?) {
|
||||
if (session != null && kept?.session === session) kept = null
|
||||
}
|
||||
|
||||
fun clear(generation: Int? = null) {
|
||||
val current = launch ?: return
|
||||
if (generation == null || current.generation == generation) launch = null
|
||||
if (generation == null || current.generation == generation) {
|
||||
launch = null
|
||||
kept?.session?.takeIf { it.pid > 0 }?.finishIfRunning()
|
||||
kept = null
|
||||
}
|
||||
}
|
||||
|
||||
/** Ends this generation's terminal without killing its shell, and returns the shell's pid if it still runs. */
|
||||
fun detach(generation: Int): Int? {
|
||||
val current = launch ?: return null
|
||||
if (current.generation != generation) return null
|
||||
launch = null
|
||||
val pid = kept?.session?.takeIf { it.isRunning && it.pid > 0 }?.pid
|
||||
kept = null
|
||||
return pid
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user