mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-26 00:06:02 +00:00
fix(onboarding): a smoother first run, from the child-process setting to the Steam sign-in (#3114)
The child-process fix always uses the guided pairing flow, Finish setup opens the setting directly and queues the Steam launch, the Play button carries the first-run progress, the setup bar weighs each download by its real size, and the Steam client packages download over four connections and unpack one at a time under a flock.
This commit is contained in:
1 parent
46ec222fa5
commit
39debda0b0
67 files changed
+1151
-2078
No files matched your search
@@ -1255,6 +1255,10 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
drivers.restartBlocked = ::runtimeChangesBlocked
|
||||
drivers.loadTpUbwcMode()
|
||||
pendingSessionLogExport = savedInstanceState?.getString(KEY_PENDING_SESSION_LOG_EXPORT)?.let(::File)
|
||||
queuedLaunch.restore(
|
||||
savedInstanceState?.let { androidx.core.os.BundleCompat.getParcelable(it, STATE_PENDING_GATE_LAUNCH, Intent::class.java) },
|
||||
savedInstanceState?.getLong(STATE_PENDING_GATE_LAUNCH_AT, 0L) ?: 0L, System.currentTimeMillis(),
|
||||
)
|
||||
homeChoiceOpen = savedInstanceState?.getBoolean(STATE_HOME_CHOICE_OPEN) == true
|
||||
gameSpaceOffered = savedInstanceState?.getBoolean(STATE_GAME_SPACE_OFFERED) == true
|
||||
if (savedInstanceState == null) readIntegrationIntent(intent)
|
||||
@@ -1404,6 +1408,9 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
),
|
||||
FrontEndActions(
|
||||
onPlay = { playSteam() },
|
||||
onQueuePlaySteam = {
|
||||
queuedLaunch.queue(Intent(this, SessionActivity::class.java).putExtra(SessionActivity.EXTRA_STEAMVR, false), System.currentTimeMillis())
|
||||
},
|
||||
onPlaySteamVr = { playSteamVr() },
|
||||
onSteamUrl = { url ->
|
||||
if (!SessionState.running) startSession(
|
||||
@@ -1775,31 +1782,6 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
},
|
||||
onRefreshPhantomStatus = { refreshPhantomStatus() },
|
||||
onOpenDeveloperOptions = { displayId -> openDeveloperOptions(displayId) },
|
||||
onWirelessAdbPair = { host, port, code, complete ->
|
||||
Thread({
|
||||
val result = runCatching {
|
||||
kotlinx.coroutines.runBlocking { WirelessAdbFix.pair(this@FrontEndActivity, host, port, code) }
|
||||
}
|
||||
val error = result.exceptionOrNull()?.let { it.localizedMessage ?: getString(R.string.main_wadb_pair_failed) }
|
||||
ui.post { complete(error) }
|
||||
}, "wireless-adb-pair").start()
|
||||
},
|
||||
onFindWirelessAdbPort = { host, complete ->
|
||||
Thread({
|
||||
val port = WirelessAdbFix.findConnectPort(this@FrontEndActivity, host)
|
||||
ui.post { complete(port) }
|
||||
}, "wireless-adb-discovery").start()
|
||||
},
|
||||
onWirelessAdbApply = { host, port, enabled, complete ->
|
||||
Thread({
|
||||
val result = runCatching { WirelessAdbFix.setChildProcessLimit(this@FrontEndActivity, host, port, enabled) }
|
||||
val error = result.exceptionOrNull()?.let { it.localizedMessage ?: getString(R.string.main_wadb_command_failed) }
|
||||
ui.post {
|
||||
if (error == null) refreshPhantomStatus()
|
||||
complete(error)
|
||||
}
|
||||
}, "wireless-adb-fix").start()
|
||||
},
|
||||
onSetPhantomProcessLimit = { enabled, complete ->
|
||||
Thread({
|
||||
val result = runCatching { WirelessAdbFix.setUsingSavedPairing(this@FrontEndActivity, enabled) }
|
||||
@@ -1816,18 +1798,14 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
)
|
||||
android.widget.Toast.makeText(this, R.string.main_adb_copied, android.widget.Toast.LENGTH_SHORT).show()
|
||||
},
|
||||
onDismissPhantomGate = { showPhantomGate = false },
|
||||
onDismissPhantomGate = { queuedLaunch.clear(); showPhantomGate = false },
|
||||
onShowPhantomGate = {
|
||||
refreshPhantomStatus()
|
||||
showPhantomGate = true
|
||||
},
|
||||
onStartWirelessAdbPairing = { WirelessAdbPairingService.start(this) },
|
||||
onStartWirelessAdbPairing = { enabled -> WirelessAdbPairingService.start(this, enabled) },
|
||||
onStartPairingGuide = { displayId, toggleOnly -> PairingGuideActivity.start(this, displayId, toggleOnly) },
|
||||
onOpenNotificationSettings = {
|
||||
startActivity(Intent(android.provider.Settings.ACTION_APP_NOTIFICATION_SETTINGS)
|
||||
.putExtra(android.provider.Settings.EXTRA_APP_PACKAGE, packageName)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
},
|
||||
onEnsureNotifications = { done -> ensureNotifications(done) },
|
||||
updates = updates.actions(),
|
||||
controller = ControllerActions(
|
||||
onMapping = { showPerformance = false; showComponents = false; showMapping = true },
|
||||
@@ -2007,7 +1985,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
}
|
||||
|
||||
private fun startSteamSession(steamVr: Boolean = false) {
|
||||
startSession(Intent(this, SessionActivity::class.java).putExtra(SessionActivity.EXTRA_STEAMVR, steamVr), steamSession = true)
|
||||
startSession(Intent(this, SessionActivity::class.java).putExtra(SessionActivity.EXTRA_STEAMVR, steamVr), steamSession = true, queueIfBlocked = !steamVr)
|
||||
}
|
||||
|
||||
@Suppress("OVERRIDE_DEPRECATION")
|
||||
@@ -2230,6 +2208,10 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
outState.putBoolean(STATE_HOME_CHOICE_OPEN, homeChoiceOpen)
|
||||
outState.putBoolean(STATE_GAME_SPACE_OFFERED, gameSpaceOffered)
|
||||
pendingSessionLogExport?.let { outState.putString(KEY_PENDING_SESSION_LOG_EXPORT, it.absolutePath) }
|
||||
queuedLaunch.launch?.let {
|
||||
outState.putParcelable(STATE_PENDING_GATE_LAUNCH, it)
|
||||
outState.putLong(STATE_PENDING_GATE_LAUNCH_AT, queuedLaunch.queuedAt)
|
||||
}
|
||||
if (slowUsbNever) SessionPrefs.setSlowUsbWarningOff(this)
|
||||
saveCompatLaunch(outState)
|
||||
pendingSwitch?.let { outState.putParcelable(KEY_PENDING_SWITCH, it) }
|
||||
@@ -2256,6 +2238,8 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
// The queued launch was saved before this; a restored activity keeps its copy, and this one must not start it too.
|
||||
queuedLaunchRunner.destroy()
|
||||
triggerKeys.cancel()
|
||||
gameLaunchRequest.incrementAndGet()
|
||||
cancelCompatLaunch()
|
||||
@@ -3355,7 +3339,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
install(release)
|
||||
}
|
||||
|
||||
private fun startSession(intent: Intent, steamSession: Boolean = false): Boolean {
|
||||
private fun startSession(intent: Intent, steamSession: Boolean = false, queueIfBlocked: Boolean = false): Boolean {
|
||||
if (busy || LinuxRuntimeInstaller.isBusy()) return false
|
||||
if (SessionState.installing != null && !SessionState.running) {
|
||||
android.widget.Toast.makeText(this, R.string.main_wait_desktop_install, android.widget.Toast.LENGTH_SHORT).show()
|
||||
@@ -3367,6 +3351,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
}
|
||||
refreshPhantomStatus()
|
||||
if (steamSession && PhantomProcessLimit.blocksSteam(phantomProcessStatus)) {
|
||||
if (queueIfBlocked) queuedLaunch.queue(intent, System.currentTimeMillis())
|
||||
showPhantomGate = true
|
||||
return false
|
||||
}
|
||||
@@ -3376,8 +3361,64 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
return true
|
||||
}
|
||||
|
||||
private var notificationsDone: ((Boolean) -> Unit)? = null
|
||||
|
||||
private fun ensureNotifications(done: (Boolean) -> Unit) {
|
||||
if (WirelessAdbPairingService.notificationsEnabled(this)) {
|
||||
done(true)
|
||||
return
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 33 && checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
||||
notificationsDone = done
|
||||
requestPermissions(arrayOf(Manifest.permission.POST_NOTIFICATIONS), REQUEST_NOTIFICATIONS)
|
||||
return
|
||||
}
|
||||
openNotificationSettings()
|
||||
done(false)
|
||||
}
|
||||
|
||||
private fun openNotificationSettings() {
|
||||
android.widget.Toast.makeText(this, R.string.gate_notifications_toast, android.widget.Toast.LENGTH_LONG).show()
|
||||
val appAllowed = getSystemService(android.app.NotificationManager::class.java)?.areNotificationsEnabled() != false
|
||||
val intent = if (appAllowed && WirelessAdbPairingService.channelBlocked(this)) {
|
||||
Intent(android.provider.Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
|
||||
.putExtra(android.provider.Settings.EXTRA_CHANNEL_ID, WirelessAdbPairingService.channelId())
|
||||
} else {
|
||||
Intent(android.provider.Settings.ACTION_APP_NOTIFICATION_SETTINGS)
|
||||
}
|
||||
startActivity(intent.putExtra(android.provider.Settings.EXTRA_APP_PACKAGE, packageName).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
if (requestCode != REQUEST_NOTIFICATIONS) return
|
||||
val done = notificationsDone ?: return
|
||||
notificationsDone = null
|
||||
val granted = WirelessAdbPairingService.notificationsEnabled(this)
|
||||
if (!granted) openNotificationSettings()
|
||||
done(granted)
|
||||
}
|
||||
|
||||
private val queuedLaunch = com.droiddeck.launcher.session.QueuedLaunch<Intent>(GATE_LAUNCH_MS)
|
||||
private val queuedLaunchRunner = com.droiddeck.launcher.session.QueuedLaunchRunner(
|
||||
queue = queuedLaunch,
|
||||
now = System::currentTimeMillis,
|
||||
blocked = { PhantomProcessLimit.blocksSteam(phantomProcessStatus) },
|
||||
busy = ::steamStartBusy,
|
||||
schedule = { delay, task -> if (delay <= 0L) ui.post(task) else ui.postDelayed(task, delay) },
|
||||
unschedule = ui::removeCallbacks,
|
||||
start = { launch -> startSession(launch, steamSession = true, queueIfBlocked = true) },
|
||||
retryMs = GATE_LAUNCH_RETRY_MS,
|
||||
)
|
||||
|
||||
/** The conditions under which a Steam start waits instead of being refused: setup, a runtime or desktop install, or a storage cleanup. */
|
||||
private fun steamStartBusy(): Boolean = busy || LinuxRuntimeInstaller.isBusy() || com.droiddeck.launcher.session.Onboarding.settling() ||
|
||||
(SessionState.installing != null && !SessionState.running) || com.droiddeck.launcher.storage.StorageState.cleaning
|
||||
|
||||
private fun refreshPhantomStatus() {
|
||||
phantomProcessStatus = PhantomProcessLimit.read(this)
|
||||
if (queuedLaunch.launch != null && !PhantomProcessLimit.blocksSteam(phantomProcessStatus)) showPhantomGate = false
|
||||
queuedLaunchRunner.poke()
|
||||
adbPaired = WirelessAdbFix.hasSavedPairing(this)
|
||||
phantomWarning = if (PhantomProcessLimit.blocksSteam(phantomProcessStatus)) {
|
||||
getString(
|
||||
@@ -3389,7 +3430,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
|
||||
private fun openDeveloperOptions(displayId: Int?) {
|
||||
val highlight = if (PhantomProcessLimit.hasDeveloperToggle() &&
|
||||
WirelessAdbPairingService.stage.value == WirelessAdbPairingService.Stage.Idle) null else "toggle_adb_wireless"
|
||||
WirelessAdbPairingService.stage.value == WirelessAdbPairingService.Stage.Idle) "disable_phantom_process_monitor" else "toggle_adb_wireless"
|
||||
val intent = Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.apply { if (highlight != null) putExtra(":settings:fragment_args_key", highlight) }
|
||||
@@ -3508,7 +3549,12 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val REQUEST_NOTIFICATIONS = 7103
|
||||
private const val STATE_HOME_CHOICE_OPEN = "home_choice_open"
|
||||
private const val STATE_PENDING_GATE_LAUNCH = "pending_gate_launch"
|
||||
private const val STATE_PENDING_GATE_LAUNCH_AT = "pending_gate_launch_at"
|
||||
private const val GATE_LAUNCH_MS = 15 * 60_000L
|
||||
private const val GATE_LAUNCH_RETRY_MS = 2_000L
|
||||
private const val KEY_PENDING_SESSION_LOG_EXPORT = "pending_session_log_export"
|
||||
private const val STATE_GAME_SPACE_OFFERED = "game_space_offered"
|
||||
private const val TAG = "MainActivity"
|
||||
|
||||
@@ -93,6 +93,14 @@ class PairingGuideActivity : ComponentActivity() {
|
||||
launchPending = true
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
val stage = WirelessAdbPairingService.stage.value
|
||||
if (isFinishing && (stage is WirelessAdbPairingService.Stage.Waiting || stage is WirelessAdbPairingService.Stage.CodeNeeded)) {
|
||||
WirelessAdbPairingService.cancel(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (!launchPending) return
|
||||
|
||||
@@ -38,6 +38,8 @@ class WirelessAdbPairingService : Service() {
|
||||
private var pairingHost: String? = null
|
||||
private var pairingPort: Int? = null
|
||||
@Volatile private var working = false
|
||||
@Volatile private var limitEnabled = false
|
||||
@Volatile private var session = 0
|
||||
private val timeout = Runnable { finish(Stage.Failed(getString(R.string.adbpair_timed_out))) }
|
||||
|
||||
override fun onBind(intent: Intent?): IBinder? = null
|
||||
@@ -50,12 +52,15 @@ class WirelessAdbPairingService : Service() {
|
||||
onCode(code)
|
||||
}
|
||||
ACTION_CANCEL -> finish(Stage.Idle)
|
||||
else -> begin()
|
||||
else -> begin(intent?.getBooleanExtra(EXTRA_ENABLE_LIMIT, false) == true)
|
||||
}
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
private fun begin() {
|
||||
private fun begin(enableLimit: Boolean) {
|
||||
if (working) return
|
||||
session++
|
||||
limitEnabled = enableLimit
|
||||
pairingHost = null
|
||||
pairingPort = null
|
||||
working = false
|
||||
@@ -68,12 +73,13 @@ class WirelessAdbPairingService : Service() {
|
||||
|
||||
private fun startDiscovery() {
|
||||
stopDiscovery()
|
||||
val owner = session
|
||||
val manager = getSystemService(Context.NSD_SERVICE) as NsdManager
|
||||
val listener = object : NsdManager.DiscoveryListener {
|
||||
override fun onDiscoveryStarted(serviceType: String) = Unit
|
||||
override fun onServiceFound(serviceInfo: NsdServiceInfo) {
|
||||
if (serviceInfo.serviceType?.contains(PAIRING_TYPE) != true) return
|
||||
runCatching { manager.resolveService(serviceInfo, resolveListener()) }
|
||||
runCatching { manager.resolveService(serviceInfo, resolveListener(owner)) }
|
||||
}
|
||||
override fun onServiceLost(serviceInfo: NsdServiceInfo) = Unit
|
||||
override fun onDiscoveryStopped(serviceType: String) = Unit
|
||||
@@ -87,18 +93,20 @@ class WirelessAdbPairingService : Service() {
|
||||
.onFailure { finish(Stage.Failed(getString(R.string.adbpair_discovery_failed, it.localizedMessage.toString()))) }
|
||||
}
|
||||
|
||||
private fun resolveListener() = object : NsdManager.ResolveListener {
|
||||
private fun resolveListener(owner: Int): NsdManager.ResolveListener {
|
||||
return object : NsdManager.ResolveListener {
|
||||
override fun onResolveFailed(serviceInfo: NsdServiceInfo, errorCode: Int) = Unit
|
||||
override fun onServiceResolved(serviceInfo: NsdServiceInfo) {
|
||||
val address = serviceInfo.host ?: return
|
||||
if (!WirelessAdbFix.isLocalAddress(address)) return
|
||||
main.post {
|
||||
if (working || current.value == Stage.Done) return@post
|
||||
if (owner != session || working || current.value == Stage.Done) return@post
|
||||
pairingHost = address.hostAddress
|
||||
pairingPort = serviceInfo.port
|
||||
if (current.value !is Stage.CodeNeeded) show(Stage.CodeNeeded())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun onCode(code: String) {
|
||||
@@ -114,29 +122,34 @@ class WirelessAdbPairingService : Service() {
|
||||
return
|
||||
}
|
||||
working = true
|
||||
val owner = session
|
||||
val enable = limitEnabled
|
||||
show(Stage.Working(getString(R.string.adbpair_pairing)))
|
||||
Thread({
|
||||
val paired = runCatching { kotlinx.coroutines.runBlocking { WirelessAdbFix.pair(this@WirelessAdbPairingService, WirelessAdbFix.LOOPBACK, port, code) } }
|
||||
if (paired.isFailure) {
|
||||
main.post {
|
||||
working = false
|
||||
if (owner != session) return@post
|
||||
pairingPort = null
|
||||
show(Stage.CodeNeeded(getString(R.string.adbpair_code_rejected)))
|
||||
}
|
||||
return@Thread
|
||||
}
|
||||
main.post {
|
||||
if (owner != session) return@post
|
||||
stopDiscovery()
|
||||
show(Stage.Working(getString(R.string.adbpair_connecting)))
|
||||
}
|
||||
val result = runCatching {
|
||||
val connectPort = WirelessAdbFix.localConnectPort(this)
|
||||
?: error(getString(R.string.adbpair_port_not_found))
|
||||
main.post { show(Stage.Working(getString(R.string.adbpair_applying))) }
|
||||
WirelessAdbFix.setChildProcessLimit(this, WirelessAdbFix.LOOPBACK, connectPort, false)
|
||||
main.post { if (owner == session) show(Stage.Working(getString(R.string.adbpair_applying))) }
|
||||
WirelessAdbFix.setChildProcessLimit(this, WirelessAdbFix.LOOPBACK, connectPort, enable)
|
||||
}
|
||||
main.post {
|
||||
working = false
|
||||
if (owner != session) return@post
|
||||
finish(result.exceptionOrNull()?.let { Stage.Failed(it.localizedMessage ?: getString(R.string.adbpair_command_failed)) } ?: Stage.Done)
|
||||
}
|
||||
}, "wireless-adb-pairing").start()
|
||||
@@ -148,6 +161,7 @@ class WirelessAdbPairingService : Service() {
|
||||
}
|
||||
|
||||
private fun finish(stage: Stage) {
|
||||
session++
|
||||
main.removeCallbacks(timeout)
|
||||
stopDiscovery()
|
||||
publish(stage)
|
||||
@@ -248,6 +262,7 @@ class WirelessAdbPairingService : Service() {
|
||||
private const val ACTION_CODE = "com.droiddeck.launcher.action.WIRELESS_ADB_CODE"
|
||||
private const val ACTION_CANCEL = "com.droiddeck.launcher.action.WIRELESS_ADB_CANCEL"
|
||||
private const val KEY_CODE = "code"
|
||||
private const val EXTRA_ENABLE_LIMIT = "enable_limit"
|
||||
private const val TIMEOUT_MS = 5 * 60_000L
|
||||
|
||||
private val current = MutableStateFlow<Stage>(Stage.Idle)
|
||||
@@ -255,10 +270,10 @@ class WirelessAdbPairingService : Service() {
|
||||
|
||||
private fun publish(stage: Stage) { current.value = stage }
|
||||
|
||||
fun start(context: Context) {
|
||||
fun start(context: Context, enableLimit: Boolean = false) {
|
||||
context.getSystemService(NotificationManager::class.java)?.cancel(NOTIFICATION_ID)
|
||||
publish(Stage.Waiting)
|
||||
val intent = Intent(context, WirelessAdbPairingService::class.java)
|
||||
val intent = Intent(context, WirelessAdbPairingService::class.java).putExtra(EXTRA_ENABLE_LIMIT, enableLimit)
|
||||
if (Build.VERSION.SDK_INT >= 26) context.startForegroundService(intent) else context.startService(intent)
|
||||
}
|
||||
|
||||
@@ -271,6 +286,12 @@ class WirelessAdbPairingService : Service() {
|
||||
}
|
||||
|
||||
fun notificationsEnabled(context: Context): Boolean =
|
||||
context.getSystemService(NotificationManager::class.java)?.areNotificationsEnabled() != false
|
||||
context.getSystemService(NotificationManager::class.java)?.areNotificationsEnabled() != false && !channelBlocked(context)
|
||||
|
||||
/** The code is typed into a notification on this channel; a channel the user switched off leaves pairing with nothing to type into. */
|
||||
fun channelBlocked(context: Context): Boolean =
|
||||
context.getSystemService(NotificationManager::class.java)?.getNotificationChannel(CHANNEL_ID)?.importance == NotificationManager.IMPORTANCE_NONE
|
||||
|
||||
fun channelId(): String = CHANNEL_ID
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,15 @@ import java.io.RandomAccessFile
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
class LoadingState(context: Context, private val steam: Boolean = true) {
|
||||
var visible by mutableStateOf(true)
|
||||
private val prefs = context.getSharedPreferences("loading", Context.MODE_PRIVATE)
|
||||
private val firstRun = steam && !prefs.getBoolean(FIRST_DONE, false)
|
||||
private var shown by mutableStateOf(true)
|
||||
var visible: Boolean
|
||||
get() = shown
|
||||
set(value) {
|
||||
shown = value
|
||||
if (!value && steam) prefs.edit().putBoolean(FIRST_DONE, true).apply()
|
||||
}
|
||||
var step by mutableStateOf(context.getString(com.droiddeck.launcher.R.string.loadstate_starting))
|
||||
private set
|
||||
var topic by mutableStateOf(Topic.SESSION)
|
||||
@@ -33,7 +41,7 @@ class LoadingState(context: Context, private val steam: Boolean = true) {
|
||||
fun tick() {
|
||||
val seconds = (SystemClock.elapsedRealtime() - startedAt) / 1000
|
||||
elapsed = res.getString(com.droiddeck.launcher.R.string.loadstate_elapsed, seconds / 60, seconds % 60)
|
||||
hint = hints[((seconds / 8) % hints.size).toInt()]
|
||||
hint = if (firstRun) res.getString(com.droiddeck.launcher.R.string.loading_first_run) else hints[((seconds / 8) % hints.size).toInt()]
|
||||
}
|
||||
|
||||
fun say(line: String, topic: Topic, readable: Boolean) {
|
||||
@@ -126,6 +134,7 @@ class LoadingState(context: Context, private val steam: Boolean = true) {
|
||||
enum class Topic { RUNTIME, SESSION, DESKTOP, STEAM, STEAM_STARTING, OTHER }
|
||||
|
||||
companion object {
|
||||
private const val FIRST_DONE = "first_done"
|
||||
internal fun topicOf(scriptStep: String, steam: Boolean): Topic {
|
||||
val t = scriptStep.lowercase()
|
||||
return when {
|
||||
|
||||
@@ -26,8 +26,34 @@ object Onboarding {
|
||||
@Volatile private var appContext: Context? = null
|
||||
private var hold: (() -> Unit)? = null
|
||||
|
||||
/** The setup screens belong to the first run; later runtime, Proton and Steam client updates keep the usual Play button. */
|
||||
val firstRun = MutableStateFlow(true)
|
||||
|
||||
fun attach(context: Context) {
|
||||
appContext = context.applicationContext
|
||||
val prefs = context.applicationContext.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
var done = prefs.getBoolean(KEY_FIRST_RUN_DONE, false)
|
||||
if (!done && runCatching { installedAndReady(context) }.getOrDefault(false)) {
|
||||
done = true
|
||||
prefs.edit().putBoolean(KEY_FIRST_RUN_DONE, true).apply()
|
||||
}
|
||||
firstRun.value = !done
|
||||
}
|
||||
|
||||
/** Everything first run installs is in place, with the same Proton rule as [recheck]. */
|
||||
private fun installedAndReady(context: Context): Boolean {
|
||||
val own = ProtonExtras.tools.first { it.id == ProtonExtras.OWN }
|
||||
return LinuxRuntime.isInstalled(context) && !SteamClientPrefetch.pending(context) &&
|
||||
(ProtonExtras.declined(context) || ProtonExtras.installedAll(context, own).isNotEmpty())
|
||||
}
|
||||
|
||||
private const val PREFS = "onboarding"
|
||||
private const val KEY_FIRST_RUN_DONE = "first_run_done"
|
||||
|
||||
private fun markFirstRunDone() {
|
||||
val context = appContext ?: return
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().putBoolean(KEY_FIRST_RUN_DONE, true).apply()
|
||||
firstRun.value = false
|
||||
}
|
||||
|
||||
/** Keeps the process in the foreground, with one notification, while a step downloads and the runtime installer is not already doing so. */
|
||||
@@ -52,6 +78,15 @@ object Onboarding {
|
||||
proton = ProtonExtras.declined(context) || ProtonExtras.installedAll(context, own).isNotEmpty(),
|
||||
steam = runtime && !SteamClientPrefetch.pending(context),
|
||||
)
|
||||
settle()
|
||||
}
|
||||
|
||||
/** A new attempt starts from zero once everything is ready, whichever screen is showing. */
|
||||
@Synchronized fun settle() {
|
||||
if (!pending(rows(active.value, failed.value, facts.value))) {
|
||||
resetProgress()
|
||||
markFirstRunDone()
|
||||
}
|
||||
}
|
||||
|
||||
fun report(step: Step, label: String, percent: Int) {
|
||||
@@ -85,9 +120,29 @@ object Onboarding {
|
||||
|
||||
fun pending(rows: List<Row>): Boolean = rows.any { it.state != State.DONE }
|
||||
|
||||
/** The aggregate fraction of the whole first-run work, weighting each step by what it downloads. */
|
||||
fun overall(rows: List<Row>): Int {
|
||||
val weights = mapOf(Step.RUNTIME to 60, Step.PROTON to 15, Step.STEAM to 25)
|
||||
/** Whether first-run downloads are under way, as the home screen decides it. */
|
||||
fun settling(): Boolean = firstRun.value && active.value.isNotEmpty() && pending(rows(active.value, failed.value, facts.value))
|
||||
|
||||
@Volatile private var highWater = 0
|
||||
|
||||
@Synchronized internal fun resetProgress() { highWater = 0 }
|
||||
|
||||
/**
|
||||
* The aggregate fraction of the whole first-run work, weighting each step by what it downloads: about 290 MB, 630 MB and 1,050 MB.
|
||||
* Steps download first and install later, restarting their own percent, so the figure only moves forward until everything is done.
|
||||
*/
|
||||
@Synchronized fun overall(rows: List<Row>): Int {
|
||||
val measured = measure(rows)
|
||||
if (!pending(rows)) {
|
||||
highWater = 0
|
||||
return measured
|
||||
}
|
||||
highWater = maxOf(highWater, measured)
|
||||
return highWater
|
||||
}
|
||||
|
||||
internal fun measure(rows: List<Row>): Int {
|
||||
val weights = mapOf(Step.RUNTIME to 20, Step.PROTON to 30, Step.STEAM to 50)
|
||||
val total = weights.values.sum()
|
||||
val got = rows.sumOf { row ->
|
||||
val w = weights.getValue(row.step)
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
/** A launch the user asked for that waits for something else to finish first, and is forgotten if it waits too long. */
|
||||
class QueuedLaunch<T : Any>(private val lifetimeMs: Long = 15 * 60_000L) {
|
||||
var launch: T? = null
|
||||
private set
|
||||
var queuedAt: Long = 0L
|
||||
private set
|
||||
|
||||
fun queue(launch: T, now: Long) {
|
||||
this.launch = launch
|
||||
queuedAt = now
|
||||
}
|
||||
|
||||
/** Takes back a saved launch with the time it was first queued; one without a valid time or past its lifetime is dropped. */
|
||||
fun restore(launch: T?, queuedAt: Long, now: Long) {
|
||||
if (launch != null && fresh(queuedAt, now)) {
|
||||
this.launch = launch
|
||||
this.queuedAt = queuedAt
|
||||
} else {
|
||||
clear()
|
||||
}
|
||||
}
|
||||
|
||||
/** The launch if it is still wanted; an expired one is cleared. */
|
||||
fun current(now: Long): T? {
|
||||
val queued = launch ?: return null
|
||||
if (fresh(queuedAt, now)) return queued
|
||||
clear()
|
||||
return null
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
launch = null
|
||||
}
|
||||
|
||||
private fun fresh(queuedAt: Long, now: Long) = now - queuedAt in 0..lifetimeMs
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
/**
|
||||
* Starts a queued launch once nothing stands in its way and retries until it can or it expires. One runner belongs to one
|
||||
* activity: destroying it clears its queue and cancels its retry, so a restored activity is the only one that starts the launch.
|
||||
*/
|
||||
class QueuedLaunchRunner<T : Any>(
|
||||
private val queue: QueuedLaunch<T>,
|
||||
private val now: () -> Long,
|
||||
private val blocked: () -> Boolean,
|
||||
private val busy: () -> Boolean,
|
||||
private val schedule: (delayMs: Long, task: Runnable) -> Unit,
|
||||
private val unschedule: (Runnable) -> Unit,
|
||||
private val start: (T) -> Unit,
|
||||
private val retryMs: Long = 2_000L,
|
||||
) {
|
||||
private var posted = false
|
||||
private var retry: Runnable? = null
|
||||
private var destroyed = false
|
||||
|
||||
/** Call whenever the blocking setting may have changed. */
|
||||
fun poke() {
|
||||
if (destroyed || posted) return
|
||||
val launch = queue.current(now()) ?: return
|
||||
if (blocked()) return
|
||||
posted = true
|
||||
schedule(0L, Runnable {
|
||||
posted = false
|
||||
attempt(launch)
|
||||
})
|
||||
}
|
||||
|
||||
private fun attempt(launch: T) {
|
||||
if (destroyed || queue.current(now()) !== launch) return
|
||||
if (busy()) {
|
||||
val again = Runnable { if (!destroyed && queue.launch === launch) poke() }
|
||||
retry = again
|
||||
schedule(retryMs, again)
|
||||
return
|
||||
}
|
||||
queue.clear()
|
||||
start(launch)
|
||||
}
|
||||
|
||||
fun destroy() {
|
||||
destroyed = true
|
||||
queue.clear()
|
||||
retry?.let(unschedule)
|
||||
retry = null
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,7 @@ object SteamClientPrefetch {
|
||||
else Onboarding.fail(Onboarding.Step.STEAM, problem ?: failedLabel)
|
||||
val steamReady = !pending(app)
|
||||
Onboarding.facts.update { it.copy(steam = steamReady) }
|
||||
Onboarding.settle()
|
||||
}, "steam-client-prefetch").also { it.start() }
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,239 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import com.droiddeck.launcher.R
|
||||
import android.text.Editable
|
||||
import android.text.InputType
|
||||
import android.text.TextWatcher
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.EditText
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.TextRange
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.ImeOptions
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import kotlin.math.min
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@Composable
|
||||
internal fun AdbTextField(
|
||||
value: String,
|
||||
onValueChange: (String) -> Unit,
|
||||
label: String,
|
||||
keyboardType: KeyboardType,
|
||||
imeAction: ImeAction,
|
||||
modifier: Modifier = Modifier,
|
||||
placeholder: String? = null,
|
||||
compact: Boolean = false,
|
||||
onFocusChange: (Boolean) -> Unit = {},
|
||||
clearFocus: Boolean = false,
|
||||
onNext: (() -> Unit)? = null,
|
||||
onDone: (() -> Unit)? = null,
|
||||
focusOnShow: Boolean = false,
|
||||
showLabel: Boolean = true,
|
||||
focusAtTap: Int? = null,
|
||||
onBack: (() -> Unit)? = null,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val onBackLatest = rememberUpdatedState(onBack)
|
||||
val focusAsked = remember { booleanArrayOf(false) }
|
||||
val focusTapAsked = remember { arrayOfNulls<Int>(1) }
|
||||
val palette = LocalPalette.current
|
||||
val onValueChangeLatest = rememberUpdatedState(onValueChange)
|
||||
val onNextLatest = rememberUpdatedState(onNext)
|
||||
val onDoneLatest = rememberUpdatedState(onDone)
|
||||
val onFocusChangeLatest = rememberUpdatedState(onFocusChange)
|
||||
var focused by remember { mutableStateOf(false) }
|
||||
val shape = RoundedCornerShape(8.dp)
|
||||
val inputHeight = if (compact) 44.dp else 52.dp
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val bottomTyping = LocalBottomTyping.current
|
||||
val bottomTypingLatest = rememberUpdatedState(bottomTyping)
|
||||
val typingRequest = remember { arrayOfNulls<TypingRequest>(1) }
|
||||
|
||||
fun typeOnBottom(editText: EditText): Boolean {
|
||||
if (!bottomTypingLatest.value || !DualScreenPanel.attached) return false
|
||||
val text = editText.text.toString()
|
||||
lateinit var request: TypingRequest
|
||||
request = TypingRequest(
|
||||
TextFieldValue(text, TextRange(editText.selectionStart.coerceIn(0, text.length), editText.selectionEnd.coerceIn(0, text.length))),
|
||||
ImeOptions(singleLine = true, keyboardType = keyboardType, imeAction = imeAction),
|
||||
{ next ->
|
||||
if (editText.text.toString() != next.text) editText.setText(next.text)
|
||||
editText.setSelection(next.selection.start.coerceIn(0, next.text.length), next.selection.end.coerceIn(0, next.text.length))
|
||||
},
|
||||
{ action -> editText.onEditorAction(imeActionFlag(action)) },
|
||||
{ editText.post { if (typingRequest[0] === request) onBackLatest.value?.invoke() ?: editText.clearFocus() } },
|
||||
)
|
||||
typingRequest[0] = request
|
||||
DualScreenPanel.startTyping(request)
|
||||
return true
|
||||
}
|
||||
|
||||
DisposableEffect(Unit) {
|
||||
onDispose { typingRequest[0]?.let { DualScreenPanel.stopTyping(it) } }
|
||||
}
|
||||
|
||||
Column(modifier = modifier.fillMaxWidth()) {
|
||||
if (showLabel) Text(
|
||||
label,
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = colors.onSurfaceVariant,
|
||||
maxLines = 1,
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(inputHeight)
|
||||
.background(colors.surfaceVariant, shape)
|
||||
.glideBorder(focused, shape, palette.signal, palette.line2)
|
||||
.padding(horizontal = 10.dp),
|
||||
contentAlignment = Alignment.CenterStart,
|
||||
) {
|
||||
AndroidView(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
factory = { viewContext ->
|
||||
EditText(viewContext).apply {
|
||||
isSingleLine = true
|
||||
setHorizontallyScrolling(true)
|
||||
background = null
|
||||
setPadding((2 * context.resources.displayMetrics.density).roundToInt(), 0, 0, 0)
|
||||
setTextSize(android.util.TypedValue.COMPLEX_UNIT_SP, if (compact) 13f else 14f)
|
||||
setTextColor(colors.onBackground.toArgb())
|
||||
setHintTextColor(colors.onSurfaceVariant.toArgb())
|
||||
contentDescription = label
|
||||
inputType = if (keyboardType == KeyboardType.Number) {
|
||||
InputType.TYPE_CLASS_NUMBER
|
||||
} else {
|
||||
InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_URI or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
|
||||
}
|
||||
imeOptions = imeActionFlag(imeAction) or EditorInfo.IME_FLAG_NO_FULLSCREEN or EditorInfo.IME_FLAG_NO_EXTRACT_UI
|
||||
hint = placeholder
|
||||
setOnEditorActionListener { _, actionId, event ->
|
||||
val isEnter = event?.keyCode == android.view.KeyEvent.KEYCODE_ENTER
|
||||
when {
|
||||
imeAction == ImeAction.Next && (actionId == EditorInfo.IME_ACTION_NEXT || isEnter) -> {
|
||||
onNextLatest.value?.invoke()
|
||||
true
|
||||
}
|
||||
imeAction == ImeAction.Done && (actionId == EditorInfo.IME_ACTION_DONE || isEnter) -> {
|
||||
onDoneLatest.value?.invoke()
|
||||
true
|
||||
}
|
||||
// Search and Go are terminal: leaving them unhandled
|
||||
// keeps focus in the field, so the keyboard would stay
|
||||
// up over the results it was used to find.
|
||||
imeAction in setOf(ImeAction.Search, ImeAction.Go) &&
|
||||
(actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_GO || isEnter) -> {
|
||||
onDoneLatest.value?.invoke()
|
||||
post {
|
||||
clearFocus()
|
||||
(context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE)
|
||||
as? android.view.inputmethod.InputMethodManager)
|
||||
?.hideSoftInputFromWindow(windowToken, 0)
|
||||
}
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
showSoftInputOnFocus = !bottomTyping
|
||||
// B on a controller puts the keyboard away first; with no keyboard up it goes back as usual.
|
||||
var hidingKeyboard = false
|
||||
setOnKeyListener { view, keyCode, event ->
|
||||
if (keyCode != android.view.KeyEvent.KEYCODE_BUTTON_B) return@setOnKeyListener false
|
||||
if (event.action == android.view.KeyEvent.ACTION_DOWN && event.repeatCount == 0) {
|
||||
hidingKeyboard = androidx.core.view.ViewCompat.getRootWindowInsets(view)
|
||||
?.isVisible(androidx.core.view.WindowInsetsCompat.Type.ime()) == true
|
||||
if (hidingKeyboard) (view.context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager)
|
||||
?.hideSoftInputFromWindow(view.windowToken, 0)
|
||||
onBackLatest.value?.let { hidingKeyboard = true; it() }
|
||||
}
|
||||
hidingKeyboard
|
||||
}
|
||||
setOnClickListener { if (hasFocus() && !typeOnBottom(this) && bottomTypingLatest.value) showKeyboardHere(this) }
|
||||
setOnFocusChangeListener { _, hasFocus ->
|
||||
focused = hasFocus
|
||||
if (hasFocus) { if (!typeOnBottom(this) && bottomTypingLatest.value) showKeyboardHere(this) }
|
||||
else typingRequest[0]?.let { DualScreenPanel.stopTyping(it) }
|
||||
onFocusChangeLatest.value(hasFocus)
|
||||
}
|
||||
addTextChangedListener(object : TextWatcher {
|
||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) = Unit
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) = Unit
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
onValueChangeLatest.value(s?.toString().orEmpty())
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
update = { editText ->
|
||||
editText.showSoftInputOnFocus = !bottomTyping
|
||||
// A new tap may ask again: a field still on screen while it closes can be opened once more.
|
||||
val fresh = if (focusAtTap != null) focusTapAsked[0] != focusAtTap else !focusAsked[0]
|
||||
if (focusOnShow && fresh) {
|
||||
if (focusAtTap != null) focusTapAsked[0] = focusAtTap else focusAsked[0] = true
|
||||
editText.post {
|
||||
if (focusAtTap != null && focusAtTap != ScreenTaps.count) return@post
|
||||
editText.requestFocus()
|
||||
if (!bottomTypingLatest.value) (editText.context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager)
|
||||
?.showSoftInput(editText, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
}
|
||||
if (clearFocus && editText.hasFocus()) {
|
||||
editText.clearFocus()
|
||||
(editText.context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager)
|
||||
?.hideSoftInputFromWindow(editText.windowToken, 0)
|
||||
}
|
||||
editText.setTextColor(colors.onBackground.toArgb())
|
||||
editText.setHintTextColor(colors.onSurfaceVariant.toArgb())
|
||||
editText.hint = placeholder
|
||||
editText.contentDescription = label
|
||||
if (editText.text.toString() != value) {
|
||||
val cursor = if (editText.hasFocus()) editText.selectionStart.coerceAtLeast(0) else value.length
|
||||
editText.setText(value)
|
||||
editText.setSelection(min(cursor, value.length))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun showKeyboardHere(editText: EditText) {
|
||||
(editText.context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager)
|
||||
?.showSoftInput(editText, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
|
||||
private fun imeActionFlag(action: ImeAction): Int = when (action) {
|
||||
ImeAction.Next -> EditorInfo.IME_ACTION_NEXT
|
||||
ImeAction.Done -> EditorInfo.IME_ACTION_DONE
|
||||
ImeAction.Go -> EditorInfo.IME_ACTION_GO
|
||||
ImeAction.Search -> EditorInfo.IME_ACTION_SEARCH
|
||||
else -> EditorInfo.IME_ACTION_UNSPECIFIED
|
||||
}
|
||||
@@ -314,16 +314,14 @@ class FrontEndActions(
|
||||
val onBackActionsInverted: (Boolean) -> Unit = {},
|
||||
val onRefreshPhantomStatus: () -> Unit = {},
|
||||
val onOpenDeveloperOptions: (Int?) -> Unit = {},
|
||||
val onWirelessAdbPair: (String, Int, String, (String?) -> Unit) -> Unit,
|
||||
val onFindWirelessAdbPort: (String, (Int?) -> Unit) -> Unit = { _, done -> done(null) },
|
||||
val onWirelessAdbApply: (String, Int, Boolean, (String?) -> Unit) -> Unit,
|
||||
val onSetPhantomProcessLimit: (Boolean, (String?) -> Unit) -> Unit,
|
||||
val onCopyPhantomCommand: (Boolean) -> Unit = {},
|
||||
val onDismissPhantomGate: () -> Unit = {},
|
||||
val onStartWirelessAdbPairing: () -> Unit = {},
|
||||
val onStartWirelessAdbPairing: (Boolean) -> Unit = {},
|
||||
val onStartPairingGuide: (Int?, Boolean) -> Boolean = { _, _ -> false },
|
||||
val onShowPhantomGate: () -> Unit = {},
|
||||
val onOpenNotificationSettings: () -> Unit = {},
|
||||
val onQueuePlaySteam: () -> Unit = {},
|
||||
val onEnsureNotifications: ((Boolean) -> Unit) -> Unit = { it(true) },
|
||||
val controller: ControllerActions? = null,
|
||||
val updates: UpdatesActions = UpdatesActions(),
|
||||
)
|
||||
@@ -509,17 +507,16 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
LaunchedEffect(com.droiddeck.launcher.stores.StoresState.openGameRequest) {
|
||||
if (com.droiddeck.launcher.stores.StoresState.openGameRequest != null) selected = "stores"
|
||||
}
|
||||
var showWirelessAdbFix by rememberSaveable { mutableStateOf(false) }
|
||||
var showDeveloperDisplayChoice by rememberSaveable { mutableStateOf(false) }
|
||||
var developerChoiceGuided by rememberSaveable { mutableStateOf(false) }
|
||||
var developerChoiceToggle by rememberSaveable { mutableStateOf(false) }
|
||||
var wirelessAdbDesiredEnabled by rememberSaveable { mutableStateOf(false) }
|
||||
var guidedLimitEnabled by rememberSaveable { mutableStateOf(false) }
|
||||
var appToChooseDisplay by remember { mutableStateOf<HomeApp.LaunchableApp?>(null) }
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val ctx = LocalContext.current
|
||||
val phantomGateVisible = s.showPhantomGate && PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)
|
||||
val processSettingsPageVisible = phantomGateVisible || showWirelessAdbFix || showDeveloperDisplayChoice
|
||||
val processSettingsPageVisible = phantomGateVisible || showDeveloperDisplayChoice
|
||||
val requestDeveloperOptions = {
|
||||
developerChoiceGuided = false
|
||||
developerChoiceToggle = false
|
||||
@@ -527,7 +524,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
else showDeveloperDisplayChoice = true
|
||||
}
|
||||
val openDeveloperOptionsOn: (Int?) -> Unit = { displayId ->
|
||||
if (developerChoiceGuided) a.onStartWirelessAdbPairing()
|
||||
if (developerChoiceGuided) a.onStartWirelessAdbPairing(guidedLimitEnabled)
|
||||
val guided = developerChoiceGuided || developerChoiceToggle
|
||||
if (!guided || !a.onStartPairingGuide(displayId, developerChoiceToggle)) a.onOpenDeveloperOptions(displayId)
|
||||
developerChoiceGuided = false
|
||||
@@ -543,31 +540,35 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
else showDeveloperDisplayChoice = true
|
||||
}
|
||||
}
|
||||
val startGuidedPairing = {
|
||||
if (!com.droiddeck.launcher.core.WirelessAdbPairingService.notificationsEnabled(ctx)) {
|
||||
wirelessAdbDesiredEnabled = false
|
||||
showWirelessAdbFix = true
|
||||
} else {
|
||||
developerChoiceGuided = true
|
||||
if (s.secondScreenDisplays.isEmpty()) openDeveloperOptionsOn(null)
|
||||
else showDeveloperDisplayChoice = true
|
||||
val startGuidedPairing: (Boolean) -> Unit = { enabled ->
|
||||
a.onEnsureNotifications { granted ->
|
||||
if (granted) {
|
||||
guidedLimitEnabled = enabled
|
||||
developerChoiceGuided = true
|
||||
if (s.secondScreenDisplays.isEmpty()) openDeveloperOptionsOn(null)
|
||||
else showDeveloperDisplayChoice = true
|
||||
}
|
||||
}
|
||||
}
|
||||
val childProcessRequest = androidx.compose.runtime.rememberUpdatedState {
|
||||
if (PhantomProcessLimit.hasDeveloperToggle()) requestChildProcessToggle() else a.onShowPhantomGate()
|
||||
}
|
||||
DisposableEffect(Unit) {
|
||||
val handler: () -> Unit = { childProcessRequest.value() }
|
||||
ChildProcessSetup.request = handler
|
||||
onDispose { if (ChildProcessSetup.request === handler) ChildProcessSetup.request = null }
|
||||
}
|
||||
var applyingSavedPairing by remember { mutableStateOf(false) }
|
||||
val fixPhantomLimit = {
|
||||
if (!s.adbPaired || !com.droiddeck.launcher.core.GlobalSettings.wirelessDebuggingOn(ctx)) startGuidedPairing()
|
||||
if (!s.adbPaired || !com.droiddeck.launcher.core.GlobalSettings.wirelessDebuggingOn(ctx)) startGuidedPairing(false)
|
||||
else if (!applyingSavedPairing) {
|
||||
applyingSavedPairing = true
|
||||
a.onSetPhantomProcessLimit(false) { error ->
|
||||
applyingSavedPairing = false
|
||||
if (error != null) startGuidedPairing()
|
||||
if (error != null) startGuidedPairing(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
val requestWirelessAdbFix: (Boolean) -> Unit = { enabled ->
|
||||
wirelessAdbDesiredEnabled = enabled
|
||||
showWirelessAdbFix = true
|
||||
}
|
||||
LaunchedEffect(s.showPhantomGate, s.phantomProcessStatus) {
|
||||
if (phantomGateVisible) {
|
||||
while (true) {
|
||||
@@ -807,8 +808,8 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
else appToChooseDisplay = app
|
||||
},
|
||||
onOpenDeveloperOptions = requestChildProcessToggle,
|
||||
onRequestWirelessAdb = requestWirelessAdbFix,
|
||||
onPairWirelessDebugging = startGuidedPairing,
|
||||
onPairWirelessDebugging = { startGuidedPairing(false) },
|
||||
onRequestWirelessAdb = startGuidedPairing,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -839,7 +840,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
onDismiss = { appToChooseDisplay = null },
|
||||
)
|
||||
}
|
||||
if (phantomGateVisible && !showWirelessAdbFix) {
|
||||
if (phantomGateVisible) {
|
||||
Box(Modifier.fillMaxSize().background(colors.background)) {
|
||||
PhantomProcessGatePage(
|
||||
status = s.phantomProcessStatus,
|
||||
@@ -847,21 +848,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
onOpenDeveloperOptions = requestChildProcessToggle,
|
||||
applyingSavedPairing = applyingSavedPairing,
|
||||
onFixWithWirelessDebugging = fixPhantomLimit,
|
||||
onEnterAddressManually = { requestWirelessAdbFix(false) },
|
||||
onCopyCommand = { a.onCopyPhantomCommand(false) },
|
||||
onOpenNotificationSettings = a.onOpenNotificationSettings,
|
||||
)
|
||||
}
|
||||
}
|
||||
if (showWirelessAdbFix) {
|
||||
Box(Modifier.fillMaxSize().background(colors.background)) {
|
||||
WirelessAdbFixPage(
|
||||
onBack = { showWirelessAdbFix = false },
|
||||
desiredEnabled = wirelessAdbDesiredEnabled,
|
||||
onOpenDeveloperOptions = requestDeveloperOptions,
|
||||
onPair = a.onWirelessAdbPair,
|
||||
onFindConnectPort = a.onFindWirelessAdbPort,
|
||||
onApply = a.onWirelessAdbApply,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -907,6 +894,10 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
}
|
||||
}
|
||||
|
||||
internal object ChildProcessSetup {
|
||||
@Volatile var request: (() -> Unit)? = null
|
||||
}
|
||||
|
||||
internal object MainTabSteps {
|
||||
@Volatile var handler: ((Int) -> Unit)? = null
|
||||
}
|
||||
@@ -1282,7 +1282,8 @@ internal fun OnboardingCard(limitBlocks: Boolean = false, onSetUpLimit: () -> Un
|
||||
val failed by com.droiddeck.launcher.session.Onboarding.failed.collectAsState()
|
||||
val facts by com.droiddeck.launcher.session.Onboarding.facts.collectAsState()
|
||||
val rows = com.droiddeck.launcher.session.Onboarding.rows(active, failed, facts)
|
||||
val settling = com.droiddeck.launcher.session.Onboarding.pending(rows)
|
||||
val firstRun by com.droiddeck.launcher.session.Onboarding.firstRun.collectAsState()
|
||||
val settling = firstRun && com.droiddeck.launcher.session.Onboarding.pending(rows)
|
||||
if (!settling) return
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
|
||||
@@ -205,10 +205,12 @@ internal fun PrimaryButton(
|
||||
large: Boolean = false,
|
||||
icon: ImageVector? = null,
|
||||
fill: Boolean = false,
|
||||
progress: Float? = null,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val shownProgress by animateFloatAsState(progress?.coerceIn(0f, 1f) ?: 0f, Motion.tw(300), label = "btnProgress")
|
||||
val pillMode = LocalPillButtons.current
|
||||
val btnShape = if (pillMode) CircleShape else Shape12
|
||||
val outlined = LocalGradientOutline.current && enabled
|
||||
@@ -234,6 +236,11 @@ internal fun PrimaryButton(
|
||||
.graphicsLayer { alpha = if (LaunchOrigin.flooding === placed) 0f else 1f; scaleX = scale; scaleY = scale; shadowElevation = if (enabled) lift.dp.toPx() else 0f; shape = btnShape; clip = false; ambientShadowColor = pal.signal; spotShadowColor = pal.signal }
|
||||
.clip(btnShape)
|
||||
.background(if (enabled) Brush.linearGradient(listOf(colors.primary, pal.primary2)) else Brush.linearGradient(listOf(colors.surfaceVariant, colors.surfaceVariant)))
|
||||
.then(if (progress != null) Modifier.drawBehind {
|
||||
val done = size.width * shownProgress
|
||||
if (enabled) drawRect(Color.Black.copy(alpha = 0.32f), topLeft = androidx.compose.ui.geometry.Offset(done, 0f), size = androidx.compose.ui.geometry.Size(size.width - done, size.height))
|
||||
else drawRect(pal.signal.copy(alpha = 0.4f), size = androidx.compose.ui.geometry.Size(done, size.height))
|
||||
} else Modifier)
|
||||
.then(if (enabled) Modifier else Modifier.border(1.dp, pal.line2, btnShape))
|
||||
.then(if (outlined) Modifier.border(2.dp, Brush.linearGradient(listOf(pal.primary2, colors.primary)), btnShape) else Modifier)
|
||||
.glideBorder(hot, btnShape, pal.signal, hotFillAlpha = 0f)
|
||||
|
||||
@@ -50,9 +50,7 @@ fun PhantomProcessGatePage(
|
||||
onDismiss: () -> Unit,
|
||||
onOpenDeveloperOptions: () -> Unit,
|
||||
onFixWithWirelessDebugging: () -> Unit,
|
||||
onEnterAddressManually: () -> Unit,
|
||||
onCopyCommand: () -> Unit,
|
||||
onOpenNotificationSettings: () -> Unit,
|
||||
) {
|
||||
BackHandler(onBack = onDismiss)
|
||||
val context = LocalContext.current
|
||||
@@ -82,11 +80,11 @@ fun PhantomProcessGatePage(
|
||||
val fix: @Composable ColumnScope.() -> Unit = {
|
||||
if (sideQuest) SideQuestGroup(compact, onCopyCommand)
|
||||
else FixGroup(hasToggle, stage, environment, compact, applyingSavedPairing, onOpenDeveloperOptions, onFixWithWirelessDebugging,
|
||||
onOpenNotificationSettings, onCancel = { WirelessAdbPairingService.cancel(context) })
|
||||
onCancel = { WirelessAdbPairingService.cancel(context) })
|
||||
}
|
||||
val side: @Composable ColumnScope.() -> Unit = {
|
||||
StatusGroup(status, compact)
|
||||
if (!sideQuest) OtherWays(hasToggle, compact, onOpenDeveloperOptions, onFixWithWirelessDebugging, onEnterAddressManually, onCopyCommand)
|
||||
if (!sideQuest) OtherWays(hasToggle, compact, onOpenDeveloperOptions, onFixWithWirelessDebugging, onCopyCommand)
|
||||
}
|
||||
if (wide) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(14.dp), modifier = Modifier.widthIn(max = 900.dp).fillMaxWidth()) {
|
||||
@@ -104,15 +102,16 @@ fun PhantomProcessGatePage(
|
||||
}
|
||||
}
|
||||
|
||||
private data class GateEnvironment(val onWifi: Boolean, val notifications: Boolean) {
|
||||
private data class GateEnvironment(val onWifi: Boolean) {
|
||||
companion object {
|
||||
fun read(context: Context): GateEnvironment {
|
||||
val connectivity = context.getSystemService(ConnectivityManager::class.java)
|
||||
val wifi = runCatching {
|
||||
connectivity?.getNetworkCapabilities(connectivity.activeNetwork)
|
||||
?.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) == true
|
||||
connectivity?.allNetworks?.any { network ->
|
||||
connectivity.getNetworkCapabilities(network)?.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) == true
|
||||
} == true
|
||||
}.getOrDefault(true)
|
||||
return GateEnvironment(wifi, WirelessAdbPairingService.notificationsEnabled(context))
|
||||
return GateEnvironment(wifi)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,7 +125,6 @@ private fun FixGroup(
|
||||
applyingSavedPairing: Boolean,
|
||||
onOpenDeveloperOptions: () -> Unit,
|
||||
onFixWithWirelessDebugging: () -> Unit,
|
||||
onOpenNotificationSettings: () -> Unit,
|
||||
onCancel: () -> Unit,
|
||||
) {
|
||||
val pairing = stage is Stage.Waiting || stage is Stage.CodeNeeded || stage is Stage.Working
|
||||
@@ -144,6 +142,7 @@ private fun FixGroup(
|
||||
hasToggle -> {
|
||||
Body(stringResource(R.string.gate_toggle_steps))
|
||||
PrimaryButton(stringResource(R.string.gate_open_dev), compact = compact, onClick = onOpenDeveloperOptions)
|
||||
SecondaryButton(stringResource(R.string.gate_use_wireless_instead), compact = compact, enabled = environment.onWifi, onClick = onFixWithWirelessDebugging)
|
||||
}
|
||||
else -> {
|
||||
Body(stringResource(R.string.gate_no_toggle))
|
||||
@@ -151,7 +150,7 @@ private fun FixGroup(
|
||||
PrimaryButton(
|
||||
if (stage is Stage.Failed) stringResource(R.string.store_try_again) else stringResource(R.string.gate_fix_for_me),
|
||||
compact = compact,
|
||||
enabled = environment.onWifi && environment.notifications,
|
||||
enabled = environment.onWifi,
|
||||
onClick = onFixWithWirelessDebugging,
|
||||
)
|
||||
}
|
||||
@@ -160,10 +159,6 @@ private fun FixGroup(
|
||||
if (!environment.onWifi) {
|
||||
Body(stringResource(R.string.gate_needs_wifi), warn = true)
|
||||
}
|
||||
if (!environment.notifications) {
|
||||
Body(stringResource(R.string.gate_needs_notifications), warn = true)
|
||||
SecondaryButton(stringResource(R.string.gate_allow_notifications), compact = compact, onClick = onOpenNotificationSettings)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -224,7 +219,6 @@ private fun OtherWays(
|
||||
compact: Boolean,
|
||||
onOpenDeveloperOptions: () -> Unit,
|
||||
onFixWithWirelessDebugging: () -> Unit,
|
||||
onEnterAddressManually: () -> Unit,
|
||||
onCopyCommand: () -> Unit,
|
||||
) {
|
||||
var open by rememberSaveable { mutableStateOf(false) }
|
||||
@@ -240,14 +234,10 @@ private fun OtherWays(
|
||||
modifier = Modifier.fillMaxWidth().padding(start = 14.dp, end = 14.dp, bottom = 14.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
if (hasToggle) {
|
||||
SecondaryButton(stringResource(R.string.gate_use_wireless_instead), compact = true, onClick = onFixWithWirelessDebugging)
|
||||
} else {
|
||||
if (!hasToggle) {
|
||||
Body(stringResource(R.string.gate_some_roms))
|
||||
SecondaryButton(stringResource(R.string.gate_open_dev), compact = true, onClick = onOpenDeveloperOptions)
|
||||
}
|
||||
Body(stringResource(R.string.gate_manual_hint))
|
||||
SecondaryButton(stringResource(R.string.gate_enter_manually), compact = true, onClick = onEnterAddressManually)
|
||||
Body(stringResource(R.string.gate_from_computer))
|
||||
AdbCommand()
|
||||
SecondaryButton(stringResource(R.string.gate_copy_command), compact = true, onClick = onCopyCommand)
|
||||
|
||||
@@ -29,7 +29,11 @@ import androidx.compose.foundation.layout.wrapContentSize
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -154,43 +158,56 @@ internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier)
|
||||
},
|
||||
scrim = { if (games.size >= WALL_MIN_GAMES) WallFade() },
|
||||
words = {
|
||||
val onboardingActive by com.droiddeck.launcher.session.Onboarding.active.collectAsState()
|
||||
val onboardingFailed by com.droiddeck.launcher.session.Onboarding.failed.collectAsState()
|
||||
val onboardingFacts by com.droiddeck.launcher.session.Onboarding.facts.collectAsState()
|
||||
val onboardingRows = com.droiddeck.launcher.session.Onboarding.rows(onboardingActive, onboardingFailed, onboardingFacts)
|
||||
val firstRun by com.droiddeck.launcher.session.Onboarding.firstRun.collectAsState()
|
||||
val settling = firstRun && onboardingActive.isNotEmpty() && com.droiddeck.launcher.session.Onboarding.pending(onboardingRows)
|
||||
val limitBlocks = com.droiddeck.launcher.core.PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)
|
||||
val mark: @Composable () -> Unit = {
|
||||
Wordmark(if (narrow) 30.dp else 40.dp)
|
||||
}
|
||||
val runtimeStatus: @Composable () -> Unit = {
|
||||
val onboardingActive by com.droiddeck.launcher.session.Onboarding.active.collectAsState()
|
||||
val onboardingFailed by com.droiddeck.launcher.session.Onboarding.failed.collectAsState()
|
||||
val onboardingFacts by com.droiddeck.launcher.session.Onboarding.facts.collectAsState()
|
||||
val onboardingRows = com.droiddeck.launcher.session.Onboarding.rows(onboardingActive, onboardingFailed, onboardingFacts)
|
||||
val settling = onboardingActive.isNotEmpty() && com.droiddeck.launcher.session.Onboarding.pending(onboardingRows)
|
||||
if (settling || s.busy || (s.available != null && s.available != s.installed)) {
|
||||
if (settling) {
|
||||
val overall = com.droiddeck.launcher.session.Onboarding.overall(onboardingRows)
|
||||
Chip(
|
||||
stringResource(R.string.onboarding_chip, overall, onboardingRows.firstOrNull { it.state == com.droiddeck.launcher.session.Onboarding.State.ACTIVE }?.label.orEmpty()),
|
||||
ok = false, fraction = overall / 100f,
|
||||
)
|
||||
} else RuntimeChip(s)
|
||||
if (com.droiddeck.launcher.core.PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)) {
|
||||
SecondaryButton(stringResource(R.string.onboarding_limit_while_waiting), compact = true,
|
||||
modifier = Modifier.testTag("setup-while-waiting"), onClick = a.onShowPhantomGate)
|
||||
}
|
||||
} else if (setupNeedsAttention(s)) SecondaryButton(stringResource(R.string.play_needs_you), compact = true,
|
||||
if (!settling && (s.busy || (s.available != null && s.available != s.installed))) RuntimeChip(s)
|
||||
else if (!settling && setupNeedsAttention(s)) SecondaryButton(stringResource(R.string.play_needs_you), compact = true,
|
||||
modifier = Modifier.testTag("play-needs-you")) { SetupTabs.openSection = SettingsSection.OVERVIEW }
|
||||
else if (s.integration.suggested && signedIn && !com.droiddeck.launcher.core.PhantomProcessLimit.blocksSteam(s.phantomProcessStatus))
|
||||
else if (!settling && s.integration.suggested && signedIn && !limitBlocks)
|
||||
IntegrationSuggestion(s.integration, { a.onSteamIntegration(null) }, a.onDismissIntegration)
|
||||
}
|
||||
if (narrow) Column(
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
Wordmark(30.dp)
|
||||
mark()
|
||||
runtimeStatus()
|
||||
} else Row(
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
Wordmark(if (narrow) 30.dp else 40.dp)
|
||||
mark()
|
||||
runtimeStatus()
|
||||
}
|
||||
},
|
||||
button = { click ->
|
||||
PrimaryButton(stringResource(R.string.games_play_steam), enabled = !s.busy, main = true, large = true, icon = Icons.Filled.PlayArrow, modifier = Modifier.testTag("play-steam"), onClick = click)
|
||||
val onboardingActive by com.droiddeck.launcher.session.Onboarding.active.collectAsState()
|
||||
val onboardingFailed by com.droiddeck.launcher.session.Onboarding.failed.collectAsState()
|
||||
val onboardingFacts by com.droiddeck.launcher.session.Onboarding.facts.collectAsState()
|
||||
val onboardingRows = com.droiddeck.launcher.session.Onboarding.rows(onboardingActive, onboardingFailed, onboardingFacts)
|
||||
val firstRun by com.droiddeck.launcher.session.Onboarding.firstRun.collectAsState()
|
||||
val settling = firstRun && onboardingActive.isNotEmpty() && com.droiddeck.launcher.session.Onboarding.pending(onboardingRows)
|
||||
val overall = com.droiddeck.launcher.session.Onboarding.overall(onboardingRows)
|
||||
val limitBlocks = com.droiddeck.launcher.core.PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)
|
||||
LaunchedEffect(settling) {
|
||||
while (settling) {
|
||||
kotlinx.coroutines.delay(2_000)
|
||||
a.onRefreshPhantomStatus()
|
||||
}
|
||||
a.onRefreshPhantomStatus()
|
||||
}
|
||||
if (settling) PrimaryButton(
|
||||
stringResource(if (limitBlocks) R.string.onboarding_button_finish else R.string.onboarding_button_getting_ready, overall),
|
||||
enabled = limitBlocks, main = true, large = true, progress = overall / 100f,
|
||||
modifier = Modifier.testTag("play-steam"), onClick = { a.onQueuePlaySteam(); ChildProcessSetup.request?.invoke() ?: a.onShowPhantomGate() },
|
||||
) else PrimaryButton(stringResource(R.string.games_play_steam), enabled = !s.busy, main = true, large = true, icon = Icons.Filled.PlayArrow, modifier = Modifier.testTag("play-steam"), onClick = click)
|
||||
},
|
||||
rows = { tab -> a.modeSheet(mode, tab, extras) },
|
||||
)
|
||||
|
||||
@@ -1,631 +0,0 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import com.droiddeck.launcher.R
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import android.text.Editable
|
||||
import android.text.InputType
|
||||
import android.text.TextWatcher
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.EditText
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusDirection
|
||||
import androidx.compose.ui.focus.FocusManager
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.text.TextRange
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.ImeOptions
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import com.droiddeck.launcher.core.PhantomProcessLimit
|
||||
import com.droiddeck.launcher.core.WirelessAdbFix
|
||||
import kotlin.math.min
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@Composable
|
||||
fun WirelessAdbFixPage(
|
||||
onBack: () -> Unit,
|
||||
desiredEnabled: Boolean,
|
||||
onOpenDeveloperOptions: () -> Unit,
|
||||
onPair: (String, Int, String, (String?) -> Unit) -> Unit,
|
||||
onFindConnectPort: (String, (Int?) -> Unit) -> Unit,
|
||||
onApply: (String, Int, Boolean, (String?) -> Unit) -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val savedAddress = remember { WirelessAdbFix.savedConnectionAddress(context) }
|
||||
var step by rememberSaveable { mutableStateOf(if (savedAddress == null) 0 else 1) }
|
||||
var pairingAddress by rememberSaveable { mutableStateOf("") }
|
||||
var connectionAddress by rememberSaveable { mutableStateOf(savedAddress.orEmpty()) }
|
||||
var pairingCode by rememberSaveable { mutableStateOf("") }
|
||||
var busy by remember { mutableStateOf(false) }
|
||||
var editing by remember { mutableStateOf(false) }
|
||||
var message by remember { mutableStateOf<String?>(null) }
|
||||
var messageIsError by remember { mutableStateOf(false) }
|
||||
val focusManager = LocalFocusManager.current
|
||||
val keyboardController = LocalSoftwareKeyboardController.current
|
||||
val pairingEndpoint = parseAdbAddress(pairingAddress)
|
||||
|
||||
val pairNow: () -> Unit = {
|
||||
parseAdbAddress(pairingAddress)?.let { endpoint ->
|
||||
keyboardController?.hide()
|
||||
focusManager.clearFocus()
|
||||
busy = true
|
||||
editing = false
|
||||
message = null
|
||||
messageIsError = false
|
||||
onPair(endpoint.host, endpoint.port, pairingCode) { error ->
|
||||
pairingCode = ""
|
||||
if (error != null) {
|
||||
busy = false
|
||||
message = error
|
||||
messageIsError = true
|
||||
} else {
|
||||
step = 1
|
||||
busy = true
|
||||
message = context.getString(R.string.wadb_finding_port)
|
||||
onFindConnectPort(endpoint.host) { discoveredPort ->
|
||||
if (discoveredPort == null) {
|
||||
connectionAddress = formatAddressHost(endpoint.host) + ":"
|
||||
busy = false
|
||||
message = context.getString(R.string.wadb_enter_port)
|
||||
} else {
|
||||
connectionAddress = formatAdbAddress(endpoint.host, discoveredPort)
|
||||
message = context.getString(R.string.wadb_applying)
|
||||
onApply(endpoint.host, discoveredPort, desiredEnabled) { applyError ->
|
||||
busy = false
|
||||
if (applyError == null) {
|
||||
step = 2
|
||||
message = null
|
||||
} else {
|
||||
message = context.getString(R.string.wadb_apply_failed, applyError)
|
||||
messageIsError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val applyAddress: () -> Unit = {
|
||||
parseAdbAddress(connectionAddress)?.let { endpoint ->
|
||||
keyboardController?.hide()
|
||||
focusManager.clearFocus()
|
||||
busy = true
|
||||
editing = false
|
||||
message = null
|
||||
messageIsError = false
|
||||
onApply(endpoint.host, endpoint.port, desiredEnabled) { error ->
|
||||
busy = false
|
||||
if (error == null) {
|
||||
step = 2
|
||||
message = null
|
||||
} else {
|
||||
message = error
|
||||
messageIsError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val pairAgain: () -> Unit = {
|
||||
step = 0
|
||||
pairingAddress = ""
|
||||
pairingCode = ""
|
||||
message = null
|
||||
messageIsError = false
|
||||
}
|
||||
|
||||
BackHandler { if (!busy) onBack() }
|
||||
|
||||
BoxWithConstraints(Modifier.fillMaxSize()) {
|
||||
val compactSplit = maxWidth < 620.dp && maxHeight < 500.dp
|
||||
val form: @Composable () -> Unit = {
|
||||
WirelessStepForm(
|
||||
step = step,
|
||||
pairingAddress = pairingAddress,
|
||||
onPairingAddressChange = { pairingAddress = it },
|
||||
pairingCode = pairingCode,
|
||||
onPairingCodeChange = { pairingCode = it.filter(Char::isDigit).take(6) },
|
||||
connectionAddress = connectionAddress,
|
||||
onConnectionAddressChange = { connectionAddress = it },
|
||||
busy = busy,
|
||||
message = message,
|
||||
messageIsError = messageIsError,
|
||||
compact = compactSplit,
|
||||
editing = editing,
|
||||
onEditingChanged = { editing = it },
|
||||
focusManager = focusManager,
|
||||
desiredEnabled = desiredEnabled,
|
||||
canPair = pairingEndpoint != null && pairingCode.length == 6,
|
||||
onPair = pairNow,
|
||||
onApply = applyAddress,
|
||||
onPairAgain = pairAgain,
|
||||
)
|
||||
}
|
||||
SettingsPage(
|
||||
host = rememberMenuHost(),
|
||||
title = when {
|
||||
compactSplit && step < 2 -> stringResource(R.string.wadb_title_wireless)
|
||||
step == 2 -> stringResource(R.string.wadb_title_done)
|
||||
else -> stringResource(R.string.wadb_title)
|
||||
},
|
||||
eyebrow = stringResource(R.string.setup_title),
|
||||
lede = when {
|
||||
compactSplit && step == 0 -> stringResource(R.string.wadb_lede_compact0)
|
||||
compactSplit && step == 1 -> stringResource(R.string.wadb_lede_compact1)
|
||||
compactSplit -> stringResource(R.string.wadb_lede_done)
|
||||
step == 0 -> stringResource(R.string.wadb_lede0)
|
||||
step == 1 -> stringResource(R.string.wadb_lede1)
|
||||
else -> stringResource(R.string.wadb_lede_done_long)
|
||||
},
|
||||
onBack = { if (!busy) onBack() },
|
||||
action = if (compactSplit && step < 2) {
|
||||
{ SecondaryButton(stringResource(R.string.setup_dev_options), compact = true, enabled = !busy, onClick = onOpenDeveloperOptions) }
|
||||
} else null,
|
||||
scrollContent = !compactSplit,
|
||||
compactLayout = compactSplit,
|
||||
) {
|
||||
BoxWithConstraints(Modifier.fillMaxWidth()) {
|
||||
val wide = maxWidth >= 620.dp
|
||||
if (step == 2) {
|
||||
Column(
|
||||
modifier = Modifier.widthIn(max = 680.dp).fillMaxWidth(),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
) {
|
||||
SettingsGroup(stringResource(R.string.setup_limit), compact = compactSplit) {
|
||||
Text(
|
||||
if (desiredEnabled) stringResource(R.string.wadb_confirmed_on) else stringResource(R.string.wadb_confirmed_off),
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(14.dp),
|
||||
)
|
||||
}
|
||||
PrimaryButton(stringResource(R.string.setup_check_done), enabled = !busy, onClick = onBack)
|
||||
}
|
||||
} else if (compactSplit) {
|
||||
Column(
|
||||
modifier = Modifier.widthIn(max = 600.dp).fillMaxWidth(),
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
) {
|
||||
form()
|
||||
if (!editing) CompactComputerFallback(desiredEnabled)
|
||||
}
|
||||
} else {
|
||||
val routes: @Composable () -> Unit = {
|
||||
FallbackOrder(desiredEnabled, busy, onOpenDeveloperOptions)
|
||||
}
|
||||
if (wide) {
|
||||
Row(
|
||||
modifier = Modifier.widthIn(max = 900.dp).fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(14.dp),
|
||||
verticalAlignment = Alignment.Top,
|
||||
) {
|
||||
Column(Modifier.weight(1f)) { routes() }
|
||||
Column(Modifier.weight(1f)) { form() }
|
||||
}
|
||||
} else {
|
||||
Column(
|
||||
modifier = Modifier.widthIn(max = 600.dp).fillMaxWidth(),
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
) {
|
||||
routes()
|
||||
form()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun WirelessStepForm(
|
||||
step: Int,
|
||||
pairingAddress: String,
|
||||
onPairingAddressChange: (String) -> Unit,
|
||||
pairingCode: String,
|
||||
onPairingCodeChange: (String) -> Unit,
|
||||
connectionAddress: String,
|
||||
onConnectionAddressChange: (String) -> Unit,
|
||||
busy: Boolean,
|
||||
message: String?,
|
||||
messageIsError: Boolean,
|
||||
compact: Boolean,
|
||||
editing: Boolean,
|
||||
onEditingChanged: (Boolean) -> Unit,
|
||||
focusManager: FocusManager,
|
||||
desiredEnabled: Boolean,
|
||||
canPair: Boolean,
|
||||
onPair: () -> Unit,
|
||||
onApply: () -> Unit,
|
||||
onPairAgain: () -> Unit,
|
||||
) {
|
||||
if (step == 0) {
|
||||
SettingsGroup(stringResource(R.string.wadb_pair_group), compact = compact) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = if (compact) 8.dp else 12.dp, vertical = if (compact) 6.dp else 12.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(if (compact) 5.dp else 6.dp),
|
||||
) {
|
||||
AdbTextField(
|
||||
value = pairingAddress,
|
||||
onValueChange = onPairingAddressChange,
|
||||
label = stringResource(R.string.wadb_pair_address),
|
||||
placeholder = "192.168.1.42:37123",
|
||||
keyboardType = KeyboardType.Ascii,
|
||||
imeAction = ImeAction.Next,
|
||||
compact = compact,
|
||||
onFocusChange = onEditingChanged,
|
||||
onNext = { focusManager.moveFocus(FocusDirection.Next) },
|
||||
)
|
||||
Row(
|
||||
verticalAlignment = Alignment.Bottom,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
) {
|
||||
AdbTextField(
|
||||
value = pairingCode,
|
||||
onValueChange = onPairingCodeChange,
|
||||
label = stringResource(R.string.wadb_pin),
|
||||
placeholder = stringResource(R.string.wadb_pin_placeholder),
|
||||
keyboardType = KeyboardType.Number,
|
||||
imeAction = ImeAction.Done,
|
||||
compact = compact,
|
||||
onFocusChange = onEditingChanged,
|
||||
onDone = {
|
||||
focusManager.clearFocus()
|
||||
},
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
PrimaryButton(stringResource(R.string.wadb_pair), compact = compact, enabled = !busy && canPair, onClick = onPair)
|
||||
}
|
||||
StatusMessage(busy, message, isError = messageIsError)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SettingsGroup(stringResource(R.string.wadb_apply_group), compact = compact) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = if (compact) 8.dp else 12.dp, vertical = if (compact) 6.dp else 12.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(if (compact) 5.dp else 6.dp),
|
||||
) {
|
||||
AdbTextField(
|
||||
value = connectionAddress,
|
||||
onValueChange = onConnectionAddressChange,
|
||||
label = stringResource(R.string.wadb_connect_address),
|
||||
placeholder = "192.168.1.42:45678",
|
||||
keyboardType = KeyboardType.Ascii,
|
||||
imeAction = ImeAction.Done,
|
||||
compact = compact,
|
||||
onFocusChange = onEditingChanged,
|
||||
onDone = { focusManager.clearFocus() },
|
||||
)
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
) {
|
||||
StatusMessage(busy, message, Modifier.weight(1f), isError = messageIsError)
|
||||
SecondaryButton(stringResource(R.string.wadb_pair_again), compact = compact, enabled = !busy, onClick = onPairAgain)
|
||||
PrimaryButton(
|
||||
if (desiredEnabled) stringResource(R.string.setup_limit_turn_on) else stringResource(R.string.wadb_turn_off),
|
||||
compact = compact,
|
||||
enabled = !busy && parseAdbAddress(connectionAddress) != null,
|
||||
onClick = onApply,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun AdbTextField(
|
||||
value: String,
|
||||
onValueChange: (String) -> Unit,
|
||||
label: String,
|
||||
keyboardType: KeyboardType,
|
||||
imeAction: ImeAction,
|
||||
modifier: Modifier = Modifier,
|
||||
placeholder: String? = null,
|
||||
compact: Boolean = false,
|
||||
onFocusChange: (Boolean) -> Unit = {},
|
||||
clearFocus: Boolean = false,
|
||||
onNext: (() -> Unit)? = null,
|
||||
onDone: (() -> Unit)? = null,
|
||||
focusOnShow: Boolean = false,
|
||||
showLabel: Boolean = true,
|
||||
focusAtTap: Int? = null,
|
||||
onBack: (() -> Unit)? = null,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val onBackLatest = rememberUpdatedState(onBack)
|
||||
val focusAsked = remember { booleanArrayOf(false) }
|
||||
val focusTapAsked = remember { arrayOfNulls<Int>(1) }
|
||||
val palette = LocalPalette.current
|
||||
val onValueChangeLatest = rememberUpdatedState(onValueChange)
|
||||
val onNextLatest = rememberUpdatedState(onNext)
|
||||
val onDoneLatest = rememberUpdatedState(onDone)
|
||||
val onFocusChangeLatest = rememberUpdatedState(onFocusChange)
|
||||
var focused by remember { mutableStateOf(false) }
|
||||
val shape = RoundedCornerShape(8.dp)
|
||||
val inputHeight = if (compact) 44.dp else 52.dp
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val bottomTyping = LocalBottomTyping.current
|
||||
val bottomTypingLatest = rememberUpdatedState(bottomTyping)
|
||||
val typingRequest = remember { arrayOfNulls<TypingRequest>(1) }
|
||||
|
||||
fun typeOnBottom(editText: EditText): Boolean {
|
||||
if (!bottomTypingLatest.value || !DualScreenPanel.attached) return false
|
||||
val text = editText.text.toString()
|
||||
lateinit var request: TypingRequest
|
||||
request = TypingRequest(
|
||||
TextFieldValue(text, TextRange(editText.selectionStart.coerceIn(0, text.length), editText.selectionEnd.coerceIn(0, text.length))),
|
||||
ImeOptions(singleLine = true, keyboardType = keyboardType, imeAction = imeAction),
|
||||
{ next ->
|
||||
if (editText.text.toString() != next.text) editText.setText(next.text)
|
||||
editText.setSelection(next.selection.start.coerceIn(0, next.text.length), next.selection.end.coerceIn(0, next.text.length))
|
||||
},
|
||||
{ action -> editText.onEditorAction(imeActionFlag(action)) },
|
||||
{ editText.post { if (typingRequest[0] === request) onBackLatest.value?.invoke() ?: editText.clearFocus() } },
|
||||
)
|
||||
typingRequest[0] = request
|
||||
DualScreenPanel.startTyping(request)
|
||||
return true
|
||||
}
|
||||
|
||||
DisposableEffect(Unit) {
|
||||
onDispose { typingRequest[0]?.let { DualScreenPanel.stopTyping(it) } }
|
||||
}
|
||||
|
||||
Column(modifier = modifier.fillMaxWidth()) {
|
||||
if (showLabel) Text(
|
||||
label,
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = colors.onSurfaceVariant,
|
||||
maxLines = 1,
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(inputHeight)
|
||||
.background(colors.surfaceVariant, shape)
|
||||
.glideBorder(focused, shape, palette.signal, palette.line2)
|
||||
.padding(horizontal = 10.dp),
|
||||
contentAlignment = Alignment.CenterStart,
|
||||
) {
|
||||
AndroidView(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
factory = { viewContext ->
|
||||
EditText(viewContext).apply {
|
||||
isSingleLine = true
|
||||
setHorizontallyScrolling(true)
|
||||
background = null
|
||||
setPadding((2 * context.resources.displayMetrics.density).roundToInt(), 0, 0, 0)
|
||||
setTextSize(android.util.TypedValue.COMPLEX_UNIT_SP, if (compact) 13f else 14f)
|
||||
setTextColor(colors.onBackground.toArgb())
|
||||
setHintTextColor(colors.onSurfaceVariant.toArgb())
|
||||
contentDescription = label
|
||||
inputType = if (keyboardType == KeyboardType.Number) {
|
||||
InputType.TYPE_CLASS_NUMBER
|
||||
} else {
|
||||
InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_URI or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
|
||||
}
|
||||
imeOptions = imeActionFlag(imeAction) or EditorInfo.IME_FLAG_NO_FULLSCREEN or EditorInfo.IME_FLAG_NO_EXTRACT_UI
|
||||
hint = placeholder
|
||||
setOnEditorActionListener { _, actionId, event ->
|
||||
val isEnter = event?.keyCode == android.view.KeyEvent.KEYCODE_ENTER
|
||||
when {
|
||||
imeAction == ImeAction.Next && (actionId == EditorInfo.IME_ACTION_NEXT || isEnter) -> {
|
||||
onNextLatest.value?.invoke()
|
||||
true
|
||||
}
|
||||
imeAction == ImeAction.Done && (actionId == EditorInfo.IME_ACTION_DONE || isEnter) -> {
|
||||
onDoneLatest.value?.invoke()
|
||||
true
|
||||
}
|
||||
// Search and Go are terminal: leaving them unhandled
|
||||
// keeps focus in the field, so the keyboard would stay
|
||||
// up over the results it was used to find.
|
||||
imeAction in setOf(ImeAction.Search, ImeAction.Go) &&
|
||||
(actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_GO || isEnter) -> {
|
||||
onDoneLatest.value?.invoke()
|
||||
post {
|
||||
clearFocus()
|
||||
(context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE)
|
||||
as? android.view.inputmethod.InputMethodManager)
|
||||
?.hideSoftInputFromWindow(windowToken, 0)
|
||||
}
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
showSoftInputOnFocus = !bottomTyping
|
||||
// B on a controller puts the keyboard away first; with no keyboard up it goes back as usual.
|
||||
var hidingKeyboard = false
|
||||
setOnKeyListener { view, keyCode, event ->
|
||||
if (keyCode != android.view.KeyEvent.KEYCODE_BUTTON_B) return@setOnKeyListener false
|
||||
if (event.action == android.view.KeyEvent.ACTION_DOWN && event.repeatCount == 0) {
|
||||
hidingKeyboard = androidx.core.view.ViewCompat.getRootWindowInsets(view)
|
||||
?.isVisible(androidx.core.view.WindowInsetsCompat.Type.ime()) == true
|
||||
if (hidingKeyboard) (view.context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager)
|
||||
?.hideSoftInputFromWindow(view.windowToken, 0)
|
||||
onBackLatest.value?.let { hidingKeyboard = true; it() }
|
||||
}
|
||||
hidingKeyboard
|
||||
}
|
||||
setOnClickListener { if (hasFocus() && !typeOnBottom(this) && bottomTypingLatest.value) showKeyboardHere(this) }
|
||||
setOnFocusChangeListener { _, hasFocus ->
|
||||
focused = hasFocus
|
||||
if (hasFocus) { if (!typeOnBottom(this) && bottomTypingLatest.value) showKeyboardHere(this) }
|
||||
else typingRequest[0]?.let { DualScreenPanel.stopTyping(it) }
|
||||
onFocusChangeLatest.value(hasFocus)
|
||||
}
|
||||
addTextChangedListener(object : TextWatcher {
|
||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) = Unit
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) = Unit
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
onValueChangeLatest.value(s?.toString().orEmpty())
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
update = { editText ->
|
||||
editText.showSoftInputOnFocus = !bottomTyping
|
||||
// A new tap may ask again: a field still on screen while it closes can be opened once more.
|
||||
val fresh = if (focusAtTap != null) focusTapAsked[0] != focusAtTap else !focusAsked[0]
|
||||
if (focusOnShow && fresh) {
|
||||
if (focusAtTap != null) focusTapAsked[0] = focusAtTap else focusAsked[0] = true
|
||||
editText.post {
|
||||
if (focusAtTap != null && focusAtTap != ScreenTaps.count) return@post
|
||||
editText.requestFocus()
|
||||
if (!bottomTypingLatest.value) (editText.context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager)
|
||||
?.showSoftInput(editText, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
}
|
||||
if (clearFocus && editText.hasFocus()) {
|
||||
editText.clearFocus()
|
||||
(editText.context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager)
|
||||
?.hideSoftInputFromWindow(editText.windowToken, 0)
|
||||
}
|
||||
editText.setTextColor(colors.onBackground.toArgb())
|
||||
editText.setHintTextColor(colors.onSurfaceVariant.toArgb())
|
||||
editText.hint = placeholder
|
||||
editText.contentDescription = label
|
||||
if (editText.text.toString() != value) {
|
||||
val cursor = if (editText.hasFocus()) editText.selectionStart.coerceAtLeast(0) else value.length
|
||||
editText.setText(value)
|
||||
editText.setSelection(min(cursor, value.length))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun FallbackOrder(
|
||||
desiredEnabled: Boolean,
|
||||
busy: Boolean,
|
||||
onOpenDeveloperOptions: () -> Unit,
|
||||
) {
|
||||
SettingsGroup(stringResource(R.string.wadb_other_ways)) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
Text(stringResource(R.string.wadb_dev_try_first), style = MaterialTheme.typography.bodySmall, fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onBackground)
|
||||
Text(if (desiredEnabled) stringResource(R.string.wadb_restrict_on) else stringResource(R.string.wadb_restrict_off), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
SecondaryButton(stringResource(R.string.gate_open_dev), enabled = !busy, onClick = onOpenDeveloperOptions)
|
||||
Text(stringResource(R.string.wadb_computer_last), style = MaterialTheme.typography.bodySmall, fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onBackground)
|
||||
Text(stringResource(R.string.wadb_only_if), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
Text(
|
||||
PhantomProcessLimit.adbCommand(desiredEnabled),
|
||||
style = MaterialTheme.typography.bodySmall.copy(fontFamily = FontFamily.Monospace),
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CompactComputerFallback(desiredEnabled: Boolean) {
|
||||
SettingsGroup(stringResource(R.string.wadb_computer_group), compact = true) {
|
||||
Text(
|
||||
PhantomProcessLimit.adbCommand(desiredEnabled),
|
||||
style = MaterialTheme.typography.labelSmall.copy(fontFamily = FontFamily.Monospace),
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 10.dp, vertical = 4.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun StatusMessage(busy: Boolean, message: String?, modifier: Modifier = Modifier, isError: Boolean = false) {
|
||||
if (busy) {
|
||||
Row(modifier = modifier, verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
CircularProgressIndicator(modifier = Modifier.size(20.dp), strokeWidth = 2.dp)
|
||||
Text(message ?: stringResource(R.string.common_working), style = MaterialTheme.typography.bodySmall)
|
||||
}
|
||||
} else {
|
||||
message?.let {
|
||||
Text(
|
||||
it,
|
||||
modifier = modifier,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = if (isError) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data class AdbEndpoint(val host: String, val port: Int)
|
||||
|
||||
private fun parseAdbAddress(value: String): AdbEndpoint? {
|
||||
val address = value.trim()
|
||||
val host: String
|
||||
val portText: String
|
||||
if (address.startsWith("[")) {
|
||||
val closingBracket = address.indexOf(']')
|
||||
if (closingBracket <= 1 || address.getOrNull(closingBracket + 1) != ':') return null
|
||||
host = address.substring(1, closingBracket)
|
||||
if (':' !in host) return null
|
||||
portText = address.substring(closingBracket + 2)
|
||||
} else {
|
||||
val colon = address.lastIndexOf(':')
|
||||
if (colon <= 0 || address.indexOf(':') != colon) return null
|
||||
host = address.substring(0, colon)
|
||||
portText = address.substring(colon + 1)
|
||||
}
|
||||
if (host.isBlank() || host.any(Char::isWhitespace)) return null
|
||||
val port = portText.toIntOrNull()?.takeIf { it in 1..65535 } ?: return null
|
||||
return AdbEndpoint(host, port)
|
||||
}
|
||||
|
||||
private fun formatAddressHost(host: String): String = if (':' in host) "[$host]" else host
|
||||
private fun formatAdbAddress(host: String, port: Int): String = "${formatAddressHost(host)}:$port"
|
||||
|
||||
private fun showKeyboardHere(editText: EditText) {
|
||||
(editText.context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager)
|
||||
?.showSoftInput(editText, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
|
||||
private fun imeActionFlag(action: ImeAction): Int = when (action) {
|
||||
ImeAction.Next -> EditorInfo.IME_ACTION_NEXT
|
||||
ImeAction.Done -> EditorInfo.IME_ACTION_DONE
|
||||
ImeAction.Go -> EditorInfo.IME_ACTION_GO
|
||||
ImeAction.Search -> EditorInfo.IME_ACTION_SEARCH
|
||||
else -> EditorInfo.IME_ACTION_UNSPECIFIED
|
||||
}
|
||||
Reference in new issue
Block a user