M0.5: Tauri desktop shell with themed main window

The window is built in setup with the theme tokens injected by an
initialization script and the background colour taken from the theme, so
the first frame is already themed. Frontend IPC (engine_execute,
engine_list_commands) and the control channel both run commands through
the Host, which applies effects such as Quit. ui.screenshot captures the
window's client area from the screen because xcap skips windows of its own
process. build.rs generates the placeholder icon into the gitignored
icons/ directory. Verified on Windows: window opens, ping, listCommands,
screenshot, app.quit, and exit status 1 when the control port is taken.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-14 18:39:49 +02:00
parent a3f83102f1
commit 55acb0dffb
14 changed files with 6025 additions and 36 deletions

View file

@ -0,0 +1,93 @@
//! Command-line arguments of the desktop app.
use std::path::PathBuf;
/// Parsed arguments.
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct Args {
/// Port for the JSON control channel (`--control PORT`).
pub control: Option<u16>,
/// Folder or file to open.
pub path: Option<PathBuf>,
/// `--help` was given.
pub help: bool,
/// `--version` was given.
pub version: bool,
}
/// Usage text for `--help`.
pub const USAGE: &str = "usage: lutra-desktop [--control PORT] [PATH]
--control PORT serve the JSON control channel on 127.0.0.1:PORT
--version print the version
--help print this help";
/// Parses the arguments after the program name.
///
/// # Errors
/// A message for an unknown flag, a missing or invalid port, or more than one
/// path.
pub fn parse(args: impl IntoIterator<Item = String>) -> Result<Args, String> {
let mut parsed = Args::default();
let mut args = args.into_iter();
while let Some(arg) = args.next() {
if let Some(value) = arg.strip_prefix("--control=") {
parsed.control = Some(port(value)?);
continue;
}
match arg.as_str() {
"--control" => {
let value = args.next().ok_or("--control needs a port")?;
parsed.control = Some(port(&value)?);
}
"--help" | "-h" => parsed.help = true,
"--version" | "-V" => parsed.version = true,
flag if flag.starts_with('-') => return Err(format!("unknown option {flag}")),
path => {
if parsed.path.is_some() {
return Err("only one PATH can be given".into());
}
parsed.path = Some(PathBuf::from(path));
}
}
}
Ok(parsed)
}
/// Parses a TCP port number.
///
/// # Errors
/// A message if the value is not a number from 1 to 65535.
fn port(value: &str) -> Result<u16, String> {
match value.parse::<u16>() {
Ok(0) | Err(_) => Err(format!("invalid port {value:?}; expected 1-65535")),
Ok(port) => Ok(port),
}
}
#[cfg(test)]
mod tests {
use super::*;
fn p(args: &[&str]) -> Result<Args, String> {
parse(args.iter().map(|s| s.to_string()))
}
#[test]
fn parses_control_and_path() {
let a = p(&["--control", "7979", "/tmp/demo"]).unwrap();
assert_eq!(a.control, Some(7979));
assert_eq!(a.path, Some(PathBuf::from("/tmp/demo")));
assert_eq!(p(&["--control=80"]).unwrap().control, Some(80));
assert_eq!(p(&[]).unwrap(), Args::default());
}
#[test]
fn rejects_bad_input() {
assert!(p(&["--control"]).is_err());
assert!(p(&["--control", "0"]).is_err());
assert!(p(&["--control", "70000"]).is_err());
assert!(p(&["--frobnicate"]).is_err());
assert!(p(&["a", "b"]).is_err());
}
}