Skip to main content
The ControlCenter is the core supervisor of the Palyra Desktop application. It acts as a process manager for the two primary backend services: palyrad (the Gateway) and palyra-browserd (the Browser Service). It handles their lifecycle, monitors health, aggregates logs, and manages the persistence of the desktop application’s state.

ControlCenter Architecture

The ControlCenter struct is the central authority for the desktop app’s runtime. It is managed as a thread-safe state within Tauri using Arc<Mutex<ControlCenter>> apps/desktop/src-tauri/src/commands.rs#49-51.

ManagedService Lifecycle

Each service (Gateway and Browserd) is wrapped in a ManagedService struct apps/desktop/src-tauri/src/supervisor.rs#97-107.

Supervisor Loop and Reconciliation

The supervisor operates on a periodic tick defined by SUPERVISOR_TICK_MS (500ms) apps/desktop/src-tauri/src/lib.rs#1. In each iteration, it performs:
  1. Liveness Checks: Verifies if the child processes are still running.
  2. Backoff Logic: If a service has exited but desired_running is true, it calculates a restart delay using exponential backoff apps/desktop/src-tauri/src/supervisor.rs#102-103.
  3. Health Probing: Attempts to reach the health endpoints of the services via the http_client apps/desktop/src-tauri/src/supervisor.rs#212.

ControlCenter Entity Mapping

The following diagram maps the high-level supervision concepts to the specific Rust entities in the codebase. Diagram: Supervision Entity Map Sources: apps/desktop/src-tauri/src/commands.rs#49-51, apps/desktop/src-tauri/src/supervisor.rs#201-218, apps/desktop/src-tauri/src/supervisor.rs#97-107

Log Aggregation and Rotation

The ControlCenter implements an asynchronous log reading pipeline to capture stdout and stderr from managed processes without blocking the supervisor loop.

Implementation Details

Diagram: Log Data Flow Sources: apps/desktop/src-tauri/src/lib.rs#1-3, apps/desktop/src-tauri/src/supervisor.rs#105, apps/desktop/src-tauri/src/supervisor.rs#215-216

DesktopStateFile and Persistence

The DesktopStateFile manages the persistent configuration and onboarding progress of the desktop application.

Schema Versioning and Migration

The system uses DESKTOP_STATE_SCHEMA_VERSION (currently 4) to handle data evolution apps/desktop/src-tauri/src/lib.rs#9.

DesktopSecretStore

Secrets such as the desktop_admin_token and desktop_browser_auth_token are not stored in the plain-text state.json. Instead, they are managed by the DesktopSecretStore, which interfaces with the palyra-vault crate apps/desktop/src-tauri/src/desktop_state.rs#8.
FieldTypeDescription
onboarding_stepDesktopOnboardingStepCurrent phase of the setup wizard apps/desktop/src-tauri/src/desktop_state.rs#209-219
runtime_state_root_overrideOption<PathBuf>User-selected path for data storage apps/desktop/src-tauri/src/supervisor.rs#140-146
browser_service_enabledboolWhether palyra-browserd should be started apps/desktop/src-tauri/src/commands.rs#154-162
companionDesktopCompanionStateState for the tray-based companion UI apps/desktop/src-tauri/src/desktop_state.rs#90-101
Sources: apps/desktop/src-tauri/src/lib.rs#9-12, apps/desktop/src-tauri/src/desktop_state.rs#209-219, apps/desktop/src-tauri/src/supervisor.rs#231-233

Tauri Command Interface

The ControlCenter exposes its functionality to the frontend via Tauri commands defined in commands.rs.

Key Commands

Snapshot Generation

The snapshot is built by calling capture_snapshot_inputs on the ControlCenter, which gathers volatile process information, and then passing it to build_snapshot_from_inputs apps/desktop/src-tauri/src/snapshot.rs#204-216. This includes: Sources: apps/desktop/src-tauri/src/commands.rs#54-162, apps/desktop/src-tauri/src/snapshot.rs#173-182, apps/desktop/src-tauri/src/snapshot.rs#204-216