mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix: keep the launcher from reclaiming focus when an app opens on the primary screen (#1797)
This commit is contained in:
1 parent
26e2f26ec9
commit
5736297987
2 files changed
+12
No files matched your search
@@ -1629,6 +1629,7 @@ class FrontEndActivity : ComponentActivity() {
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
compatLaunchVisible = true
|
||||
com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(taskId, false)
|
||||
orientation = SessionPrefs.orientation(this)
|
||||
launcherOrientation = com.droiddeck.launcher.core.AppUiPrefs.orientation(this)
|
||||
requestedOrientation = launcherOrientation
|
||||
@@ -1780,9 +1781,12 @@ class FrontEndActivity : ComponentActivity() {
|
||||
private fun launchPending(): Boolean = gameLinkReading || (pendingGameLink != null && !gameLinkTried)
|
||||
|
||||
private fun launchAndroidApp(app: HomeApp.LaunchableApp, displayId: Int?) {
|
||||
val onOwnScreen = displayId == null || displayId == (display?.displayId ?: Display.DEFAULT_DISPLAY)
|
||||
if (onOwnScreen) com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(taskId, true)
|
||||
try {
|
||||
HomeApp.launch(this, app, displayId)
|
||||
} catch (_: Exception) {
|
||||
com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(taskId, false)
|
||||
val label = secondScreenDisplays.firstOrNull { it.id == displayId }?.label
|
||||
val message = when {
|
||||
displayId == null || displayId == Display.DEFAULT_DISPLAY -> getString(R.string.android_app_open_failed_primary, app.label)
|
||||
|
||||
@@ -69,6 +69,7 @@ object DualScreenPanel {
|
||||
private var launching = false
|
||||
set(value) { field = value; available = value || activity != null }
|
||||
private var ownerTask = -1
|
||||
private var ownerYielded = false
|
||||
|
||||
var typing by mutableStateOf<TypingRequest?>(null)
|
||||
private set
|
||||
@@ -118,6 +119,7 @@ object DualScreenPanel {
|
||||
hide()
|
||||
displayId = display
|
||||
ownerTask = task
|
||||
ownerYielded = false
|
||||
launching = true
|
||||
val intent = Intent(context, DualScreenActivity::class.java)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK or Intent.FLAG_ACTIVITY_NO_ANIMATION)
|
||||
@@ -146,7 +148,13 @@ object DualScreenPanel {
|
||||
return true
|
||||
}
|
||||
|
||||
// The panel resumes when an app opens over the owner on the primary screen; pulling the owner back would hide that app.
|
||||
fun yieldTo(task: Int, app: Boolean) {
|
||||
if (ownerTask == task) ownerYielded = app
|
||||
}
|
||||
|
||||
internal fun returnFocus(context: Context) {
|
||||
if (ownerYielded) return
|
||||
val task = ownerTask.takeIf { it >= 0 } ?: return
|
||||
runCatching { (context.getSystemService(Context.ACTIVITY_SERVICE) as android.app.ActivityManager).moveTaskToFront(task, 0) }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user