Introducing a new way to review your PRs.

Read the announcement

crmne / zapfast

ZapFast: a fast, native WhatsApp client in Rust and egui

View on GitHub

19 documents · Updated Nov 18, 2026

docs / application-shell

Desktop application shell

ZapFast's desktop application shell turns a process start into one resident client. It owns the running instance, the window and tray lifecycle, shared application state, and the top-level route between account access, chats, calls, and settings.

Startup and runtime ownership

Startup sequence

Startup validates the launch request before it creates user state or a window. It then prepares local paths and logging, loads settings, creates the application state, and gives that state to the desktop shell.

The startup path also accepts targets from desktop links. A target can name a chat or a group invite. The first process queues that request for its first frame, while a later process sends it to the resident process.

flowchart TD
    A[Desktop launch] --> B[Parse control or target]
    B -->|control| C[Send to resident process]
    B -->|chat or invite target| D[Claim single-instance slot]
    B -->|ordinary launch| D
    D -->|existing process| E[Resident process handles request]
    D -->|first process| F[Prepare paths, logs, and settings]
    F --> G[Create application state]
    G --> H[Start resident desktop shell]
    H --> I[Create or defer the window]

References: src/main.rs• L203-365 src/main.rs• L372-434 src/app.rs• L1397-1477

Single-instance coordination

The single-instance service keeps one linked client for each user. A later launch does not open a second window beside the first one. It sends a small command to the resident process and exits.

The supported requests cover the shell's external entry points:

  • Show or ping the resident client.
  • Open a chat or group invite from a desktop link.
  • Reload themes without opening a window.
  • Quit through the same path as the tray menu.

The request is checked before it enters the application queue. If an older client does not understand a request, the new launch brings that client forward instead of risking two clients using the same local data.

References: src/single_instance.rs• L34-62 src/single_instance.rs• L86-118 src/single_instance.rs• L225-245 src/main.rs• L247-290

Resident lifecycle

The process can remain alive when its window is gone. This supports background login, tray use, notification clicks, and later launches. A close request becomes either hide, reopen, or quit according to the platform and the user's background-running choice.

The shell creates a window when the resident state asks to show one. On Wayland, it can replace a hidden or covered window because the compositor may reject a direct focus request. On other platforms, it restores and focuses the existing window.

References: src/app.rs• L1216-1267 src/app.rs• L1346-1352 src/app.rs• L2222-2275 src/app.rs• L10027-10060

Shared application state

Application state model

App is the shared state for the resident process and its current window. It combines settings, account state, connection state, the current page and chat, transient overlays, notifications, and queued user actions. Views read this state and queue actions rather than changing the route in the middle of drawing.

This split keeps the product state alive across window recreation. It also lets background events, tray commands, notifications, and desktop links use the same route as direct user input.

References: src/app.rs• L1-4 src/app.rs• L450-477 src/model.rs• L2708-2724 src/app.rs• L11394-11459

Frame lifecycle

Each frame has a state pass and a drawing pass. The state pass handles background events, power changes, tray input, single-instance commands, notifications, theme updates, backend events, and queued actions. The drawing pass applies the current theme, handles visible input, draws the shared UI, and applies actions produced by that UI.

flowchart LR
    A[Backend, tray, notification, or process event] --> B[Background state pass]
    B --> C[Apply queued actions]
    C --> D[Draw shared UI]
    D --> E[Queue new actions]
    E --> C
    C --> F[Persist state when needed]

The application can run the state pass while no window exists. This is what allows links, notifications, and the tray to request a window without creating a second application state.

References: src/app.rs• L10431-10472 src/app.rs• L11394-11459 src/app.rs• L11831-11855

Shared window composition

The shared UI compositor chooses the surface that matches the application state. A locked app shows only the lock surface. An unlinked app shows account access. A linked app shows the rail, chat or call content, and settings surfaces. Dialogs, pickers, previews, calls, toasts, and other overlays are added around that main surface.

