diff --git a/README.md b/README.md index 17e3015..c5720cc 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,7 @@ iwmenu -l custom --launcher-command "fuzzel -d --placeholder '{hint}' {password_ | `-i`, `--icon` | Specify the icon type to use. | `font`, `xdg` | `font` | | `-s`, `--spaces` | Specify icon to text space count (font icons only). | Any positive integer | `1` | | `--interactive` | Stay in menus after actions and return to previous menu on escape. | N/A | `false` | +| `--no-auto-power-on` | Don't automatically power on adapter device when iwmenu launches. | N/A | `false` | ## Contributing diff --git a/src/app.rs b/src/app.rs index 40f9bde..8efb984 100644 --- a/src/app.rs +++ b/src/app.rs @@ -19,6 +19,7 @@ pub struct App { pub running: bool, pub reset_mode: bool, pub interactive: bool, + pub no_auto_power_on: bool, pub session: Arc, pub current_mode: Mode, adapter: Adapter, @@ -27,15 +28,13 @@ pub struct App { } impl App { - pub async fn new(icons: Arc, interactive: bool) -> Result { + pub async fn new(icons: Arc, interactive: bool, no_auto_power_on: bool) -> Result { let agent_manager = AgentManager::new().await?; let session = agent_manager.session(); let adapter = Adapter::new(session.clone()).await?; - let current_mode = adapter.device.mode; - let notification_manager = Arc::new(NotificationManager::new(icons.clone())); - if !adapter.device.is_powered { + if !no_auto_power_on && !adapter.device.is_powered { adapter .device .power_on() @@ -43,6 +42,8 @@ impl App { .with_context(|| "Failed to power on the adapter during initialization")?; } + let current_mode = adapter.device.mode; + Ok(Self { running: true, adapter, @@ -52,6 +53,7 @@ impl App { current_mode, reset_mode: false, interactive, + no_auto_power_on, }) } diff --git a/src/main.rs b/src/main.rs index c7046e3..1560fe2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,6 +83,12 @@ async fn main() -> Result<()> { .action(clap::ArgAction::SetTrue) .help("Stay in menus after actions and return to previous menu on escape"), ) + .arg( + Arg::new("no_auto_power_on") + .long("no-auto-power-on") + .action(clap::ArgAction::SetTrue) + .help("Don't automatically power on adapter device when iwmenu launches"), + ) .get_matches(); let launcher_type: LauncherType = if matches.contains_id("launcher") { @@ -107,6 +113,7 @@ async fn main() -> Result<()> { let icon_type = matches.get_one::("icon").unwrap().clone(); let interactive = matches.get_flag("interactive"); + let no_auto_power_on = matches.get_flag("no_auto_power_on"); let icons = Arc::new(Icons::new()); let menu = Menu::new(launcher_type, icons.clone()); @@ -116,7 +123,7 @@ async fn main() -> Result<()> { .and_then(|s| s.parse::().ok()) .ok_or_else(|| anyhow!("Invalid value for --spaces. Must be a positive integer."))?; - run_app_loop(&menu, &command_str, &icon_type, spaces, icons, interactive).await?; + run_app_loop(&menu, &command_str, &icon_type, spaces, icons, interactive, no_auto_power_on).await?; Ok(()) } @@ -128,8 +135,9 @@ async fn run_app_loop( spaces: usize, icons: Arc, interactive: bool, + no_auto_power_on: bool, ) -> Result<()> { - let mut app = App::new(icons.clone(), interactive).await?; + let mut app = App::new(icons.clone(), interactive, no_auto_power_on).await?; loop { match app.run(menu, command_str, icon_type, spaces).await { @@ -148,7 +156,7 @@ async fn run_app_loop( } if app.reset_mode { - app = App::new(icons.clone(), interactive).await?; + app = App::new(icons.clone(), interactive, no_auto_power_on).await?; app.reset_mode = false; } }