You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Window per database: route backend emits to the matching window instead of "main" #2033
Split out of #1536, which flagged this piece as optional and separable ("split if it grows"). #1536 keeps the tray database menu; this issue is the multi-window half.
Problem
The app is single-window and every backend emit targets get_webview_window("main"). With one daemon serving N databases (ADR-053), a user cannot have two databases open side by side, and any event that carries a database_id has nowhere else to go.
Scope
Window label = database id; each window pins its own database id and stamps it on calls.
Replace hardcoded get_webview_window("main") emits in packages/desktop-app/src-tauri/src/lib.rs with routing by the event's database_id to the matching window; fall back to the focused window when an event carries no id.
Persist window state (size/position) per database.
The database_id is already present in the event streams, so this is routing existing data rather than new plumbing.
Acceptance
Two windows on two databases operate concurrently with no event cross-talk
An event carrying a database_id reaches only that database's window
An event with no id reaches the focused window
Window size/position persist per database
bun run test:all green, bun run quality:fix clean
Non-goals
Per-window theming; new sync features; anything beyond routing existing events.
window_routing.rs (new): WindowDatabaseRegistry (a live window-label -> database-id pin map) and emit_routed, the replacement for every previous app.get_webview_window("main") + .emit(...) call. Routes an event carrying a non-empty database_id to only the window(s) pinned to it; falls back to the focused window (deterministic default when nothing is focused) for events with no id. Falls back to broadcast only when no window exists yet, or no window has pinned to a database yet (the real startup gap before the frontend's async pin_window_database call lands) — never a silent drop.
Replaced every get_webview_window("main") site in lib.rs/commands/settings.rs, and watcher.rs's node:*/relationship:* broadcasts (which used to reach every open window regardless of database), with emit_routed.
Fixed a related pre-existing bug the first test against this module caught: handle_relaunch's tray:select-database emit called window.emit(...) believing it was scoped to that window — Emitter::emit's default body always broadcasts regardless of the object it's called on (confirmed against the tauri 2.11 source). Now uses Emitter::emit_to(label, ...).
A window's Tauri label is its database id wherever known at creation time; the bootstrap window (database resolved asynchronously by the frontend) keeps its static "main" label but is tracked in the registry via the new pin_window_database command, called from databaseStore's load()/switchTo().
window_state.rs (new): per-database window size/position persistence — atomic JSON write (shared atomic_file::write_json, also now used by preferences.rs), serialized behind a mutex so concurrent saves can't race, restored via pin_window_database (with a plausibility check rejecting degenerate saved sizes).
Acceptance criteria
Two windows on two databases operate concurrently with no event cross-talk — proven end-to-end in tests/window_routing_no_cross_talk_test.rs: a real spawned daemon, two real registered databases, two concurrent watcher::run tasks, two mock windows pinned to the two databases — a window pinned to database A never receives database B's events.
An event carrying a database_id reaches only that database's window — emit_routed, unit-tested via the pure resolve_targets function and integration-tested against real Tauri window/event APIs.
An event with no id reaches the focused window — same routing function, focused-window fallback with a deterministic no-focus default.
bun run test:all green, bun run quality:fix clean — confirmed on every push through the pre-push gate (which runs test:all plus the full cargo test -p nodespace-app Tauri-seam suite).
Scope note
The daemon already supports genuine concurrent multi-database live streaming (independently opened WatchNodes streams per database), but this PR does not wire up N concurrent watcher::run tasks in production or make the shared GrpcClient per-window for outbound commands — both are larger changes, and there is no way to open a second window in the shipped app yet regardless (tauri-plugin-single-instance, from #2180, dedupes any second launch into an in-place switch). This PR is the client-side event-routing foundation; wiring real concurrent windows is a follow-up once an "open a second window" UX exists.
Not independently verified (no GUI console)
Actual multi-window rendering — two real OS windows on screen, resized/dragged, showing different databases — needs a real desktop session, and there's no way to open a second window from the shipped UI yet regardless. Covered instead: the routing decision in isolation (pure-function unit tests), the real Tauri event/window APIs wired correctly (mock_app() tests), and the real production watcher + routing path against a real daemon with two real databases (the integration test above).
Activity
Address adversarial review findings on the window-routing PR
Route backend emits to the matching window instead of "main" (#2184)
mstomar125 commentedon Aug 20, 2026
Done via #2184 (merged
ab5bb47f).What shipped
window_routing.rs(new):WindowDatabaseRegistry(a live window-label -> database-id pin map) andemit_routed, the replacement for every previousapp.get_webview_window("main")+.emit(...)call. Routes an event carrying a non-emptydatabase_idto only the window(s) pinned to it; falls back to the focused window (deterministic default when nothing is focused) for events with no id. Falls back to broadcast only when no window exists yet, or no window has pinned to a database yet (the real startup gap before the frontend's asyncpin_window_databasecall lands) — never a silent drop.get_webview_window("main")site inlib.rs/commands/settings.rs, andwatcher.rs'snode:*/relationship:*broadcasts (which used to reach every open window regardless of database), withemit_routed.handle_relaunch'stray:select-databaseemit calledwindow.emit(...)believing it was scoped to that window —Emitter::emit's default body always broadcasts regardless of the object it's called on (confirmed against thetauri2.11 source). Now usesEmitter::emit_to(label, ...)."main"label but is tracked in the registry via the newpin_window_databasecommand, called fromdatabaseStore'sload()/switchTo().window_state.rs(new): per-database window size/position persistence — atomic JSON write (sharedatomic_file::write_json, also now used bypreferences.rs), serialized behind a mutex so concurrent saves can't race, restored viapin_window_database(with a plausibility check rejecting degenerate saved sizes).Acceptance criteria
tests/window_routing_no_cross_talk_test.rs: a real spawned daemon, two real registered databases, two concurrentwatcher::runtasks, two mock windows pinned to the two databases — a window pinned to database A never receives database B's events.database_idreaches only that database's window —emit_routed, unit-tested via the pureresolve_targetsfunction and integration-tested against real Tauri window/event APIs.window_state.rs, save/restore round-trip tested, concurrent-save safety tested.bun run test:allgreen,bun run quality:fixclean — confirmed on every push through the pre-push gate (which runstest:allplus the fullcargo test -p nodespace-appTauri-seam suite).Scope note
The daemon already supports genuine concurrent multi-database live streaming (independently opened
WatchNodesstreams per database), but this PR does not wire up N concurrentwatcher::runtasks in production or make the sharedGrpcClientper-window for outbound commands — both are larger changes, and there is no way to open a second window in the shipped app yet regardless (tauri-plugin-single-instance, from #2180, dedupes any second launch into an in-place switch). This PR is the client-side event-routing foundation; wiring real concurrent windows is a follow-up once an "open a second window" UX exists.Not independently verified (no GUI console)
Actual multi-window rendering — two real OS windows on screen, resized/dragged, showing different databases — needs a real desktop session, and there's no way to open a second window from the shipped UI yet regardless. Covered instead: the routing decision in isolation (pure-function unit tests), the real Tauri event/window APIs wired correctly (
mock_app()tests), and the real production watcher + routing path against a real daemon with two real databases (the integration test above).