From 99beeb590766fa60805995e22444563eb98ddb88 Mon Sep 17 00:00:00 2001 From: Kavish Devar Date: Tue, 28 Oct 2025 17:29:31 +0530 Subject: [PATCH] linux-rust: add `--start-minimized` --- linux-rust/src/main.rs | 4 +++- linux-rust/src/ui/window.rs | 20 +++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/linux-rust/src/main.rs b/linux-rust/src/main.rs index 896bad9..73097d6 100644 --- a/linux-rust/src/main.rs +++ b/linux-rust/src/main.rs @@ -25,6 +25,8 @@ struct Args { debug: bool, #[arg(long)] no_tray: bool, + #[arg(long)] + start_minimized: bool, } fn main() -> iced::Result { @@ -41,7 +43,7 @@ fn main() -> iced::Result { rt.block_on(async_main(ui_tx)).unwrap(); }); - ui::window::start_ui(ui_rx) + ui::window::start_ui(ui_rx, args.start_minimized) } diff --git a/linux-rust/src/ui/window.rs b/linux-rust/src/ui/window.rs index 189f987..5145282 100644 --- a/linux-rust/src/ui/window.rs +++ b/linux-rust/src/ui/window.rs @@ -5,11 +5,11 @@ use std::sync::Arc; use log::debug; use tokio::sync::{mpsc::UnboundedReceiver, Mutex}; -pub fn start_ui(ui_rx: UnboundedReceiver<()>) -> iced::Result { +pub fn start_ui(ui_rx: UnboundedReceiver<()>, start_minimized: bool) -> iced::Result { daemon(App::title, App::update, App::view) .subscription(App::subscription) .theme(App::theme) - .run_with(|| App::new(ui_rx)) + .run_with(move || App::new(ui_rx, start_minimized)) } pub struct App { @@ -44,26 +44,32 @@ pub enum Pane { } impl App { - pub fn new(ui_rx: UnboundedReceiver<()>) -> (Self, Task) { + pub fn new(ui_rx: UnboundedReceiver<()>, start_minimized: bool) -> (Self, Task) { let (mut panes, first_pane) = pane_grid::State::new(Pane::Sidebar); let split = panes.split(pane_grid::Axis::Vertical, first_pane, Pane::Content); panes.resize(split.unwrap().1, 0.2); - let (_, open) = window::open(window::Settings::default()); - let ui_rx = Arc::new(Mutex::new(ui_rx)); let wait_task = Task::perform( wait_for_message(Arc::clone(&ui_rx)), |_| Message::OpenMainWindow, ); + + let (window, open_task) = if start_minimized { + (None, Task::none()) + } else { + let (id, open) = window::open(window::Settings::default()); + (Some(id), open.map(Message::WindowOpened)) + }; + ( Self { - window: None, + window, panes, selected_tab: Tab::Device1, ui_rx, }, - Task::batch(vec![open.map(Message::WindowOpened), wait_task]), + Task::batch(vec![open_task, wait_task]), ) }