feat(phase-1/m5.2): tray + single-instance lock + first-run onboarding
SingleInstanceLock (OS FileLock on <dataDir>/incido.lock) claims the library before the container starts; a second launch prints INSTANCE and exits 0 — which also converts the wedged-child trap into a clean message. Tray (ApplicationScope extension; Item/Separator menu) attaches only for non-scripted, non-headless, SystemTray-capable sessions; close=quit kept. First-run dialog explains the per-machine library + backup bridge, gated on onboarded_v1 in the window store. Two new §3 traps recorded (Window iconBitmap overload ambiguity; Tray receiver/params) + new harness legs in §1. Verify: second launch same dir (INSTANCE ... exits, 0); interactive run (TRAY attached, live KDE SNI); :desktopApp:run --args="--data-dir /tmp/incido-m52-ob --onboarding-smoke --exit-after 8" (shown=true, flag-persisted=true PASS) then --onboarding-verify (shown=false gate respected); --keys-smoke KEYS ALL-OK; --self-test id=1; :core:data-jvm:smoke M1a PASS; assembleDebug SUCCESSFUL.
This commit is contained in:
1 parent
639f39d187
commit
0cad7729aa
7 files changed
+255
No files matched your search
@@ -49,11 +49,15 @@ 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.Tray
|
||||
import androidx.compose.ui.window.Window
|
||||
import androidx.compose.ui.window.application
|
||||
import androidx.compose.ui.window.rememberWindowState
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.datastore.preferences.core.booleanPreferencesKey
|
||||
import androidx.datastore.preferences.core.edit
|
||||
import androidx.datastore.preferences.core.intPreferencesKey
|
||||
import java.awt.GraphicsEnvironment
|
||||
import java.io.File
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.FileOutputStream
|
||||
@@ -121,6 +125,11 @@ fun main(args: Array<String>) {
|
||||
val cryptoSelfTest = "--crypto-self-test" in args
|
||||
val cryptoReopen = "--crypto-reopen" in args
|
||||
val cryptoPassphrase = args.argAfter("--crypto-passphrase") ?: "selftest-passphrase"
|
||||
// M5.2 scripted onboarding legs: --onboarding-smoke on a FRESH dir
|
||||
// asserts the dialog shows and its dismiss persists the flag;
|
||||
// --onboarding-verify on the SAME dir asserts the flag gates it off.
|
||||
val onboardingSmoke = "--onboarding-smoke" in args
|
||||
val onboardingVerify = "--onboarding-verify" in args
|
||||
// Recovery-envelope file legs: --key-export writes the INCKEY1 envelope
|
||||
// the phone's Settings screen writes; --key-import reads one (e.g. a
|
||||
// REAL phone export) with the passphrase and installs the key — the
|
||||
@@ -132,6 +141,16 @@ fun main(args: Array<String>) {
|
||||
println("JVM : ${System.getProperty("java.vendor")} ${System.getProperty("java.version")}")
|
||||
println("library : $dataDir")
|
||||
|
||||
// M5.2: single-instance claim BEFORE the container opens the library.
|
||||
// The §3 trap (a wedged AWT child still holding ObjectBox's
|
||||
// single-writer lock) surfaces here as a clean message instead of a
|
||||
// half-initialized crash — the OS FileLock dies with its process.
|
||||
val instanceHandle = SingleInstanceLock(dataDir).tryAcquire()
|
||||
if (instanceHandle == null) {
|
||||
println("INSTANCE another Incido already owns $dataDir — this copy exits")
|
||||
return
|
||||
}
|
||||
|
||||
val app = DesktopContainer(dataDir)
|
||||
|
||||
// M5.1: the desktop back stack. PlatformBackHandler (composeApp jvm
|
||||
@@ -149,16 +168,49 @@ fun main(args: Array<String>) {
|
||||
?.coerceIn(640, 8_000) ?: 1100
|
||||
val savedHeight = windowPrefs[intPreferencesKey("window_height")]
|
||||
?.coerceIn(480, 8_000) ?: 760
|
||||
// M5.2: first-run state lives in the desktop-only window store (same
|
||||
// rule as geometry — settings keeps the phone-shared schema).
|
||||
val onboarded = windowPrefs[booleanPreferencesKey("onboarded_v1")] == true
|
||||
// Other scripted legs suppress tray chrome AND the first-run overlay —
|
||||
// their assertions ride the bare shell. --onboarding-* legs are the
|
||||
// exception: they exercise the overlay's own gate (fresh vs onboarded).
|
||||
val otherScriptedLeg = selfTest || settingsSmoke || editorSmoke || keysSmoke ||
|
||||
cryptoSelfTest || cryptoReopen ||
|
||||
backupImport != null || backupExport != null || backupExportEnc != null ||
|
||||
keyExport != null || keyImport != null
|
||||
val attachTray = !(otherScriptedLeg || onboardingSmoke || onboardingVerify) &&
|
||||
!GraphicsEnvironment.isHeadless() && java.awt.SystemTray.isSupported()
|
||||
|
||||
application {
|
||||
val windowState = rememberWindowState(
|
||||
width = savedWidth.dp,
|
||||
height = savedHeight.dp,
|
||||
)
|
||||
// M5.2: tray (ApplicationScope receiver — sibling of Window, not
|
||||
// inside its content). Closing the window still QUITS (no
|
||||
// hide-to-tray): exitApplication semantics stay, and every
|
||||
// harness leg keeps its teardown; the tray restores from
|
||||
// minimized and offers a quick Quit.
|
||||
if (attachTray) {
|
||||
Tray(
|
||||
icon = painterResource("tray_icon.png"),
|
||||
tooltip = "Incido",
|
||||
menu = {
|
||||
Item("Show Incido") { windowState.isMinimized = false }
|
||||
Separator()
|
||||
Item("Quit Incido") { exitApplication() }
|
||||
},
|
||||
)
|
||||
LaunchedEffect(Unit) { println("TRAY attached") }
|
||||
}
|
||||
Window(
|
||||
onCloseRequest = ::exitApplication,
|
||||
state = windowState,
|
||||
title = "Incido",
|
||||
// NOTE: the 1.7.3 Window overloads go ambiguous if the
|
||||
// iconBitmap arg is added here — window/taskbar icon comes
|
||||
// from the jpackage distribution icon instead (M5.3), and
|
||||
// app_icon_32.png ships for that purpose.
|
||||
// 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
|
||||
@@ -184,6 +236,9 @@ fun main(args: Array<String>) {
|
||||
settingsSmoke = settingsSmoke,
|
||||
editorSmoke = editorSmoke,
|
||||
keysSmoke = keysSmoke,
|
||||
showFirstRun = !onboarded && !otherScriptedLeg,
|
||||
onboardingSmoke = onboardingSmoke,
|
||||
onboardingVerify = onboardingVerify,
|
||||
backupImport = backupImport,
|
||||
backupExport = backupExport,
|
||||
backupExportEnc = backupExportEnc,
|
||||
@@ -214,6 +269,9 @@ private fun NotesWindow(
|
||||
settingsSmoke: Boolean,
|
||||
editorSmoke: Boolean,
|
||||
keysSmoke: Boolean,
|
||||
showFirstRun: Boolean,
|
||||
onboardingSmoke: Boolean,
|
||||
onboardingVerify: Boolean,
|
||||
backupImport: String?,
|
||||
backupExport: String?,
|
||||
backupExportEnc: String?,
|
||||
@@ -230,6 +288,41 @@ private fun NotesWindow(
|
||||
// M4.5: the real settings screen replaces the M1b placeholder list.
|
||||
var showSettings by remember { mutableStateOf(false) }
|
||||
|
||||
// M5.2: first-run onboarding state. dismissWelcome is the EXACT
|
||||
// callback the dialog's buttons call, so the smoke leg asserting
|
||||
// through it asserts the real path.
|
||||
var showWelcome by remember { mutableStateOf(showFirstRun) }
|
||||
val uiScope = rememberCoroutineScope()
|
||||
fun dismissWelcome(openSettings: Boolean) {
|
||||
showWelcome = false
|
||||
uiScope.launch {
|
||||
windowStore.edit { it[booleanPreferencesKey("onboarded_v1")] = true }
|
||||
}
|
||||
if (openSettings) showSettings = true
|
||||
}
|
||||
if (onboardingSmoke) {
|
||||
LaunchedEffect(Unit) {
|
||||
delay(1500)
|
||||
val shownFresh = showWelcome
|
||||
println("ONBOARD fresh-run shown=$shownFresh ${if (shownFresh) "PASS" else "FAIL"}")
|
||||
if (shownFresh) {
|
||||
dismissWelcome(false)
|
||||
delay(800)
|
||||
val flag = windowStore.data.first()[booleanPreferencesKey("onboarded_v1")] == true
|
||||
println("ONBOARD flag-persisted=$flag ${if (flag) "PASS" else "FAIL"}")
|
||||
}
|
||||
}
|
||||
}
|
||||
if (onboardingVerify) {
|
||||
LaunchedEffect(Unit) {
|
||||
delay(1500)
|
||||
println(
|
||||
"ONBOARD reopened shown=$showWelcome " +
|
||||
(if (!showWelcome) "PASS (gate respected)" else "FAIL (flag ignored!)"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// M3: theme_mode is a real shared setting here — resolveDark picks the
|
||||
// scheme. M4.5b: the app's OWN IncidoTheme wraps the shell — the
|
||||
// shared screens get the exact color scheme + typography the phone
|
||||
@@ -251,6 +344,15 @@ private fun NotesWindow(
|
||||
)
|
||||
}
|
||||
|
||||
// M5.2: first-run overlay, above whichever screen the shell renders.
|
||||
if (showWelcome) {
|
||||
FirstRunDialog(
|
||||
dataDirPath = app.dataDir.absolutePath,
|
||||
onStartWriting = { dismissWelcome(false) },
|
||||
onImportFromPhone = { dismissWelcome(true) },
|
||||
)
|
||||
}
|
||||
|
||||
LaunchedEffect(notes.size) {
|
||||
// Logged on every change: proves the ObjectBox subscription actually
|
||||
// delivers to the composition (the first frame is always the empty
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package org.incido.desktop
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
|
||||
/**
|
||||
* M5.2 — first-run onboarding.
|
||||
*
|
||||
* Says the one thing a new desktop user must not guess (Development
|
||||
* Plan §6 product decision): this library lives on THIS machine, and the
|
||||
* encrypted backup file is the only bridge to the phone. Never shown
|
||||
* once the `onboarded_v1` window-store flag is set, never shown for
|
||||
* scripted smoke legs.
|
||||
*
|
||||
* `Dialog` here is `androidx.compose.ui.window.Dialog` — the §3 trap:
|
||||
* material3 ships AlertDialog, not Dialog.
|
||||
*/
|
||||
@Composable
|
||||
fun FirstRunDialog(
|
||||
dataDirPath: String,
|
||||
onStartWriting: () -> Unit,
|
||||
onImportFromPhone: () -> Unit,
|
||||
) {
|
||||
Dialog(onDismissRequest = onStartWriting) {
|
||||
Card(Modifier.fillMaxWidth()) {
|
||||
Column(Modifier.padding(24.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
Text("Welcome to Incido", style = MaterialTheme.typography.headlineSmall)
|
||||
Text(
|
||||
"Your notes library lives on this machine, in\n" +
|
||||
"$dataDirPath\n" +
|
||||
"It stays private and offline. The only bridge to your " +
|
||||
"phone is the encrypted backup file you create in " +
|
||||
"Settings \u25B8 Backup \u2014 export there, import here.",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
Row(
|
||||
Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.End,
|
||||
) {
|
||||
TextButton(onClick = onImportFromPhone) { Text("Import from phone backup") }
|
||||
TextButton(onClick = onStartWriting) { Text("Start writing") }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.incido.desktop
|
||||
|
||||
import java.io.File
|
||||
import java.nio.channels.FileChannel
|
||||
import java.nio.file.StandardOpenOption
|
||||
|
||||
/**
|
||||
* M5.2 — per-library single-instance guard.
|
||||
*
|
||||
* ObjectBox's single-writer lock and DataStore's file lock are crash
|
||||
* recovery, not coexistence: a second launch against the same data dir
|
||||
* would wedge on them (or worse, interleave writes). An OS `FileLock`
|
||||
* dies with its process — even on `kill -9` — so it needs no stale-file
|
||||
* cleanup, unlike a pid file.
|
||||
*/
|
||||
class SingleInstanceLock(private val dataDir: File) {
|
||||
|
||||
/**
|
||||
* Non-blocking claim. Returns the handle to keep for the process
|
||||
* lifetime, or null when another live process owns [dataDir].
|
||||
*/
|
||||
fun tryAcquire(): AutoCloseable? {
|
||||
val channel = FileChannel.open(
|
||||
File(dataDir, "incido.lock").toPath(),
|
||||
StandardOpenOption.CREATE,
|
||||
StandardOpenOption.WRITE,
|
||||
)
|
||||
val lock = runCatching { channel.tryLock() }.getOrNull()
|
||||
if (lock == null) {
|
||||
channel.close()
|
||||
return null
|
||||
}
|
||||
return AutoCloseable {
|
||||
runCatching { lock.release() }
|
||||
runCatching { channel.close() }
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.4 KiB |
Reference in new issue
Block a user