diff --git a/src/gui/mod.rs b/src/gui/mod.rs index 4d7718e..7f646f5 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -584,7 +584,11 @@ impl ApplicationHandler for App { /// Launch the GUI. Blocks until the window is closed (or the tray Quit is /// chosen). Runs on the main thread, a winit requirement, which is where `main` /// calls it from. -pub fn run() -> anyhow::Result<()> { +/// `relay` is the parent's `--relay` flag (if any), forwarded to every child +/// process so a relay chosen on the GUI command line reaches the headless +/// host/viewer. (The `PIXELPASS_RELAY` env var is inherited regardless; this +/// covers the flag form.) +pub fn run(relay: Option) -> anyhow::Result<()> { let event_loop = EventLoop::::with_user_event() .build() .map_err(|e| anyhow::anyhow!("failed to build the event loop: {e}"))?; @@ -607,6 +611,7 @@ pub fn run() -> anyhow::Result<()> { tray, close_to_tray: gui_settings.close_to_tray, show_qr: gui_settings.show_qr, + relay, waker, }; let mut app = App { @@ -845,6 +850,9 @@ struct PixelPassApp { /// Persisted preference: render the QR-code panel on the host screen. /// Defaults to on; toggled in Settings. show_qr: bool, + /// The parent's `--relay` flag, forwarded to host/viewer children so the + /// flag form reaches them (env-var form is inherited automatically). + relay: Option, /// Wakes the winit loop when a spawned child emits/exits. waker: Waker, } @@ -1230,6 +1238,10 @@ impl PixelPassApp { if self.host.window { args.push("--window".to_string()); } + if let Some(relay) = &self.relay { + args.push("--relay".to_string()); + args.push(relay.clone()); + } match ChildProc::spawn(&args, self.waker.clone()) { Ok(p) => self.host.proc = Some(p), @@ -1503,7 +1515,11 @@ impl PixelPassApp { let ticket = self.viewer.ticket_input.trim().to_string(); self.viewer.connecting_to = ticket_endpoint_id(&ticket).map(|id| short_id(&id)); - let args = vec![ticket, "--output".to_string(), "json".to_string()]; + let mut args = vec![ticket, "--output".to_string(), "json".to_string()]; + if let Some(relay) = &self.relay { + args.push("--relay".to_string()); + args.push(relay.clone()); + } match ChildProc::spawn(&args, self.waker.clone()) { Ok(p) => self.viewer.proc = Some(p), Err(e) => self.viewer.error = Some(format!("Couldn't connect: {e}")), diff --git a/src/main.rs b/src/main.rs index 98ea6cb..2739ff4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ async fn main() -> Result<()> { if cli.gui { #[cfg(feature = "gui")] { - return gui::run(); + return gui::run(cli.relay); } #[cfg(not(feature = "gui"))] {