mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
feat: exit the launcher with three back presses (#1599)
Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
1 parent
91a217879f
commit
cbcf39d7c2
35 files changed
+87
-3
No files matched your search
@@ -0,0 +1,40 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.os.SystemClock
|
||||
|
||||
internal fun Context.finishTask() {
|
||||
var c: Context = this
|
||||
while (c is ContextWrapper) {
|
||||
if (c is Activity) {
|
||||
c.finishAndRemoveTask()
|
||||
return
|
||||
}
|
||||
c = c.baseContext
|
||||
}
|
||||
}
|
||||
|
||||
internal object ExitGesture {
|
||||
private const val WINDOW_MS = 2_000L
|
||||
|
||||
private var count = 0
|
||||
private var firstAt = 0L
|
||||
|
||||
fun back(): Int {
|
||||
val now = SystemClock.uptimeMillis()
|
||||
if (count == 0 || now - firstAt > WINDOW_MS) {
|
||||
count = 1
|
||||
firstAt = now
|
||||
} else {
|
||||
count += 1
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
count = 0
|
||||
firstAt = 0L
|
||||
}
|
||||
}
|
||||
@@ -845,8 +845,19 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
(s.pageKey == null && Hops.origin?.page == selected) ||
|
||||
((s.pageKey == null || page == null) &&
|
||||
(selected.startsWith("emu:") || selected.startsWith("rom:") || selected.startsWith("user:") || selected == "store"))
|
||||
BackHandler(enabled = !processSettingsPageVisible && !hasBackTarget) {
|
||||
if (inputModeManager.inputMode != InputMode.Keyboard) inputModeManager.requestInputMode(InputMode.Keyboard)
|
||||
runCatching { frontFocus.railFor(railSelection).requestFocus() }
|
||||
val exitArmed = !processSettingsPageVisible && !hasBackTarget
|
||||
LaunchedEffect(exitArmed, selected) { ExitGesture.reset() }
|
||||
BackHandler(enabled = exitArmed) {
|
||||
when (ExitGesture.back()) {
|
||||
2 -> android.widget.Toast.makeText(ctx, R.string.exit_hint_back, android.widget.Toast.LENGTH_SHORT).show()
|
||||
3 -> {
|
||||
ExitGesture.reset()
|
||||
ctx.finishTask()
|
||||
}
|
||||
else -> {
|
||||
if (inputModeManager.inputMode != InputMode.Keyboard) inputModeManager.requestInputMode(InputMode.Keyboard)
|
||||
runCatching { frontFocus.railFor(railSelection).requestFocus() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user