Feat/reset all settings (#696)

This commit is contained in:
0x1Nawaf authored and GitHub committed 2026-10-13 13:36:31 -04:00
1 parent 69e68a5008
commit 249ab44533
15 files changed
+323

No files matched your search

@@ -116,6 +116,7 @@ class MainActivity : ComponentActivity() {
private var frameGenLabel by mutableStateOf("")
private var lossless by mutableStateOf(Lossless.State.NONE)
private var showRemove by mutableStateOf(false)
private var showResetSettings by mutableStateOf(false)
private var showNonAdreno by mutableStateOf<LinuxRuntimeInstaller.Release?>(null)
private var glThread by mutableStateOf(true)
private var noGlError by mutableStateOf(true)
@@ -727,6 +728,10 @@ class MainActivity : ComponentActivity() {
}
}, "clear-logs").start()
},
onResetSettings = {
if (SessionState.running) android.widget.Toast.makeText(this, R.string.setup_reset_settings_session_running, android.widget.Toast.LENGTH_LONG).show()
else showResetSettings = true
},
onOffline = {
OfflineMode.setEnabled(this, !OfflineMode.enabled(this))
offline = OfflineMode.enabled(this)
@@ -872,6 +877,10 @@ class MainActivity : ComponentActivity() {
onConfirm = { showRemove = false; removeRuntime() },
onDismiss = { showRemove = false },
)
if (showResetSettings) com.droiddeck.launcher.ui.ResetSettingsDialog(
onConfirm = { gameProfiles -> resetSettings(gameProfiles) },
onDismiss = { showResetSettings = false },
)
flood?.let { f -> com.droiddeck.launcher.ui.LaunchFlood(f.from, onProgress = { floodProgress = it }) { launchFlooded(f) } }
returning?.let { r ->
com.droiddeck.launcher.ui.FloodReturn(androidx.compose.ui.graphics.Color(r.color), r.to, onProgress = { floodProgress = it }) {
@@ -1750,6 +1759,22 @@ class MainActivity : ComponentActivity() {
}
}
/** Setup's Reset all settings; the activity is recreated so every screen reads the defaults (and the language) again. */
private fun resetSettings(gameProfiles: Boolean) {
if (SessionState.running) return
val scopes = steamGames.map { it.profileKey }
Thread({
val ok = com.droiddeck.launcher.session.SettingsReset.resetAll(this, gameProfiles, scopes)
ui.post {
if (isDestroyed) return@post
com.droiddeck.launcher.core.AppLanguage.setChosen(this, com.droiddeck.launcher.core.AppLanguage.SYSTEM)
if (!ok) android.widget.Toast.makeText(this, R.string.setup_reset_settings_partial, android.widget.Toast.LENGTH_LONG).show()
com.droiddeck.launcher.ui.Motion.refresh(this)
recreate()
}
}, "reset-settings").start()
}
private fun removeRuntime() {
if (runtimeChangesBlocked()) return
val removal = LinuxRuntimeInstaller.beginUninstall(this) ?: return
@@ -0,0 +1,85 @@
package com.droiddeck.launcher.session
import android.content.Context
import android.util.Log
import com.droiddeck.launcher.core.GameEnvironment
import com.droiddeck.launcher.input.ControllerPrefs
import com.droiddeck.launcher.runtime.LinuxRuntime
/**
* Setup's "Reset all settings": every choice goes back to the default its getter falls back to.
*
* Only settings are removed. The "session" file also holds the library (added games' names, exes,
* appids and art picks), migration records, the drivers Auto installed, the storage and ROMs
* folders and the one-time permission prompts; those stay, as do store sign-ins, imported drivers
* and Lossless Scaling. Game profiles (each game's and the Default profile's environment
* overrides) are cleared only when asked for.
*/
object SettingsReset {
private const val TAG = "SettingsReset"
internal val SESSION_KEYS = setOf(
"orientation", "launcherFullscreen", "animations", "theme", "runSteamAtStartup", "addedGamesArt",
"gameStoresEnabled", "gameStoresSpeedTier", "gameStoresParallel", "storesOpenTab", "storesShowMature",
"hud", "hudDeck", "backActionsInverted", "touch", "osc", "shape", "steamController",
"gamepadLeft", "gamepadRight", "pipAutoEnter", "unfoldedControls", "stretch16x9",
"gpuDriverMode", "androidDriver", "linuxDriver", "linuxDriver.steam", "linuxDriver.desktop",
"tuSysmem", "glThread", "noGlError", "zinkLazy", "mangoapp", "gpuClockPin", "gamescopeRealtime",
"directAudio", "mic", "wifiDiscovery", "clientCpusOverride", "clientCpus", "gameCpus",
"noXalia", "fastSync", "fsyncFirst", "syncFallback", "prootNoSeccomp", "prootFastPath",
"guestHostname", "fexPreset", "forceSsbs", "logs", "storageDiagnostics",
"upscaler", "upscaleSharpness", "screenEffects", "textureAnisotropy", "textureLodBias",
"steamDownloadsInBackground", "steam_offline",
// Cleared so the Quest's one-time compatibility defaults are written again.
"questDefaultsV1",
)
/** Per-mode settings, stored as "<prefix><mode>". */
internal val SESSION_PREFIXES = listOf(
"resolutionCap.", "displayResolution.", "customRes.", "hdr.", "fpsLimit.", "suspendPolicy.",
)
private val STEAM_TOUCH_KEYS = listOf("feedback", "autoFade", "gyro", "shake")
internal fun isSessionSetting(key: String) = key in SESSION_KEYS || SESSION_PREFIXES.any { key.startsWith(it) }
/**
* Resets the settings, then per-game profiles when [gameProfiles] is set ([gameScopes] are the
* library's profile keys; scopes with saved overrides are found on their own). Blocking: call
* off the main thread. Returns false if a part could not be reset; the rest is still done.
* The language is not reset here: AppLanguage.setChosen changes the process locale, so the
* caller does that on the main thread.
*/
fun resetAll(context: Context, gameProfiles: Boolean, gameScopes: Collection<String> = emptyList()): Boolean {
var ok = true
val session = context.getSharedPreferences("session", Context.MODE_PRIVATE)
session.edit().apply { session.all.keys.filter { isSessionSetting(it) }.forEach { remove(it) } }.commit()
ControllerPrefs.resetAll(context)
context.getSharedPreferences("app-ui", Context.MODE_PRIVATE).edit().clear().commit()
context.getSharedPreferences("frame_gen", Context.MODE_PRIVATE).edit().clear().commit()
context.getSharedPreferences("steam_touch", Context.MODE_PRIVATE).edit()
.apply { STEAM_TOUCH_KEYS.forEach { remove(it) } }.commit()
com.droiddeck.launcher.agent.AgentAccess.setCommandsEnabled(context, false)
if (gameProfiles) {
val scopes = (gameScopes + runCatching { GameEnvironmentStore.read(context).games.keys }.getOrDefault(emptySet()) +
SessionPrefs.gameTextureFiltering(context).keys)
.filter { it.isNotEmpty() && GameEnvironment.validScope(it) }.toSet()
scopes.forEach { scope ->
runCatching { GameProfileManager.reset(context, scope) }
.onFailure { ok = false; Log.w(TAG, "Could not reset the profile of $scope", it) }
}
session.edit().remove("gameTextureFiltering").commit()
runCatching { GameEnvironmentStore.save(context, GameEnvironmentStore.read(context).copy(shared = emptyMap())) }
.onFailure { ok = false; Log.w(TAG, "Could not clear the Default profile's environment", it) }
}
QuestExperimental.initialize(context)
runCatching { OfflineMode.apply(context, LinuxRuntime.rootDir(context)) }
.onFailure { ok = false; Log.w(TAG, "Could not turn offline mode off", it) }
runCatching { GameEnvironmentStore.publish(context) }
.onFailure { ok = false; Log.w(TAG, "Could not update game environment", it) }
Log.i(TAG, "settings reset (game profiles: $gameProfiles, ok: $ok)")
return ok
}
}
@@ -205,6 +205,8 @@ class FrontEndActions(
val onAgentCommands: () -> Unit = {},
val onShareLogs: () -> Unit = {},
val onClearLogs: () -> Unit = {},
/** Setup's Reset all settings: asks first, then puts every setting back to its default. */
val onResetSettings: () -> Unit = {},
val onOffline: () -> Unit,
val onPageBack: () -> Unit = {},
val onTheme: (String) -> Unit = {},
@@ -405,6 +405,8 @@ internal fun SetupPanel(
ActionRow(stringResource(R.string.setup_latest_logs), stringResource(R.string.drawer_logs_hint), stringResource(R.string.drawer_share_logs), a.onShareLogs,
progress = com.droiddeck.launcher.session.SessionLogShare.progress)
ActionRow(stringResource(R.string.setup_saved_logs), stringResource(R.string.setup_saved_logs_hint, com.droiddeck.launcher.session.SessionPaths.KEEP_SESSIONS), stringResource(R.string.setup_clear_logs), a.onClearLogs)
ActionRow(stringResource(R.string.setup_reset_settings), stringResource(R.string.setup_reset_settings_hint),
stringResource(R.string.setup_reset_settings_button), a.onResetSettings)
}
}
}
@@ -2,17 +2,29 @@ package com.droiddeck.launcher.ui
import com.droiddeck.launcher.R
import androidx.compose.ui.res.stringResource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.selection.toggleable
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Checkbox
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp
import com.droiddeck.launcher.HomeApp
import com.droiddeck.launcher.input.SecondScreenDisplay
@@ -53,3 +65,32 @@ fun ConfirmDialog(title: String, text: String, confirm: String, onConfirm: () ->
dismissButton = { TextButton(onClick = onDismiss) { Text(stringResource(R.string.common_cancel)) } },
)
}
/** Setup's Reset all settings, with the choice to clear game profiles too (off unless ticked). */
@Composable
fun ResetSettingsDialog(onConfirm: (gameProfiles: Boolean) -> Unit, onDismiss: () -> Unit) {
var gameProfiles by remember { mutableStateOf(false) }
AlertDialog(
onDismissRequest = onDismiss,
title = { Text(stringResource(R.string.setup_reset_settings_title)) },
text = {
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
Text(stringResource(R.string.setup_reset_settings_body))
Row(
Modifier.fillMaxWidth().toggleable(gameProfiles, role = Role.Checkbox) { gameProfiles = it },
verticalAlignment = Alignment.CenterVertically,
) {
Checkbox(checked = gameProfiles, onCheckedChange = null)
Spacer(Modifier.width(8.dp))
Text(stringResource(R.string.setup_reset_settings_profiles), style = MaterialTheme.typography.bodyMedium)
}
}
},
confirmButton = {
TextButton(onClick = { onDismiss(); onConfirm(gameProfiles) }) {
Text(stringResource(R.string.setup_reset_settings_button), color = MaterialTheme.colorScheme.error)
}
},
dismissButton = { TextButton(onClick = onDismiss) { Text(stringResource(R.string.common_cancel)) } },
)
}