Repository navigation
Refresh the tray database menu live, and restore the open marker - #2042
Merged
Merged
Conversation
The Databases submenu was built once, right after the default database opened, and nothing pushed again — so it showed the registry exactly as it was at daemon boot. A database created, renamed or removed afterwards, or opened by a switch, or closed by the idle reaper, read wrong until the daemon restarted. DatabaseManager now publishes a change signal on every registry and open-set mutation, and the daemon forwards it to the tray for the life of the process. The signal is a counter rather than the snapshot: building a snapshot takes the same locks the mutation holds, so publishing one from inside a mutation would invite a deadlock. Observers re-read after waking, which also collapses a burst of changes into a single refresh, and every notify fires after its locks are released. That makes the open marker safe to show again. It was deliberately left out of the first slice because a marker pushed once at boot would be confidently wrong within minutes — the idle reaper closes databases and in-app switching opens others. With the menu rebuilt on every change it now tracks reality, so the label reads "name — default · open · synced" in a fixed marker order (a reshuffling label would read as flicker under live updates). Missing still suppresses every other marker. The test asserting open state was absent now asserts it is present; it pinned the old deliberate omission, not a property worth keeping. Tests cover the signal on create/rename/remove and on open/evict, and were confirmed to fail with notify_changed stubbed out. Does not address the other half of the issue — picking a database while the app is already running should switch it in place and focus the window, and there should be exactly one app instance regardless of launch path. Both need cross-process focus and a single-instance plugin, which cannot be exercised without a desktop session. Co-Authored-By: Claude Opus 5 <[email protected]>
5 tasks done
mstomar125
added a commit
that referenced
this pull request
Aug 20, 2026
#2180) * Focus and switch the running app when picking a database from the tray (closes #2040) open_ui previously no-op'd (or, when the app was launched outside the tray, silently spawned a second process) whenever it tried to check whether a UI process was already alive — the daemon has no reliable way to know that, especially for a process it never spawned itself. Delegate dedup to the app instead of tracking it in the daemon: tauri-plugin-single-instance now guards the desktop app, so open_ui always spawns a fresh UI process and a genuinely-second launch detects the running instance, forwards its argv, and exits immediately. The requested database rides both the existing INITIAL_DATABASE_ENV (read by a cold launch at startup) and a new `--database <id>` CLI arg (the only thing visible to an already-running instance's relaunch handler, since a spawned-then-immediately-exited process's environment is not). The relaunch handler focuses the main window (unminimize + show + set_focus, the cross-process equivalent of NSRunningApplication:: activate on every desktop platform Tauri targets) and, when a database was requested, emits `tray:select-database` so the frontend switches in place through the same databaseStore.switchTo path an in-app switcher click already uses. Live tray-submenu refresh (registry/open-set changes pushed to the tray without a daemon restart, and the `open` marker) already landed in #2042; this closes the second half of #2040. * Address adversarial review findings on the tray relaunch/switch mechanism - Validate the tray-supplied database id against the registered list before committing to a switch in databaseStore.switchTo, mirroring the registered() guard load() already applies to this exact input. Previously an id for a database removed (or otherwise not registered) between the tray click and the relaunch event arriving would clear every cache and reset the workspace before the daemon's per-request NOT_FOUND ever surfaced, with no rollback. - Add a pull-based fallback for the tray:select-database event: Tauri does not buffer/replay an event emitted with zero current listeners, and the frontend's listener only exists once app-shell.svelte has mounted, so a relaunch landing in that narrow boot window would silently drop the switch (the window still focused correctly). handle_relaunch now also stashes the id in a process-wide slot that the frontend pulls once via a new take_pending_tray_database_selection command right after registering the listener; switchTo is idempotent against the value the live event also happened to deliver. - Log unminimize/show/set_focus failures in handle_relaunch instead of swallowing them silently, matching the emit's existing warn-on-error. - Soften the open_ui/plugin-registration doc comments: this plugin's macOS backend claims its lock with a connect-then-bind probe rather than one atomic OS primitive (Windows uses a named mutex, Linux a D-Bus name claim), so two processes launched in that scheduling gap can theoretically both survive. Not fixable in this codebase; now documented rather than overstated as an absolute guarantee. - Add test coverage for handle_relaunch (generic over the Tauri runtime, like graceful_shutdown/handle_run_event, so it's testable against tauri::test::mock_app()): no-main-window early return, and the full stash/pull/consume cycle for the fallback. Found by a fresh adversarial review agent against the real PR diff.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First half of #2040. Does not close it — see "Not addressed" below.
Problem
The Databases submenu had exactly one push, right after the default database opened, and nothing pushed again. So it showed the registry as it was at daemon boot: a database created, renamed or removed afterwards — or opened by a switch, or closed by the idle reaper — read wrong until the daemon restarted.
Change
DatabaseManager::subscribe_changes()publishes on every registry and open-set mutation (insert_entry, covering create/register;rename;close, covering remove and eviction; andget_or_open's real-open branch).spawn_tray_database_syncin the daemon forwards it to the tray for the life of the process, replacing the two identical one-shot calls (there are two trayserve_grpcvariants).Two decisions worth a look:
RegistrySnapshottakes the same locks the mutation is holding, so publishing one from inside a mutation would invite a deadlock. Observers re-readlist()after waking — which also means a burst of changes collapses into one refresh, sincewatchkeeps only the latest value. Everynotify_changed()fires after its locks are released, so a woken observer cannot deadlock against the mutation that woke it.openmarker is back. Multi-database polish: tray database menu, multi-window, and docs reconciliation #1536 left it out on purpose: pushed once at boot it would be confidently wrong within minutes, because the idle reaper closes databases and in-app switching opens others. With the menu rebuilt on every change it tracks reality. Markers render in a fixed order (default · open · synced) — under live updates a reshuffling label reads as flicker rather than information — andmissingstill suppresses everything else.Tests
missingstill winning.Both signal tests were confirmed to fail with
notify_changedstubbed out.Two notes on the test changes:
open_state_is_not_reflected_in_the_labelwas replaced rather than fixed — it pinned the old deliberate omission, which is exactly what this PR reverses.create()already opens the database, so theget_or_openthat followed was a cache hit and correctly signalled nothing. It now evicts first, then reopens.cargo test -p nodespace-daemongreen ·clippy --all-targets -- -D warningsclean.Not addressed (issue stays open)
The other half — picking a database while the app is already running should switch it in place and focus the window, and there should be exactly one app instance regardless of launch path. That needs cross-process focus (
NSRunningApplication::activateand platform equivalents) plus a single-instance plugin, neither of which can be exercised or verified without a desktop session. So these acceptance boxes remain unticked:Also unrun here:
bun run test:all/quality:fix— this change is Rust-only and the pre-push gate rantest:allplus the e2e suite, but the frontend legs of that acceptance box belong with the UI half.Note
packages/desktop-app/src-tauri/src/commands/nodes.rscarries pre-existingcargo fmtdrift onmain; I kept it out of this commit rather than mixing an unrelated reformat in.Co-Authored-By: Claude Opus 5 [email protected]