lib.rs — Application Bootstrap
lib.rs is where the entire Tauri application is configured and started. It does the following in order:
1. Managed state registration
Two pieces of state are registered with Tauri's state manager so they can be injected into any command via State<'_>:
RoverState— the three rover mode booleans (drive_manual_mode,arm_manual_mode,pickup_mode), all wrapped inMutexso they are safe to read and write from async commandsDummyStreamHandle— holds an optional cancellation flag for the dummy simulator
Warning:RoverState Youis subject to change, because the rover might bebecome able to drive and move the arm at the same time
2. Plugin registration
Three official Tauri plugins are loaded:
Plugin | Purpose |
|---|---|
| File system access from the frontend |
| Open files/URLs in the OS default application |
| Native file picker and dialog boxes |
3. Command registration
All Tauri commands are registered here via tauri::generate_handler!. This is the complete list of commands callable from the frontend via invoke(). If you add a new command in any commands/ file, it must also be added here or it will not be accessible from the frontend.
4. Setup (startup sequence)
The .setup() closure runs once at launch, before any window is shown. It performs these steps in order:
a) GStreamer plugin path Sets the GST_PLUGIN_PATH environment variable so GStreamer can find its plugins. The path differs by OS:
- Linux:
/usr/lib/x86_64-linux-gnu/gstreamer-1.0 - Windows:
C:\gstreamer\1.0\msvc_x86_64\bin
b) Storage directory creation Calls ensure_storage_dirs_internal() to create the tasks/, images/, and maps/ subdirectories under the app data directory if they don't already exist.
c) Cache clearing Calls clear_cache_on_startup() to wipe any stale cached files from the previous session.
d) GStreamer streaming server Spawns an async task that runs commands::gstreamer::stream() for the lifetime of the app. This starts the three GStreamer pipelines and their corresponding MJPEG HTTP servers.
e) UDP service Creates UdpService (binding 0.0.0.0:9000) synchronously using block_on. The socket is extracted before the service is moved into Tauri's state manager, so it can be passed to the listener independently.
f) UDP listener Spawns an async task running network::listener::run_listener() with the shared socket. This is the loop that receives, decodes, and forwards all incoming rover packets to the frontend.
g) Controller listener Calls commands::controller::start_controller_listener(), which spawns an OS thread to poll for gamepad events.