mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix: Home screen setting keeps DroidDeck in RedMagic Game Space (#2083)
This commit is contained in:
1 parent
26274114a3
commit
d849e6ae0a
36 files changed
+108
-9
No files matched your search
@@ -321,11 +321,7 @@ class FrontEndActivity : ComponentActivity() {
|
||||
refreshWifiDiscovery()
|
||||
}
|
||||
SteamIntegration.Feature.BRIGHTNESS -> integrationSettings(SteamIntegration.brightnessSettings(this))
|
||||
SteamIntegration.Feature.HOME -> if (HomeApp.isDefault(this)) HomeApp.openSystemHomeSettings(this) else {
|
||||
HomeApp.setHomeScreenEnabled(this, true)
|
||||
refreshHomeAppState()
|
||||
manageHomeApp()
|
||||
}
|
||||
SteamIntegration.Feature.HOME -> if (HomeApp.isDefault(this)) HomeApp.openSystemHomeSettings(this) else offerHomeScreen()
|
||||
SteamIntegration.Feature.SHORTCUTS -> {
|
||||
if (!integrationState.shortcuts) shortcutsTried = true
|
||||
if (!HomeApp.isDefault(this)) configureIntegration(SteamIntegration.Feature.HOME)
|
||||
@@ -590,8 +586,17 @@ class FrontEndActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
private val homeRoleRequest = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
homeChoiceOpen = false
|
||||
HomeApp.releaseUnusedHomeEntry(this)
|
||||
refreshHomeAppState()
|
||||
}
|
||||
private val gameSpaceAdd = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
homeChoiceOpen = false
|
||||
if (HomeApp.inGameSpace(this)) enableHomeScreen()
|
||||
else refreshHomeAppState()
|
||||
}
|
||||
private var homeChoiceOpen = false
|
||||
private var gameSpaceOffered = false
|
||||
|
||||
override fun startActivity(intent: Intent?) {
|
||||
val compat = protons.protonBusyId != null || ProtonExtras.installInProgress
|
||||
@@ -1025,6 +1030,8 @@ class FrontEndActivity : ComponentActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
homeChoiceOpen = savedInstanceState?.getBoolean(STATE_HOME_CHOICE_OPEN) == true
|
||||
gameSpaceOffered = savedInstanceState?.getBoolean(STATE_GAME_SPACE_OFFERED) == true
|
||||
if (savedInstanceState == null) readIntegrationIntent(intent)
|
||||
readGameIntent(intent)
|
||||
gameSyncFolder = GameFileSync.folder(this)
|
||||
@@ -1390,8 +1397,11 @@ class FrontEndActivity : ComponentActivity() {
|
||||
integrationState = readIntegration()
|
||||
},
|
||||
onHomeScreen = { on ->
|
||||
HomeApp.setHomeScreenEnabled(this, on)
|
||||
refreshHomeAppState()
|
||||
if (on && HomeApp.hasGameSpace(this)) offerHomeScreen()
|
||||
else {
|
||||
HomeApp.setHomeScreenEnabled(this, on)
|
||||
refreshHomeAppState()
|
||||
}
|
||||
},
|
||||
onAndroidApp = { app, displayId -> launchAndroidApp(app, displayId) },
|
||||
onBackActionsInverted = { inverted ->
|
||||
@@ -1715,6 +1725,10 @@ class FrontEndActivity : ComponentActivity() {
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (!homeChoiceOpen) {
|
||||
HomeApp.releaseUnusedHomeEntry(this)
|
||||
refreshHomeAppState()
|
||||
}
|
||||
if (settingsMode == SessionService.MODE_STEAM) refreshFoundSteamLibraries()
|
||||
compatLaunchVisible = true
|
||||
com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(taskId, false)
|
||||
@@ -1791,6 +1805,8 @@ class FrontEndActivity : ComponentActivity() {
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putBoolean(STATE_HOME_CHOICE_OPEN, homeChoiceOpen)
|
||||
outState.putBoolean(STATE_GAME_SPACE_OFFERED, gameSpaceOffered)
|
||||
if (slowUsbNever) SessionPrefs.setSlowUsbWarningOff(this)
|
||||
saveCompatLaunch(outState)
|
||||
pendingSwitch?.let { outState.putParcelable(KEY_PENDING_SWITCH, it) }
|
||||
@@ -1810,7 +1826,13 @@ class FrontEndActivity : ComponentActivity() {
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
override fun onRestart() {
|
||||
super.onRestart()
|
||||
homeChoiceOpen = false
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
if (!homeChoiceOpen) HomeApp.releaseUnusedHomeEntry(this)
|
||||
unregisterReceiver(wifiLocationReceiver)
|
||||
unregisterReceiver(mediaReceiver)
|
||||
getSystemService(android.content.pm.LauncherApps::class.java).unregisterCallback(packageCallback)
|
||||
@@ -1890,12 +1912,32 @@ class FrontEndActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun offerHomeScreen() {
|
||||
if (!gameSpaceOffered && HomeApp.hasGameSpace(this) && !HomeApp.inGameSpace(this)) {
|
||||
gameSpaceOffered = true
|
||||
val opened = runCatching { gameSpaceAdd.launch(HomeApp.gameSpaceAddIntent()) }.isSuccess
|
||||
if (opened) {
|
||||
homeChoiceOpen = true
|
||||
android.widget.Toast.makeText(this, R.string.setup_home_game_space_first, android.widget.Toast.LENGTH_LONG).show()
|
||||
return
|
||||
}
|
||||
}
|
||||
enableHomeScreen()
|
||||
}
|
||||
|
||||
private fun enableHomeScreen() {
|
||||
HomeApp.setHomeScreenEnabled(this, true)
|
||||
refreshHomeAppState()
|
||||
manageHomeApp()
|
||||
}
|
||||
|
||||
private fun manageHomeApp() {
|
||||
homeChoiceOpen = true
|
||||
val request = HomeApp.roleRequestIntent(this)
|
||||
if (request != null) {
|
||||
homeRoleRequest.launch(request)
|
||||
} else {
|
||||
HomeApp.openSystemHomeSettings(this)
|
||||
} else if (runCatching { homeRoleRequest.launch(HomeApp.settingsIntent()) }.isFailure) {
|
||||
homeChoiceOpen = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2835,6 +2877,8 @@ class FrontEndActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val STATE_HOME_CHOICE_OPEN = "home_choice_open"
|
||||
private const val STATE_GAME_SPACE_OFFERED = "game_space_offered"
|
||||
private const val TAG = "MainActivity"
|
||||
private const val MEDIA_SETTLE_MS = 1500L
|
||||
private const val COMPONENT_RESTORE_MS = 60_000L
|
||||
|
||||
@@ -24,6 +24,9 @@ import kotlin.math.roundToInt
|
||||
|
||||
object HomeApp {
|
||||
private const val ICON_DP = 72
|
||||
private const val GAME_SPACE = "cn.nubia.gamelauncher"
|
||||
private const val GAME_SPACE_ADD = "cn.nubia.gamelauncher.action.GAME_MANAGER"
|
||||
private val GAME_SPACE_GAMES = Uri.parse("content://cn.nubia.gamelauncher.db.AppAddProvider/appadd")
|
||||
|
||||
data class LaunchableApp(
|
||||
val label: String,
|
||||
@@ -54,6 +57,24 @@ object HomeApp {
|
||||
)
|
||||
}
|
||||
|
||||
fun hasGameSpace(context: Context): Boolean =
|
||||
runCatching { context.packageManager.getPackageInfo(GAME_SPACE, 0) }.isSuccess
|
||||
|
||||
fun inGameSpace(context: Context): Boolean =
|
||||
runCatching {
|
||||
context.contentResolver.query(GAME_SPACE_GAMES, arrayOf("component"), null, null, null)?.use { rows ->
|
||||
val prefix = context.packageName + ","
|
||||
generateSequence { if (rows.moveToNext()) rows.getString(0) else null }.any { it.startsWith(prefix) }
|
||||
}
|
||||
}.getOrNull() ?: true
|
||||
|
||||
fun gameSpaceAddIntent(): Intent = Intent(GAME_SPACE_ADD).setPackage(GAME_SPACE)
|
||||
|
||||
fun releaseUnusedHomeEntry(context: Context) {
|
||||
if (isHomeScreenEnabled(context) && !isDefault(context) && hasGameSpace(context))
|
||||
setHomeScreenEnabled(context, false)
|
||||
}
|
||||
|
||||
fun isDefault(context: Context): Boolean {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
val roles = context.getSystemService(RoleManager::class.java)
|
||||
|
||||
Reference in new issue
Block a user