Native windows, tray, and events
Rowel uses a Tauri native host to control the desktop window, keep the app available from the system tray, and carry operating-system events into the web UI. The host also owns behavior that must remain reliable when the UI is hidden or suspended, such as auto-lock, clipboard expiry, locale selection, and file opening. See the parent page Desktop platform integration for the wider host boundary and Tauri command bridge for request-and-response calls.
Native window lifecycle
The main window is created hidden so the user sees a prepared splash rather than an empty webview. The frontend receives the small set of state needed for its first frame before its scripts run, then reads the full app snapshot through app_status; it signals readiness with app_ready. A short fallback also reveals the window if the frontend cannot make that call. Both paths share a one-time reveal gate, so a later tray action or file-open request cannot unexpectedly reopen a window that the user closed.
The startup path is:
- The native host reads the main-window configuration and creates the webview.
- The host injects the initial locale and settings needed for the first frame.
- The frontend starts its splash and calls
app_ready. - The frontend probes the complete non-secret app snapshot through
app_status. - The host shows and focuses the window. If readiness does not arrive in time, the fallback performs the reveal.
This sequence keeps native window state and UI state aligned. The initial boot data is limited to values needed for the first painted frame, so later changes come from a fresh app snapshot rather than stale data held by a reloaded webview. External HTTP and HTTPS navigation leaves the app and opens in the operating-system browser instead of replacing the app content.
After reveal, the window continues to coordinate native work. Window activity feeds auto-lock, mobile focus resume checks pending sync consent work, and drag-and-drop paths receive purpose-specific read grants before the UI reads them. This keeps dropped images and environment files on the correct import path.
This diagram shows how first-frame data, frontend readiness, and the full app snapshot fit into window startup.
flowchart LR
A[Native app start] --> B[Create hidden main window]
B --> C[Inject first-frame locale and settings]
C --> D[Frontend starts splash]
D --> E[app_ready]
D --> F[Fallback reveal]
D --> G[app_status snapshot]
E --> H[Reveal once]
F --> H
H --> I[Show and focus window]
G --> J[Hydrate UI state]
Initial app state
The initial app state is split by timing. Boot data gives the first frame its locale and settings, while app_status gives the running UI one consistent view of setup state, preferences, sync state, biometric state, and workspaces. The snapshot can run while the app is locked because it excludes secrets, so the lock screen and later screens use the same source for their non-secret state.
References: src-tauri/…/app.rs• L15-40 src-tauri/…/app.rs• L60-129 src-tauri/…/app.rs• L132-172
Tray integration
The desktop tray gives the app a persistent control surface after the main window is hidden. Its actions map to the same session and window behavior used elsewhere in the app, so locking from the tray produces the normal lock event and opening the app restores focus to the main window.
| Tray action | User-visible result |
|---|---|
| Open Rowel | Shows, unminimizes, and focuses the main window. |
| Lock vault | Ends the active vault session through the normal lock path. |
| About | Opens the Rowel website in the system browser. |
| Quit | Exits the native application. |
The tray menu is built before the webview is available and remains alive after the window is closed. It therefore uses the native locale table rather than the web UI translation service. When the user changes language, the saved preference and the tray labels are updated together. A language that is not shipped falls back to the operating-system locale and then to English.
Locale and zoom controls
Locale selection
Locale choice has two sources: an explicit user preference or the operating system. The native host resolves the OS value to a locale that Rowel supports, while the frontend uses the same resolved value for its catalogue. With no explicit choice, a later launch continues to follow the OS rather than storing the first detected language as a permanent choice.
The tray follows the same choice as the web UI. This matters because the tray can remain visible when the webview is not running or when the main window is closed.
References: src-tauri/…/locale.rs• L1-8 src-tauri/…/locale.rs• L13-18 src-tauri/…/locale.rs• L50-75 src/…/prefs.ts• L199-209
macOS window zoom
macOS window zoom is coordinated with web content so the page changes size during the native animation instead of jumping after it ends. The host handles the operating-system zoom routes, keeps the previous frame for restore, and ignores a new zoom request while an animation is still active. Other platforms use their normal native window behavior.
References: src-tauri/…/lib.rs• L41-49 src-tauri/…/window.rs• L49-55 src-tauri/…/zoom.rs• L1-27 src-tauri/…/zoom.rs• L84-121
Timer behavior
Inactivity lock
Auto-lock protects an open session when the user stops interacting with the app. Activity in the webview and window focus changes reset one shared deadline. When the window returns from the background, the host also checks elapsed wall-clock time, so sleep or mobile suspension cannot turn a long absence into a fresh full timeout.
Changing the auto-lock preference takes effect for the current session. Ending a session removes its pending lock deadline, which prevents an old timer from locking a later session.
References: src-tauri/…/autolock.rs• L15-37 src-tauri/…/autolock.rs• L83-123 src-tauri/…/autolock.rs• L125-168
Reusable one-shot timers
The native timer service keeps one pending callback and replaces it when a new deadline is armed. It serves delayed work such as auto-lock and clipboard clearing without creating a sleeping thread for every user action. A callback is removed before it runs, and a callback failure does not stop future timers.
References: src-tauri/…/timer.rs• L1-23 src-tauri/…/timer.rs• L25-85 src-tauri/…/clipboard.rs• L133-182 src-tauri/…/state.rs• L260-266
Clipboard expiry
Copied secrets can have a delay or can remain until the session ends. A delayed clear only removes the value if the clipboard still contains the exact value Rowel wrote. This prevents an older deadline from deleting text that the user copied later. On iOS, the system pasteboard expiry is used because the app may be suspended while its own timer is not running.
References: src-tauri/…/clipboard.rs• L133-148 src-tauri/…/clipboard.rs• L150-182 src-tauri/…/settings.rs• L104-119
Desktop event delivery
Native events carry changes that do not fit a single frontend request. The Rust host defines the event name and payload, emits it through Tauri, and the frontend listens through a typed event catalogue. Store subscribers then turn the event into one state change or refresh, which lets React screens respond without knowing which native action caused it.
The delivery path is:
sequenceDiagram
participant OS as Operating system or native task
participant Rust as Tauri host
participant Bridge as Typed event API
participant Store as Frontend stores
participant UI as User interface
OS->>Rust: Focus, file-open, tray, or background event
Rust->>Rust: Update native state
Rust-->>Bridge: Emit named payload
Bridge-->>Store: Listen and validate payload shape
Store-->>UI: Update state or refresh data
Event contracts
The event catalogue uses complete state snapshots where order could otherwise matter. For example, sync status is sent as one status value rather than as a series of transitions. Vault merges send the refreshed entry metadata, while a lock carries no payload because the frontend always performs the same session cleanup.
| Event group | Meaning at the UI boundary |
|---|---|
vault:locked | Clear session data and show the lock screen. |
vault:merged | Replace the visible entry metadata and refresh related views. |
sync:status | Store the latest whole sync state. |
import:progress | Update progress for a long import. |
setup:drive:* | Move the first-run Drive flow through pending, result, or error. |
workspaces:* | Refresh remote workspace choices or names. |
file:opened | Hold a backup path until a screen can import or restore it. |
browser:associate | Ask the UI to approve a browser extension connection. |
browser:passkey | Ask the UI to approve a browser passkey action and select its account when needed. |
browser:clients | Refresh the browser extension connections after consent. |
Browser extension events carry request identifiers when the UI must answer one specific request. The passkey event also carries the ceremony type and the account choices needed by the dialog. A completed connection emits a separate refresh signal because the UI reads the current client list from the app state rather than treating the event as the list itself.
References: src-tauri/…/events.rs• L1-33 src-tauri/…/events.rs• L35-63 src-tauri/…/events.rs• L65-121 src-tauri/…/events.rs• L123-145 src-tauri/…/events.rs• L147-229 src/…/events.ts• L6-18 src/…/events.ts• L19-63
File association flow
Desktop file associations let the operating system open .rowel backups and .swftx legacy vaults with Rowel. At launch, the native host parks the first valid path because the webview is not listening yet. After the UI subscribes, it takes that parked path once; files opened while the app is running arrive as file:opened events.
The frontend keeps the path across lock and flow changes. A fresh install offers it to the restore flow, while an unlocked vault routes it to Settings so the import action is shown at the right time. When the app is already revealed, the native host raises and focuses the window for a file opened by the operating system. During startup, it leaves the reveal to the normal splash sequence so the window does not appear without its prepared first frame.
References: src-tauri/…/opened.rs• L1-14 src-tauri/…/opened.rs• L27-45 src-tauri/…/lib.rs• L148-159 src-tauri/…/lib.rs• L238-246 src-tauri/…/window.rs• L136-145 src/App.tsx• L52-81 src/…/app.ts• L281-298
UI event subscriptions
The top-level app subscribes once after its first render and removes the listeners when it unmounts. The subscription layer owns the cross-cutting reactions: a lock clears session state, a vault merge refreshes rows and audit data, and a workspace rename re-reads the app snapshot. Feature screens consume the resulting store state instead of subscribing to native events directly.
References: src/App.tsx• L52-81 src/…/events.ts• L37-75 src/…/app.ts• L239-262
Change checklist
When these files or sections are changed, remember to consider these:
- Keep every Rust event name and payload aligned with src/…/events.ts; a renamed event can fail silently if one side still listens to the old name.
- Keep request identifiers aligned between browser event payloads and their response commands; a dialog that answers a stale identifier can complete the wrong browser request.
- Keep the launch file path handoff ordered: subscribe before taking the parked path so a backup opened during startup is not missed.
- Keep the tray locale set aligned with the supported locale set; otherwise the web UI and tray can show different languages.
- Keep all lock sources on the
vault:lockedpath so tray locks, idle locks, manual locks, and workspace changes clear the same frontend session state. - Keep timer-backed preferences normalized before arming a timer; an on-screen timeout must match the deadline enforced by the native host.
- Keep the boot payload limited to first-frame values; state that can change during a session belongs in the
app_statussnapshot. - When changing the reveal sequence, preserve both the frontend readiness call and the fallback path so a failed bundle cannot leave the native window permanently hidden.
- Keep drag-and-drop file classification aligned with the path grant purpose; the UI must receive image and environment-file paths with the access needed by their import flow.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
The frontend does not call app_ready. | The main window stays hidden until the startup delay ends. | The native fallback reveal runs independently and the reveal gate prevents duplicate shows. |
| The app snapshot mixes reads from different workspaces. | The UI can show one workspace's sync or setup state under another workspace's name. | The native snapshot holds the workspace boundary while it reads the related state. |
| A window returns after the device slept or a mobile app was suspended. | A timer based only on elapsed process time could give the user a fresh timeout. | Focus resume compares wall-clock absence with the configured timeout. |
| An old clipboard deadline fires after a newer copy. | The newer clipboard value could be erased. | The clear checks both the copy generation and the exact current clipboard text. |
| A backup opens before the webview subscribes. | A live event alone would be lost. | The native host parks one path and the frontend takes it after subscription. |
| A browser dialog answers after its request is no longer current. | A response can be applied to a later extension request. | Browser event payloads carry the request identifier and response commands match it. |
| A lock is handled only by the caller that requested it. | Some lock sources could leave sensitive rows or UI state in memory. | All lock sources end in one native lock event and one frontend reaction. |
| A supported locale is added only to the web catalogue. | The web UI changes language while the tray falls back to English. | The native locale set and tray label table are checked against each other. |
| A dropped file receives the wrong path grant. | The import flow can reject a valid file or read it with the wrong file rules. | The native drop handler classifies the path before it grants access. |
Key files
| File | Why to read it |
|---|---|
| src-tauri/…/lib.rs | Shows native startup, plugin setup, window and tray creation, command registration, and desktop run events. |
| src-tauri/…/window.rs | Defines hidden-window startup, readiness reveal, focus behavior, external navigation, drag-and-drop path grants, and window event handling. |
| src-tauri/…/tray.rs | Defines tray actions, native labels, and language updates outside the webview. |
| src-tauri/…/app.rs | Defines the first-frame boot data, the launch app snapshot, readiness signal, parked file handoff, and settings update path. |
| src-tauri/…/events.rs | Defines the native event names and payloads sent to the frontend. |
| src/…/events.ts | Defines the matching typed event contract used by frontend listeners. |
| src/…/events.ts | Connects native events to app, vault, sync, and UI state changes. |
| src-tauri/…/autolock.rs | Explains focus-aware inactivity locking and its timer rules. |
| src-tauri/…/timer.rs | Defines the shared one-shot timer behavior used by delayed native actions. |
| src-tauri/…/opened.rs | Explains desktop backup file association delivery at launch and while running. |
| src/App.tsx | Shows when subscriptions start and how the initial parked file is collected. |
| src/…/app.ts | Shows how file-open events and lock events affect the user-facing flow. |