Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 6 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Session>,
pub current_mode: Mode,
adapter: Adapter,
Expand All @@ -27,22 +28,22 @@ pub struct App {
}

impl App {
pub async fn new(icons: Arc<Icons>, interactive: bool) -> Result<Self> {
pub async fn new(icons: Arc<Icons>, interactive: bool, no_auto_power_on: bool) -> Result<Self> {
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()
.await
.with_context(|| "Failed to power on the adapter during initialization")?;
}

let current_mode = adapter.device.mode;

Ok(Self {
running: true,
adapter,
Expand All @@ -52,6 +53,7 @@ impl App {
current_mode,
reset_mode: false,
interactive,
no_auto_power_on,
})
}

Expand Down
14 changes: 11 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -107,6 +113,7 @@ async fn main() -> Result<()> {

let icon_type = matches.get_one::<String>("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());
Expand All @@ -116,7 +123,7 @@ async fn main() -> Result<()> {
.and_then(|s| s.parse::<usize>().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(())
}
Expand All @@ -128,8 +135,9 @@ async fn run_app_loop(
spaces: usize,
icons: Arc<Icons>,
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 {
Expand All @@ -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;
}
}
Expand Down