refactor: simplify custom settings logic
All checks were successful
eden-license / license-header (pull_request) Successful in 15s

This commit is contained in:
Producdevity 2025-08-03 14:49:58 +02:00
parent f04565037f
commit f68dbc6428

View file

@ -85,7 +85,6 @@ import org.yuzu.yuzu_emu.utils.CustomSettingsHandler
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlin.coroutines.resume import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine import kotlin.coroutines.suspendCoroutine
import java.io.File import java.io.File
@ -188,33 +187,29 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
} }
try { try {
if (isCustomSettingsIntent) { when {
Log.info("[EmulationFragment] Using custom settings from intent") // Game launched via intent (check for existing custom config)
} else if (intentGame != null && game != null) { intentGame != null -> {
val customConfigFile = SettingsFile.getCustomSettingsFile(game!!) game?.let { gameInstance ->
val customConfigFile = SettingsFile.getCustomSettingsFile(gameInstance)
if (customConfigFile.exists()) { if (customConfigFile.exists()) {
Log.info( Log.info("[EmulationFragment] Found existing custom settings for ${gameInstance.title}, loading them")
"[EmulationFragment] Found existing custom settings for ${game!!.title}, loading them" SettingsFile.loadCustomConfig(gameInstance)
)
SettingsFile.loadCustomConfig(game!!)
} else { } else {
Log.info( Log.info("[EmulationFragment] No custom settings found for ${gameInstance.title}, using global settings")
"[EmulationFragment] No custom settings found for ${game!!.title}, using global settings"
)
NativeConfig.reloadGlobalConfig() NativeConfig.reloadGlobalConfig()
} }
} else { } ?: run {
val isCustomFromArgs = if (game != null && game == args.game) { Log.info("[EmulationFragment] No game available, using global settings")
try { NativeConfig.reloadGlobalConfig()
args.custom
} catch (e: Exception) {
false
} }
} else {
false
} }
if (isCustomFromArgs && game != null) { // Normal game launch from arguments
else -> {
val shouldUseCustom = game?.let { it == args.game && args.custom } ?: false
if (shouldUseCustom) {
SettingsFile.loadCustomConfig(game!!) SettingsFile.loadCustomConfig(game!!)
Log.info("[EmulationFragment] Loading custom settings for ${game!!.title}") Log.info("[EmulationFragment] Loading custom settings for ${game!!.title}")
} else { } else {
@ -222,15 +217,14 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
NativeConfig.reloadGlobalConfig() NativeConfig.reloadGlobalConfig()
} }
} }
}
} catch (e: Exception) { } catch (e: Exception) {
Log.error("[EmulationFragment] Error loading configuration: ${e.message}") Log.error("[EmulationFragment] Error loading configuration: ${e.message}")
Log.info("[EmulationFragment] Falling back to global settings") Log.info("[EmulationFragment] Falling back to global settings")
try { try {
NativeConfig.reloadGlobalConfig() NativeConfig.reloadGlobalConfig()
} catch (fallbackException: Exception) { } catch (fallbackException: Exception) {
Log.error( Log.error("[EmulationFragment] Critical error: could not load global config: ${fallbackException.message}")
"[EmulationFragment] Critical error: could not load global config: ${fallbackException.message}"
)
throw fallbackException throw fallbackException
} }
} }
@ -1259,6 +1253,23 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
Log.debug("[EmulationFragment] Surface changed. Resolution: " + width + "x" + height) Log.debug("[EmulationFragment] Surface changed. Resolution: " + width + "x" + height)
if (!emulationStarted) { if (!emulationStarted) {
emulationStarted = true emulationStarted = true
// For intent launches, wait for driver initialization to complete
if (isCustomSettingsIntent || intentGame != null) {
if (!driverViewModel.isInteractionAllowed.value) {
Log.info("[EmulationFragment] Intent launch: waiting for driver initialization")
// Driver is still initializing, wait for it
lifecycleScope.launch {
driverViewModel.isInteractionAllowed.collect { allowed ->
if (allowed && holder.surface.isValid) {
emulationState.newSurface(holder.surface)
}
}
}
return
}
}
emulationState.newSurface(holder.surface) emulationState.newSurface(holder.surface)
} else { } else {
emulationState.newSurface(holder.surface) emulationState.newSurface(holder.surface)