feat(phase-1/m5.1): desktop Esc back stack + Ctrl+N/Ctrl+comma shortcuts
JVM PlatformBackHandler made real (PlatformBackStack + LocalPlatformBackStack); window drains it on Esc via Window(onPreviewKeyEvent) — the editor rides the shared seam unchanged (draft flush + discard prompt). Shell registers drawer/settings Esc; preview-phase shortcuts. New --keys-smoke leg drives the exact dispatch headlessly. Keypress capture pending-manual (KWin/Wayland drops xdotool XTEST events to the XWayland window). Verify: ./gradlew assembleDebug :composeApp:compileKotlinJvm :desktopApp:build (SUCCESSFUL); :desktopApp:run --args="--data-dir /tmp/incido-keys --keys-smoke --exit-after 12" (KEYS ALL-OK); --self-test/--settings-smoke/--editor-smoke green; :core:data-jvm:smoke M1a PASS.
This commit is contained in:
1 parent
faab0cde98
commit
639f39d187
5 files changed
+252
-8
No files matched your search
@@ -7,9 +7,9 @@ import androidx.compose.runtime.Composable
|
||||
* wrapper around `activity-compose` inside the editor file).
|
||||
*
|
||||
* Android actual = `androidx.activity.compose.BackHandler`, verbatim
|
||||
* behaviour. The JVM actual is a no-op: a desktop window has no system
|
||||
* back gesture, the editor's close button owns that path, and physical
|
||||
* Esc/back-key routing is keyboard-shortcut polish on the M5 list.
|
||||
* behaviour. The JVM actual (M5.1) registers into the desktop window's
|
||||
* [PlatformBackStack], which the window drains on Esc — so the editor's
|
||||
* discard-prompt chain works on both platforms through this one seam.
|
||||
*/
|
||||
@Composable
|
||||
expect fun PlatformBackHandler(enabled: Boolean, onBack: () -> Unit)
|
||||
@@ -1,8 +1,66 @@
|
||||
package org.incido.compose.util
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.runtime.remember
|
||||
|
||||
/** M4.4c JVM actual — no system back gesture on a desktop window; the
|
||||
* editor's close button owns that path (Esc handling is M5 polish). */
|
||||
/**
|
||||
* M5.1 — the M4.4c no-op made real: a desktop back stack.
|
||||
*
|
||||
* A desktop window has no system back gesture, so the desktop window
|
||||
* translates Esc (`Window(onPreviewKeyEvent)`) into [dispatchBack] on the
|
||||
* [PlatformBackStack] provided through [LocalPlatformBackStack]. Every live
|
||||
* `PlatformBackHandler` becomes an entry here, so the editor's existing
|
||||
* tryClose/discard-prompt chain behaves exactly like Android's BackHandler
|
||||
* stack: the topmost enabled entry wins.
|
||||
*
|
||||
* Entries keep their stack position across recompositions: the registration
|
||||
* object is remembered and its callback slot refreshed per composition.
|
||||
* Re-registering on every `onBack` lambda change would let a lower handler's
|
||||
* recomposition jump above an editor or dialog stacked on top of it.
|
||||
*/
|
||||
class PlatformBackStack {
|
||||
internal class Entry(var enabled: Boolean = false, var onBack: () -> Unit = {})
|
||||
|
||||
private val entries = ArrayDeque<Entry>()
|
||||
|
||||
internal fun push(entry: Entry) {
|
||||
entries.addLast(entry)
|
||||
}
|
||||
|
||||
internal fun remove(entry: Entry) {
|
||||
entries.remove(entry)
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the topmost enabled handler. Returns true when consumed — the
|
||||
* window uses that to decide whether Esc falls through to content.
|
||||
*/
|
||||
fun dispatchBack(): Boolean {
|
||||
val top = entries.lastOrNull { it.enabled } ?: return false
|
||||
top.onBack()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
/** Provided by the desktop host window (see `:desktopApp` Main.kt, M5.1). */
|
||||
val LocalPlatformBackStack = compositionLocalOf<PlatformBackStack?> { null }
|
||||
|
||||
/**
|
||||
* M4.4c/M5.1 JVM actual — registers into [LocalPlatformBackStack]. No-op
|
||||
* when the host provides no stack (headless tests, embeds).
|
||||
*/
|
||||
@Composable
|
||||
actual fun PlatformBackHandler(enabled: Boolean, onBack: () -> Unit) = Unit
|
||||
actual fun PlatformBackHandler(enabled: Boolean, onBack: () -> Unit) {
|
||||
val stack = LocalPlatformBackStack.current
|
||||
val entry = remember { PlatformBackStack.Entry() }
|
||||
entry.enabled = enabled
|
||||
entry.onBack = onBack
|
||||
if (stack != null) {
|
||||
DisposableEffect(stack) {
|
||||
stack.push(entry)
|
||||
onDispose { stack.remove(entry) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.incido.desktop
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.DrawerValue
|
||||
import androidx.compose.material3.ModalNavigationDrawer
|
||||
import androidx.compose.material3.rememberDrawerState
|
||||
@@ -11,12 +13,21 @@ import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.key.Key
|
||||
import androidx.compose.ui.input.key.KeyEventType
|
||||
import androidx.compose.ui.input.key.isCtrlPressed
|
||||
import androidx.compose.ui.input.key.key
|
||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||
import androidx.compose.ui.input.key.type
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import org.incido.compose.di.LocalAppGraph
|
||||
import org.incido.compose.ui.drawer.IncidoDrawer
|
||||
import org.incido.compose.ui.editor.NoteEditorScreen
|
||||
import org.incido.compose.ui.notelist.NoteListScreen
|
||||
import org.incido.compose.util.LocalPlatformBackStack
|
||||
import org.incido.compose.util.PlatformBackHandler
|
||||
import org.incido.domain.model.NoteFilter
|
||||
|
||||
/**
|
||||
@@ -31,8 +42,10 @@ import org.incido.domain.model.NoteFilter
|
||||
* Platform differences handled, not faked (§6.5):
|
||||
* - beginExternalActivity is null on desktop (no auto-lock to suppress),
|
||||
* - the editor's intake seam hides camera/voice on the JVM,
|
||||
* - PlatformBackHandler is a no-op here — Esc routing is M5 polish,
|
||||
* the editor closes via its own top-bar arrow like the phone's up button.
|
||||
* - M5.1: Esc routes through the window back stack — the editor's own
|
||||
* commonMain PlatformBackHandler gets its discard-prompt tryClose, the
|
||||
* shell registers drawer + settings below it.
|
||||
* - M5.1 shortcuts: Ctrl+N new note, Ctrl+comma settings.
|
||||
*/
|
||||
@Composable
|
||||
fun DesktopShell(
|
||||
@@ -41,13 +54,32 @@ fun DesktopShell(
|
||||
onShowSettings: (Boolean) -> Unit,
|
||||
/** M4.5b scripted leg: opens the editor headlessly after first frame. */
|
||||
editorSmoke: Boolean = false,
|
||||
/** M5.1 scripted leg: drives backStack.dispatchBack() — the exact path
|
||||
* Window(onPreviewKeyEvent) runs on Esc. */
|
||||
keysSmoke: Boolean = false,
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
val drawerState = rememberDrawerState(DrawerValue.Closed)
|
||||
val backStack = LocalPlatformBackStack.current
|
||||
var filterMode by remember { mutableStateOf<NoteFilter>(NoteFilter.Home) }
|
||||
var editorOpen by remember { mutableStateOf(false) }
|
||||
// null id = "new note" (exactly what onOpenEditor(null) means on Android).
|
||||
var editorNoteId by remember { mutableStateOf<Long?>(null) }
|
||||
// M5.1 KEYS leg mirror of the parent's showSettings — it flips only
|
||||
// through the same callback the back handler calls, so asserting on it
|
||||
// asserts on the real routing. Rendering stays on the parent's state.
|
||||
var settingsOpen by remember { mutableStateOf(false) }
|
||||
// Mirror follows the parent so every close path (back arrow, Esc,
|
||||
// shortcut toggles) keeps the KEYS-leg assertion honest.
|
||||
LaunchedEffect(showSettings) { settingsOpen = showSettings }
|
||||
|
||||
// M5.1 — Esc registrations below the editor's own (the common seam
|
||||
// registers while the editor is composed; topmost enabled entry wins).
|
||||
PlatformBackHandler(enabled = showSettings, onBack = { onShowSettings(false) })
|
||||
PlatformBackHandler(
|
||||
enabled = drawerState.isOpen,
|
||||
onBack = { scope.launch { drawerState.close() } },
|
||||
)
|
||||
|
||||
if (editorSmoke) {
|
||||
LaunchedEffect(Unit) {
|
||||
@@ -59,7 +91,74 @@ fun DesktopShell(
|
||||
}
|
||||
}
|
||||
|
||||
if (keysSmoke) {
|
||||
LaunchedEffect(Unit) {
|
||||
delay(2200)
|
||||
var pass = backStack != null
|
||||
// a) Editor owns Esc through the commonMain seam: a dispatch on
|
||||
// a clean new note must flush the draft and close — exactly
|
||||
// the Android BackHandler-chain behaviour.
|
||||
editorNoteId = null
|
||||
editorOpen = true
|
||||
delay(1200) // let the editor register its handler
|
||||
val consumedEditor = backStack?.dispatchBack() == true
|
||||
delay(400) // state flip + recomposition
|
||||
val editorClosed = !editorOpen
|
||||
pass = pass && consumedEditor && editorClosed
|
||||
println(
|
||||
"KEYS editor Esc consumed=$consumedEditor closed=$editorClosed " +
|
||||
(if (consumedEditor && editorClosed) "PASS" else "FAIL"),
|
||||
)
|
||||
// b) Nothing enabled must NOT consume — Esc keeps reaching
|
||||
// popups/text fields through the preview chain.
|
||||
val consumedEmpty = backStack?.dispatchBack() == true
|
||||
pass = pass && !consumedEmpty
|
||||
println(
|
||||
"KEYS nothing-enabled consumed=$consumedEmpty " +
|
||||
(if (!consumedEmpty) "PASS" else "FAIL"),
|
||||
)
|
||||
// c) Settings closes on Esc via the shell registration — the
|
||||
// same onShowSettings(false) the window's Esc callback makes.
|
||||
settingsOpen = true
|
||||
onShowSettings(true)
|
||||
delay(600)
|
||||
val consumedSettings = backStack?.dispatchBack() == true
|
||||
delay(400)
|
||||
val settingsGone = !settingsOpen
|
||||
pass = pass && consumedSettings && settingsGone
|
||||
println(
|
||||
"KEYS settings Esc consumed=$consumedSettings closed=$settingsGone " +
|
||||
(if (consumedSettings && settingsGone) "PASS" else "FAIL"),
|
||||
)
|
||||
println("KEYS ${if (pass) "ALL-OK" else "PROBLEMS (see FAIL lines above)"}")
|
||||
}
|
||||
}
|
||||
|
||||
CompositionLocalProvider(LocalAppGraph provides app) {
|
||||
// M5.1 shortcuts. Preview-phase, so they win over focused text
|
||||
// fields — Ctrl+N inside the editor means "new note", not "type n".
|
||||
Box(
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
.onPreviewKeyEvent { event ->
|
||||
if (event.type != KeyEventType.KeyDown) return@onPreviewKeyEvent false
|
||||
when {
|
||||
event.isCtrlPressed && event.key == Key.N &&
|
||||
!editorOpen && !showSettings -> {
|
||||
println("KEYS shortcut ctrl+N -> new note")
|
||||
editorNoteId = null
|
||||
editorOpen = true
|
||||
true
|
||||
}
|
||||
event.isCtrlPressed && event.key == Key.Comma && !showSettings -> {
|
||||
println("KEYS shortcut ctrl+comma -> settings")
|
||||
onShowSettings(true)
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
},
|
||||
) {
|
||||
when {
|
||||
showSettings -> DesktopSettingsScreen(app = app, onBack = { onShowSettings(false) })
|
||||
editorOpen -> NoteEditorScreen(
|
||||
@@ -95,4 +194,5 @@ fun DesktopShell(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -42,6 +43,10 @@ import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.key.Key
|
||||
import androidx.compose.ui.input.key.KeyEventType
|
||||
import androidx.compose.ui.input.key.key
|
||||
import androidx.compose.ui.input.key.type
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.Window
|
||||
@@ -60,6 +65,8 @@ import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.incido.compose.data.backup.BackupBridge
|
||||
import org.incido.compose.ui.theme.IncidoTheme
|
||||
import org.incido.compose.util.LocalPlatformBackStack
|
||||
import org.incido.compose.util.PlatformBackStack
|
||||
import org.incido.compose.data.backup.EncryptedBackupCodec
|
||||
import org.incido.compose.data.backup.EncryptedKeyCodec
|
||||
import org.incido.data.crypto.AesGcmFieldCipher
|
||||
@@ -107,6 +114,10 @@ fun main(args: Array<String>) {
|
||||
// so the shared sections (M4.4d) render on the JVM before auto-exit.
|
||||
val settingsSmoke = "--settings-smoke" in args
|
||||
val editorSmoke = "--editor-smoke" in args
|
||||
// M5.1 scripted leg: drives the exact Esc dispatch path the window's
|
||||
// onPreviewKeyEvent uses (backStack.dispatchBack) against the real
|
||||
// editor and settings registrations.
|
||||
val keysSmoke = "--keys-smoke" in args
|
||||
val cryptoSelfTest = "--crypto-self-test" in args
|
||||
val cryptoReopen = "--crypto-reopen" in args
|
||||
val cryptoPassphrase = args.argAfter("--crypto-passphrase") ?: "selftest-passphrase"
|
||||
@@ -123,6 +134,12 @@ fun main(args: Array<String>) {
|
||||
|
||||
val app = DesktopContainer(dataDir)
|
||||
|
||||
// M5.1: the desktop back stack. PlatformBackHandler (composeApp jvm
|
||||
// actual) registers into it; Esc below drains it, topmost enabled
|
||||
// entry first — the editor's discard-prompt chain included, since its
|
||||
// BackHandler(enabled=true){tryClose()} rides the same seam.
|
||||
val backStack = PlatformBackStack()
|
||||
|
||||
// M3: window geometry is desktop-only state, kept in its OWN store file
|
||||
// (incido_window.preferences_pb) — settings stay the phone-shared schema.
|
||||
// Position is deliberately NOT stored: KWin owns placement on this stack.
|
||||
@@ -142,7 +159,21 @@ fun main(args: Array<String>) {
|
||||
onCloseRequest = ::exitApplication,
|
||||
state = windowState,
|
||||
title = "Incido",
|
||||
// M5.1: Esc = system back. Consumed only when a handler is
|
||||
// live; otherwise it falls through so popups keep their own
|
||||
// Esc handling. This is the exact dispatcher --keys-smoke
|
||||
// drives headlessly via backStack.dispatchBack().
|
||||
onPreviewKeyEvent = { event ->
|
||||
if (event.type == KeyEventType.KeyDown && event.key == Key.Escape) {
|
||||
val consumed = backStack.dispatchBack()
|
||||
println("KEYS esc(captured) consumed=$consumed")
|
||||
consumed
|
||||
} else {
|
||||
false
|
||||
}
|
||||
},
|
||||
) {
|
||||
CompositionLocalProvider(LocalPlatformBackStack provides backStack) {
|
||||
NotesWindow(
|
||||
app = app,
|
||||
repository = app.noteRepository,
|
||||
@@ -152,6 +183,7 @@ fun main(args: Array<String>) {
|
||||
selfTest = selfTest,
|
||||
settingsSmoke = settingsSmoke,
|
||||
editorSmoke = editorSmoke,
|
||||
keysSmoke = keysSmoke,
|
||||
backupImport = backupImport,
|
||||
backupExport = backupExport,
|
||||
backupExportEnc = backupExportEnc,
|
||||
@@ -165,6 +197,7 @@ fun main(args: Array<String>) {
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// application{} returns once every window is closed.
|
||||
app.shutdown()
|
||||
@@ -180,6 +213,7 @@ private fun NotesWindow(
|
||||
selfTest: Boolean,
|
||||
settingsSmoke: Boolean,
|
||||
editorSmoke: Boolean,
|
||||
keysSmoke: Boolean,
|
||||
backupImport: String?,
|
||||
backupExport: String?,
|
||||
backupExportEnc: String?,
|
||||
@@ -213,6 +247,7 @@ private fun NotesWindow(
|
||||
showSettings = showSettings,
|
||||
onShowSettings = { showSettings = it },
|
||||
editorSmoke = editorSmoke,
|
||||
keysSmoke = keysSmoke,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -802,6 +802,57 @@ M4.4/M4.5 suite (per commit; final run this entry):
|
||||
window/menu integration, packaging (`createDistributable` re-verify +
|
||||
the M4.3d artifact notes), and the §9 perf pass on the real screens.
|
||||
|
||||
**§1 gate re-run this session: GREEN** (fresh dirs; the two crypto legs
|
||||
as SEPARATE processes; spike probes correctly absent — deleted in
|
||||
M4.5c):
|
||||
|
||||
```
|
||||
:core:data-jvm:smoke RESULT: M1a PASS, exit 0
|
||||
:desktopApp:run … --self-test SELFTEST id=1 → RENDER, exit 0
|
||||
assembleDebug BUILD SUCCESSFUL, exit 0
|
||||
crypto leg A (own process) leg-A ALL-OK (9×PASS), exit 0
|
||||
crypto leg B (own process) LEG-B PASS, leg-B ALL-OK, exit 0
|
||||
```
|
||||
|
||||
**M5.1 — Esc routing + keyboard shortcuts: DONE.**
|
||||
|
||||
- `PlatformBackHandler`'s JVM actual is no longer a no-op:
|
||||
`PlatformBackStack` + `LocalPlatformBackStack` (composeApp jvmMain).
|
||||
Entries are position-stable (remembered object, callback slot
|
||||
refreshed per composition) so a lower screen's recomposition can never
|
||||
jump above the editor. `dispatchBack()` runs the topmost ENABLED
|
||||
entry, false = unconsumed so Esc still reaches popups.
|
||||
- `Main.kt` provides the stack and drains it from
|
||||
`Window(onPreviewKeyEvent)` on Esc (logs `esc(captured)` for manual
|
||||
verification). **The editor changed zero lines** — its commonMain
|
||||
`BackHandler { tryClose() }` rides the seam, so desktop Esc gets the
|
||||
draft flush + "Discard changes?" prompt exactly like Android.
|
||||
- `DesktopShell` registers Esc for drawer + settings; shortcuts **Ctrl+N**
|
||||
(new note) and **Ctrl+comma** (settings) go on `onPreviewKeyEvent` —
|
||||
preview phase wins over focused text fields.
|
||||
- New `--keys-smoke` leg drives the window's exact dispatch
|
||||
(`dispatchBack`) headlessly: clean-editor Esc closes, nothing-enabled
|
||||
does NOT consume, settings Esc closes. One fix en route: the KEYS-leg
|
||||
settings mirror needed `LaunchedEffect(showSettings)` sync or leg (c)
|
||||
read a stale mirror.
|
||||
- **Pending-manual:** real keypresses could not be verified headless —
|
||||
KWin under Wayland does not deliver xdotool XTEST events to the
|
||||
XWayland window (focus probes confirmed the app HAS focus; zero
|
||||
events arrived). One real Esc + Ctrl+N at the desk is the outstanding
|
||||
check; `esc(captured)` logs on the console when it works.
|
||||
|
||||
```
|
||||
M5.1 suite:
|
||||
assembleDebug :composeApp:compileKotlinJvm :desktopApp:build BUILD SUCCESSFUL
|
||||
:desktopApp:run … --keys-smoke KEYS ALL-OK (editor/no-consume/settings 3×PASS), exit 0
|
||||
:desktopApp:run … --self-test SELFTEST id=1, exit 0
|
||||
:desktopApp:run … --settings-smoke SETTINGS shown, exit 0
|
||||
:desktopApp:run … --editor-smoke EDITOR shown, exit 0
|
||||
:core:data-jvm:smoke RESULT: M1a PASS
|
||||
```
|
||||
|
||||
**Next up: M5.2** — tray + single-instance + first-run onboarding.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user