refactor: simplify custom settings logic
All checks were successful
eden-license / license-header (pull_request) Successful in 15s
All checks were successful
eden-license / license-header (pull_request) Successful in 15s
This commit is contained in:
parent
f04565037f
commit
f68dbc6428
1 changed files with 44 additions and 33 deletions
|
@ -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,38 +187,35 @@ 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 ->
|
||||||
if (customConfigFile.exists()) {
|
val customConfigFile = SettingsFile.getCustomSettingsFile(gameInstance)
|
||||||
Log.info(
|
if (customConfigFile.exists()) {
|
||||||
"[EmulationFragment] Found existing custom settings for ${game!!.title}, loading them"
|
Log.info("[EmulationFragment] Found existing custom settings for ${gameInstance.title}, loading them")
|
||||||
)
|
SettingsFile.loadCustomConfig(gameInstance)
|
||||||
SettingsFile.loadCustomConfig(game!!)
|
} else {
|
||||||
} else {
|
Log.info("[EmulationFragment] No custom settings found for ${gameInstance.title}, using global settings")
|
||||||
Log.info(
|
NativeConfig.reloadGlobalConfig()
|
||||||
"[EmulationFragment] No custom settings found for ${game!!.title}, using global settings"
|
}
|
||||||
)
|
} ?: run {
|
||||||
NativeConfig.reloadGlobalConfig()
|
Log.info("[EmulationFragment] No game available, using global settings")
|
||||||
}
|
NativeConfig.reloadGlobalConfig()
|
||||||
} else {
|
|
||||||
val isCustomFromArgs = if (game != null && game == args.game) {
|
|
||||||
try {
|
|
||||||
args.custom
|
|
||||||
} catch (e: Exception) {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCustomFromArgs && game != null) {
|
// Normal game launch from arguments
|
||||||
SettingsFile.loadCustomConfig(game!!)
|
else -> {
|
||||||
Log.info("[EmulationFragment] Loading custom settings for ${game!!.title}")
|
val shouldUseCustom = game?.let { it == args.game && args.custom } ?: false
|
||||||
} else {
|
|
||||||
Log.info("[EmulationFragment] Using global settings")
|
if (shouldUseCustom) {
|
||||||
NativeConfig.reloadGlobalConfig()
|
SettingsFile.loadCustomConfig(game!!)
|
||||||
|
Log.info("[EmulationFragment] Loading custom settings for ${game!!.title}")
|
||||||
|
} else {
|
||||||
|
Log.info("[EmulationFragment] Using global settings")
|
||||||
|
NativeConfig.reloadGlobalConfig()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -228,9 +224,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||||
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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue