mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-25 07:46:01 +00:00
fix(session): picture in picture keeps the DroidDeck front end behind the game (#2559)
This commit is contained in:
1 parent
c57cc33125
commit
d058bab64f
3 files changed
+24
-4
No files matched your search
@@ -4,6 +4,7 @@ import android.app.Activity
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import com.droiddeck.launcher.session.SessionService
|
import com.droiddeck.launcher.session.SessionService
|
||||||
|
import com.droiddeck.launcher.session.SessionState
|
||||||
|
|
||||||
class HomeActivity : Activity() {
|
class HomeActivity : Activity() {
|
||||||
override fun attachBaseContext(newBase: android.content.Context) {
|
override fun attachBaseContext(newBase: android.content.Context) {
|
||||||
@@ -18,7 +19,7 @@ class HomeActivity : Activity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun routeHome() {
|
private fun routeHome() {
|
||||||
val destination = if (HomeApp.isActiveSteamSession()) {
|
val destination = if (HomeApp.isActiveSteamSession() && !SessionState.pipActive) {
|
||||||
Intent(this, SessionActivity::class.java)
|
Intent(this, SessionActivity::class.java)
|
||||||
.setAction(SessionService.ACTION_HOME_GUIDE)
|
.setAction(SessionService.ACTION_HOME_GUIDE)
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||||
@@ -32,7 +33,8 @@ class HomeActivity : Activity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
startActivity(destination)
|
if (SessionState.pipActive && destination.component?.className == FrontEndActivity::class.java.name) HomeApp.showFrontEnd(this, destination)
|
||||||
|
else startActivity(destination)
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -258,6 +258,19 @@ object HomeApp {
|
|||||||
fun isActiveSteamSession(): Boolean =
|
fun isActiveSteamSession(): Boolean =
|
||||||
SessionState.running && SessionState.mode == SessionService.MODE_STEAM
|
SessionState.running && SessionState.mode == SessionService.MODE_STEAM
|
||||||
|
|
||||||
|
fun showFrontEnd(context: Context, intent: Intent = Intent(context, FrontEndActivity::class.java)) {
|
||||||
|
val frontEnd = FrontEndActivity::class.java.name
|
||||||
|
val tasks = runCatching { context.getSystemService(android.app.ActivityManager::class.java)?.appTasks }.getOrNull().orEmpty()
|
||||||
|
val own = tasks.firstOrNull { task ->
|
||||||
|
runCatching { task.taskInfo.let { it.baseIntent.component?.className == frontEnd && it.topActivity?.className == frontEnd } }
|
||||||
|
.getOrDefault(false)
|
||||||
|
}
|
||||||
|
val launch = Intent(intent).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||||
|
if (own != null && runCatching { own.startActivity(context, launch, null) }.isSuccess) return
|
||||||
|
// The session task shares the front end's affinity, so without MULTIPLE_TASK the front end lands inside the session's PiP window.
|
||||||
|
context.startActivity(launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK))
|
||||||
|
}
|
||||||
|
|
||||||
fun openSystemHomeSettings(context: Context) {
|
fun openSystemHomeSettings(context: Context) {
|
||||||
try {
|
try {
|
||||||
context.startActivity(settingsIntent())
|
context.startActivity(settingsIntent())
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class SessionPipController(
|
|||||||
private set
|
private set
|
||||||
private var suppressAuto = false
|
private var suppressAuto = false
|
||||||
private var visit = false
|
private var visit = false
|
||||||
|
private var requested = false
|
||||||
private var lastParams = ""
|
private var lastParams = ""
|
||||||
val floating get() = transitioning || activity.isInPictureInPictureMode
|
val floating get() = transitioning || activity.isInPictureInPictureMode
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ class SessionPipController(
|
|||||||
return builder.build()
|
return builder.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun enter() {
|
fun enter(explicit: Boolean = true) {
|
||||||
if (!eligible()) {
|
if (!eligible()) {
|
||||||
Toast.makeText(activity, R.string.pip_not_ready, Toast.LENGTH_SHORT).show()
|
Toast.makeText(activity, R.string.pip_not_ready, Toast.LENGTH_SHORT).show()
|
||||||
return
|
return
|
||||||
@@ -59,8 +60,10 @@ class SessionPipController(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
prepare()
|
prepare()
|
||||||
|
requested = explicit
|
||||||
val entered = runCatching { activity.enterPictureInPictureMode(params(bounds())) }.getOrDefault(false)
|
val entered = runCatching { activity.enterPictureInPictureMode(params(bounds())) }.getOrDefault(false)
|
||||||
if (!entered) {
|
if (!entered) {
|
||||||
|
requested = false
|
||||||
restore()
|
restore()
|
||||||
Toast.makeText(activity, R.string.pip_unavailable, Toast.LENGTH_SHORT).show()
|
Toast.makeText(activity, R.string.pip_unavailable, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
@@ -68,7 +71,7 @@ class SessionPipController(
|
|||||||
|
|
||||||
fun leaving() {
|
fun leaving() {
|
||||||
if (!automatic() || !allowed()) return
|
if (!automatic() || !allowed()) return
|
||||||
if (Build.VERSION.SDK_INT < 31) enter() else prepare()
|
if (Build.VERSION.SDK_INT < 31) enter(explicit = false) else prepare()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun prepare() {
|
private fun prepare() {
|
||||||
@@ -85,6 +88,8 @@ class SessionPipController(
|
|||||||
showPipUi(true)
|
showPipUi(true)
|
||||||
SessionService.beginPip(activity)
|
SessionService.beginPip(activity)
|
||||||
SessionService.setActivityVisible(activity, true)
|
SessionService.setActivityVisible(activity, true)
|
||||||
|
if (requested) runCatching { com.droiddeck.launcher.HomeApp.showFrontEnd(activity) }
|
||||||
|
requested = false
|
||||||
} else restore()
|
} else restore()
|
||||||
refresh(true)
|
refresh(true)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user