fix: improve intent launch handling in EmulationFragment
All checks were successful
eden-license / license-header (pull_request) Successful in 37s

This commit is contained in:
Producdevity 2025-07-30 14:35:22 +02:00
parent dd6d6b4cf9
commit e8f63cf7ee

View file

@ -360,12 +360,18 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
Log.info("[EmulationFragment] Game setup complete for intent launch") Log.info("[EmulationFragment] Game setup complete for intent launch")
if (_binding != null) { if (_binding != null) {
// Hide loading indicator immediately for intent launches
binding.loadingIndicator.visibility = View.GONE
binding.surfaceEmulation.visibility = View.VISIBLE
completeViewSetup() completeViewSetup()
val driverReady = driverViewModel.isInteractionAllowed.value // For intent launches, check if surface is ready and start emulation
if (driverReady && !NativeLibrary.isRunning() && !NativeLibrary.isPaused()) { binding.root.post {
Log.info("[EmulationFragment] Starting emulation after async intent setup - driver ready") if (binding.surfaceEmulation.holder.surface?.isValid == true && !emulationStarted) {
startEmulation() emulationStarted = true
emulationState.newSurface(binding.surfaceEmulation.holder.surface)
}
} }
} }
} catch (e: Exception) { } catch (e: Exception) {
@ -769,20 +775,12 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
} }
driverViewModel.isInteractionAllowed.collect(viewLifecycleOwner) { driverViewModel.isInteractionAllowed.collect(viewLifecycleOwner) {
Log.info("[EmulationFragment] Driver interaction allowed: $it")
if (it && !NativeLibrary.isRunning() && !NativeLibrary.isPaused()) { if (it && !NativeLibrary.isRunning() && !NativeLibrary.isPaused()) {
startEmulation() startEmulation()
} }
} }
driverViewModel.onLaunchGame() driverViewModel.onLaunchGame()
val currentDriverState = driverViewModel.isInteractionAllowed.value
Log.info("[EmulationFragment] Checking initial driver state after onLaunchGame: $currentDriverState")
if (currentDriverState && !NativeLibrary.isRunning() && !NativeLibrary.isPaused()) {
Log.info("[EmulationFragment] Starting emulation immediately - driver already ready")
startEmulation()
}
} }
private fun startEmulation(programIndex: Int = 0) { private fun startEmulation(programIndex: Int = 0) {
@ -793,7 +791,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
updateScreenLayout() updateScreenLayout()
Log.info("[EmulationFragment] Calling emulationState.run() - surface will start emulation when available")
emulationState.run(emulationActivity!!.isActivityRecreated, programIndex) emulationState.run(emulationActivity!!.isActivityRecreated, programIndex)
} }
} }
@ -1261,11 +1258,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) { override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
Log.debug("[EmulationFragment] Surface changed. Resolution: " + width + "x" + height) Log.debug("[EmulationFragment] Surface changed. Resolution: " + width + "x" + height)
if (!emulationStarted) { if (!emulationStarted) {
Log.info("[EmulationFragment] Starting emulation")
emulationStarted = true emulationStarted = true
emulationState.newSurface(holder.surface) emulationState.newSurface(holder.surface)
} else { } else {
Log.debug("[EmulationFragment] Emulation already started, updating surface")
emulationState.newSurface(holder.surface) emulationState.newSurface(holder.surface)
} }
} }