From a2b83744db4765ea5d06549457d691ffbe0fd5a0 Mon Sep 17 00:00:00 2001 From: bankosegger Date: Wed, 11 Nov 2026 15:00:03 +0100 Subject: [PATCH] feat: load printer configuration from .env Configure the 80 mm thermal printer (576 dots) via a committed .env file, loaded at startup with dotenvy. Real environment variables take precedence. Co-Authored-By: Claude Opus 5.5 --- .env | 10 ++++++++++ Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/main.rs | 7 +++++++ src/printer.rs | 3 ++- 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..47156fa --- /dev/null +++ b/.env @@ -0,0 +1,10 @@ +# Photobooth configuration, loaded from the directory the app is started from. +# Variables already set in the environment (e.g. by systemd) take precedence. + +# Thermal printer (ESC/POS). Remove or leave empty to disable printing. +# A device path for USB/serial printers, or tcp://host[:port] for network +# printers (port defaults to 9100). +PHOTOBOOTH_PRINTER=/dev/usb/lp0 + +# Printable width in dots: 576 for 80 mm paper (384 for 58 mm). +PHOTOBOOTH_PRINTER_DOTS=576 diff --git a/Cargo.lock b/Cargo.lock index 19d8e7c..7f03eb7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -991,6 +991,12 @@ dependencies = [ "litrs", ] +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + [[package]] name = "downcast-rs" version = "1.2.1" @@ -5444,6 +5450,7 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" name = "winf-photobooth-app" version = "0.1.0" dependencies = [ + "dotenvy", "opencv", "slint", "slint-build", diff --git a/Cargo.toml b/Cargo.toml index c73657d..3ce9df2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2024" [dependencies] +dotenvy = "0.15.7" opencv = "0.101.1" slint = { version = "1.18.1", diff --git a/src/main.rs b/src/main.rs index c88dce1..fabf94d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,6 +35,13 @@ struct PreviewFrame { } fn main() -> Result<(), Box> { + // Load `.env` before any thread starts, since it sets process variables. + // Values already present in the real environment take precedence. + match dotenvy::dotenv() { + Ok(path) => eprintln!("[config INFO] Loaded {}", path.display()), + Err(error) if error.not_found() => {} + Err(error) => eprintln!("[config ERROR] Could not load .env: {error}"), + } // One OpenCV inference thread per worker leaves CPU time for the camera/UI // on the dual-core kiosk instead of each model spawning two busy threads. core::set_num_threads(1)?; diff --git a/src/printer.rs b/src/printer.rs index 1040ed6..bb7e85c 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -1,6 +1,7 @@ //! ESC/POS thermal printing for captured photos. //! -//! Configuration (environment variables, read once at startup): +//! Configuration (environment variables or the committed `.env`; read once at +//! startup): //! - `PHOTOBOOTH_PRINTER`: where to send print data. Either a device path such as //! `/dev/usb/lp0` (USB printer class) or a raw network printer as //! `tcp://host[:port]` (port defaults to 9100). Printing is disabled when unset.