mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-26 00:06:02 +00:00
fix(session): relaunch into a fresh activity so Switch to Desktop does not leave the loader up (#3227)
This commit is contained in:
1 parent
53c1933ac8
commit
8ec499ae3f
2 files changed
+30
-4
No files matched your search
@@ -3414,8 +3414,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (status == 0) SessionState.takeRelaunch()?.let { next ->
|
||||
next.putExtra(EXTRA_RETURN_HOME, intent.getBooleanExtra(EXTRA_RETURN_HOME, false))
|
||||
next.putExtra(EXTRA_LINK_TASK, intent.getIntExtra(EXTRA_LINK_TASK, -1))
|
||||
setIntent(next)
|
||||
recreate()
|
||||
relaunch(next)
|
||||
return@runOnUiThread
|
||||
}
|
||||
showEnded(status, hint)
|
||||
@@ -3423,6 +3422,16 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}, "session-end-hint").start()
|
||||
}
|
||||
|
||||
// recreate() keeps this window, and Compose content added to it afterwards never recomposes, so the
|
||||
// loading screen of the next session stays up over a running session. A new instance gets its own window.
|
||||
// This instance finishes first because the activity is singleTask and would otherwise take the intent itself.
|
||||
private fun relaunch(next: Intent) {
|
||||
closeAtOnce = true
|
||||
super.finish()
|
||||
startActivity(next)
|
||||
overridePendingTransition(0, 0)
|
||||
}
|
||||
|
||||
private fun showEnded(status: Int, hint: EndHint?) {
|
||||
if (status == 0 && hint?.evenOnSuccess != true) {
|
||||
finish()
|
||||
@@ -6050,8 +6059,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
Log.w(TAG, "ignoring agent start while session phase is ${SessionState.phase}")
|
||||
return
|
||||
}
|
||||
setIntent(intent)
|
||||
recreate()
|
||||
relaunch(android.content.Intent(intent).setClass(this, SessionActivity::class.java))
|
||||
return
|
||||
}
|
||||
if (this.intent.getBooleanExtra(EXTRA_RETURN_HOME, false)) intent.putExtra(EXTRA_RETURN_HOME, true)
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.droiddeck.launcher
|
||||
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
|
||||
class SessionRelaunchTest {
|
||||
// recreate() keeps the window, and Compose content set on it afterwards never recomposes (#2668):
|
||||
// a session relaunched that way kept its loading screen up over a running desktop.
|
||||
@Test fun sessionAndLauncherActivitiesNeverRecreateThemselves() {
|
||||
listOf("SessionActivity.kt", "FrontEndActivity.kt").forEach { name ->
|
||||
val code = File("src/main/java/com/droiddeck/launcher/$name").readLines()
|
||||
.map { it.substringBefore("//") }
|
||||
val calls = code.withIndex().filter { (_, line) -> Regex("""\brecreate\(\)""").containsMatchIn(line) }
|
||||
assertTrue("$name calls recreate() at line(s) ${calls.map { it.index + 1 }}", calls.isEmpty())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user