This order gives modal and protected surfaces control over input. It also keeps the title bar, focus ring, announcements, and window controls consistent across all top-level states.

References: src/…/mod.rs• L42-130 src/app.rs• L11394-11459

Primary destinations

The navigation rail is the stable left-side entry point for the main destinations. It provides Chats and Calls at the top, optional Starred, Archived, and Locked destinations, Settings, and the account switcher at the bottom. When the chat list is hidden, chat avatars keep chats reachable from the rail.

The app's page model currently includes Chats, Calls, Settings, and Wallpaper. A destination maps to actions that normalize the state before opening its page, such as leaving an archive or locked-chat view before returning to Chats.

References: src/…/rail.rs• L1-6 src/…/rail.rs• L62-151 src/model.rs• L2024-2031

Responsive layout

The shell keeps the same destinations while changing how much content fits beside them. In a wide window, the rail, chat list, conversation, and an optional right pane can share the window. In a narrow window, the chat list and detail view take turns using the full content area, with a short slide between them.

Search and information panes dock beside a conversation when there is room. They become overlays when keeping a readable conversation beside them is not possible.

References: src/…/mod.rs• L102-130 src/…/mod.rs• L150-209 src/…/mod.rs• L211-317 src/…/pane.rs• L40-92

Navigation history records a page and its open chat as one location. Back and forward restore that pair through the same open-page and open-chat actions used by the rest of the interface. Dialogs and other overlays are not locations; they close through their own controls.

History is limited and account-scoped. It is cleared when the active account changes, and entries for chats that no longer exist or are no longer visible are discarded rather than shown as empty destinations.

References: src/nav.rs• L3-27 src/nav.rs• L29-97 src/app.rs• L6158-6225

The shell provides the common route and lifecycle rules. The detailed interaction systems are documented separately:

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the launch verbs, single-instance parser, and App::handle_control_commands aligned. A command that is accepted at the process boundary but not consumed by the app can silently do nothing.
  • Keep target-link handling aligned between first-launch action queuing and resident-process command handling. Chat targets must preserve their optional composer text.
  • Keep close, hide, reopen, and quit outcomes aligned between Resident::closed, tray actions, and Action handling. A mismatch can leave a background process with no way to show its window.
  • Keep the page model, rail destinations, action routing, and navigation-history locations aligned. A new destination must remain reachable and restorable through the same route.
  • Keep the UI composition order aligned with lock state and overlays. Drawing a protected or modal surface in the wrong order can expose content or let input reach a surface below it.

Important failure modes

TriggerConsequenceGuard
A second launch starts beside the resident clientTwo processes can use the same linked data and archiveThe runtime slot and request channel route later launches to the resident process
A resident client declines an unknown commandA link or control request appears to fail even though the old client is still runningThe launcher falls back to a show request and reports an outdated client when needed
A background start has no visible tray itemThe process can remain hidden with no user path back to the windowThe shell waits for the tray, then shows the window when the wait expires
A link is combined with a hidden startThe requested chat can open behind a tray-only processA chat or invite target overrides the hidden initial window state
A navigation entry names a deleted or protected chatBack or forward can repeatedly land on a place the user cannot seeInvalid locations are forgotten while history is restored
Window composition ignores the app lockChat content or normal shortcuts can remain reachable behind the lock screenThe top-level UI returns after drawing only the lock surface

Key files

FileWhy to read it
src/main.rsDefines the process entry point, launch targets, control commands, startup order, and window-shell creation.
src/single_instance.rsDefines the resident-process contract and the commands passed between launches.
src/app.rsDefines shared application state, background processing, lifecycle outcomes, action routing, and persistence.
src/…/mod.rsDefines the top-level composition order for locked, unlinked, linked, and overlay states.
src/…/rail.rsDefines the primary desktop destinations and their mapping to navigation actions.
src/nav.rsDefines page-and-chat history used by back and forward navigation.
src/model.rsDefines the shared page and action vocabulary used by the shell and its views.