mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix: Steam no longer restarts every launch to import added games, and asks first (#1795)
This commit is contained in:
1 parent
ee3876b965
commit
23bb361006
40 files changed
+405
-7
No files matched your search
@@ -212,6 +212,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
private var gestureConfig = com.droiddeck.launcher.input.TouchGestureConfig()
|
||||
private var gestureGame: String? = null
|
||||
private var gestureSettingsOpen by mutableStateOf(false)
|
||||
private var steamImportAsk by mutableStateOf<com.droiddeck.launcher.session.SteamImportPrompt.Ask?>(null)
|
||||
private var steamImportAnswered: String? = null
|
||||
private var directHoldBehavior by mutableStateOf(com.droiddeck.launcher.input.TouchGestureConfig.MOUSE_BEHAVIOR_CLICK)
|
||||
private var screenKeyPickerOpen by mutableStateOf(false)
|
||||
private var screenKeyBind: List<Int>? = null
|
||||
@@ -902,6 +904,29 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
}
|
||||
}
|
||||
com.droiddeck.launcher.ui.GestureFeedback(recognizedGesture)
|
||||
LaunchedEffect(Unit) {
|
||||
val root = LinuxRuntime.rootDir(this@SessionActivity)
|
||||
while (true) {
|
||||
val ask = if (SessionState.running && SessionState.mode == SessionService.MODE_STEAM) {
|
||||
kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) { com.droiddeck.launcher.session.SteamImportPrompt.read(root) }
|
||||
} else null
|
||||
steamImportAsk = ask?.takeIf { it.token != steamImportAnswered }
|
||||
kotlinx.coroutines.delay(1500)
|
||||
}
|
||||
}
|
||||
steamImportAsk?.takeIf { !loading.visible }?.let { ask ->
|
||||
androidx.compose.runtime.key(ask.token) {
|
||||
com.droiddeck.launcher.ui.SteamImportDialog(ask.games) { now ->
|
||||
val root = LinuxRuntime.rootDir(this@SessionActivity)
|
||||
Thread({
|
||||
if (com.droiddeck.launcher.session.SteamImportPrompt.answer(root, ask.token, now)) runOnUiThread {
|
||||
steamImportAnswered = ask.token
|
||||
if (steamImportAsk?.token == ask.token) steamImportAsk = null
|
||||
}
|
||||
}, "steam-import-answer").start()
|
||||
}
|
||||
}
|
||||
}
|
||||
if (gestureSettingsOpen) com.droiddeck.launcher.ui.TouchGestureDialog(
|
||||
game = gestureGame,
|
||||
onDismiss = { gestureSettingsOpen = false },
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
|
||||
object SteamImportPrompt {
|
||||
data class Ask(val token: String, val games: List<String>)
|
||||
|
||||
private fun folder(root: File) = File(root, "root/.cache/droiddeck")
|
||||
|
||||
fun read(root: File): Ask? {
|
||||
val text = runCatching { File(folder(root), "steam-import.json").readText() }.getOrNull() ?: return null
|
||||
val json = runCatching { JSONObject(text) }.getOrNull() ?: return null
|
||||
val token = json.optString("token").takeIf { it.isNotEmpty() } ?: return null
|
||||
val list = json.optJSONArray("games")
|
||||
val games = if (list == null) emptyList() else (0 until list.length()).mapNotNull { list.optString(it).takeIf(String::isNotBlank) }
|
||||
return Ask(token, games)
|
||||
}
|
||||
|
||||
fun answer(root: File, token: String, now: Boolean): Boolean = runCatching {
|
||||
val dir = folder(root).apply { mkdirs() }
|
||||
val temp = File(dir, "steam-import.answer.tmp")
|
||||
temp.writeText(JSONObject().put("token", token).put("choice", if (now) "now" else "later").toString())
|
||||
temp.renameTo(File(dir, "steam-import.answer"))
|
||||
}.getOrDefault(false)
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.RestartAlt
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.droiddeck.launcher.R
|
||||
|
||||
@Composable
|
||||
internal fun SteamImportDialog(games: List<String>, onAnswer: (Boolean) -> Unit) {
|
||||
val now = remember { booleanArrayOf(false) }
|
||||
val shown = rememberShown { onAnswer(now[0]) }
|
||||
val close = { shown.targetState = false }
|
||||
val focus = remember { FocusRequester() }
|
||||
LaunchedEffect(Unit) { runCatching { focus.requestFocus() } }
|
||||
val names = if (games.size <= 3) games.joinToString(", ")
|
||||
else stringResource(R.string.steam_import_names_more, games.take(3).joinToString(", "), games.size - 3)
|
||||
AppDialog(shown, close, "steamImport", wide = false, maxWidth = 520.dp) {
|
||||
DialogTitleRow(stringResource(R.string.steam_import_title), close) {
|
||||
Icon(Icons.Filled.RestartAlt, null, tint = LocalPalette.current.signal, modifier = Modifier.size(20.dp))
|
||||
}
|
||||
Text(
|
||||
stringResource(R.string.steam_import_body, names),
|
||||
fontSize = 13.sp, lineHeight = 18.sp, color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp, androidx.compose.ui.Alignment.End), modifier = Modifier.fillMaxWidth()) {
|
||||
SecondaryButton(stringResource(R.string.steam_import_later)) { now[0] = false; close() }
|
||||
PrimaryButton(stringResource(R.string.steam_import_now), modifier = Modifier.focusRequester(focus), onClick = { now[0] = true; close() })
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user