From 931807e32607ac32ed74a7394ab617c09d57aa0a Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Sat, 21 Jun 2025 14:21:54 +0200 Subject: [PATCH 1/7] Add a launch_command setting (and put duplicate code in a function) --- src/modules/launcher/mod.rs | 37 ++++++++++++++++++++++++------------- src/modules/menu/config.rs | 5 +++++ src/modules/menu/mod.rs | 2 +- src/modules/menu/ui.rs | 17 ++++------------- 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/modules/launcher/mod.rs b/src/modules/launcher/mod.rs index 0a6757f..13338c8 100644 --- a/src/modules/launcher/mod.rs +++ b/src/modules/launcher/mod.rs @@ -108,6 +108,9 @@ pub struct LauncherModule { #[serde(default, flatten)] layout: LayoutConfig, + #[serde(default = "default_launch_command")] + launch_command: String, + /// See [common options](module-level-options#common-options). #[serde(flatten)] pub common: Option, @@ -158,6 +161,25 @@ fn default_icon_page_forward() -> String { String::from("󰅂") } +pub(crate) fn default_launch_command() -> String { String::from("gtk-launch") } +pub fn launch_command(file_name: &String, str: &String) { + let launch_command_parts: Vec<&str> = str.split_whitespace().collect(); + if let Err(err) = Command::new(&launch_command_parts[0]) + .args(&launch_command_parts[1..]) + .arg(file_name) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .spawn() + { + error!( + "{:?}", + Report::new(err) + .wrap_err("Failed to run launch command.") + .suggestion("Perhaps the applications file is invalid?") + ); + } +} + const fn default_truncate_popup() -> TruncateMode { TruncateMode::Length { mode: EllipsizeMode::Middle, @@ -373,25 +395,14 @@ impl Module for LauncherModule { let wl = context.client::(); let desktop_files = context.ironbar.desktop_files(); + let launch_command_str: String = self.launch_command.clone(); spawn(async move { while let Some(event) = rx.recv().await { if let ItemEvent::OpenItem(app_id) = event { match desktop_files.find(&app_id).await { Ok(Some(file)) => { - if let Err(err) = Command::new("gtk-launch") - .arg(file.file_name) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .spawn() - { - error!( - "{:?}", - Report::new(err) - .wrap_err("Failed to run gtk-launch command.") - .suggestion("Perhaps the applications file is invalid?") - ); - } + launch_command(&file.file_name, &launch_command_str); } Ok(None) => warn!("Could not find applications file for {}", app_id), Err(err) => error!("Failed to find parse file for {}: {}", app_id, err), diff --git a/src/modules/menu/config.rs b/src/modules/menu/config.rs index 4575880..8efe994 100644 --- a/src/modules/menu/config.rs +++ b/src/modules/menu/config.rs @@ -1,5 +1,6 @@ use crate::config::{CommonConfig, TruncateMode}; use crate::modules::menu::{MenuEntry, XdgSection}; +use crate::modules::launcher::default_launch_command; use indexmap::IndexMap; use serde::Deserialize; @@ -123,6 +124,9 @@ pub struct MenuModule { /// See [common options](module-level-options#common-options). #[serde(flatten)] pub common: Option, + + #[serde(default = "default_launch_command")] + pub launch_command: String, } impl Default for MenuModule { @@ -139,6 +143,7 @@ impl Default for MenuModule { label_icon: None, label_icon_size: default_menu_popup_icon_size(), common: Some(CommonConfig::default()), + launch_command: default_launch_command(), } } } diff --git a/src/modules/menu/mod.rs b/src/modules/menu/mod.rs index cd46766..6c9e2d7 100644 --- a/src/modules/menu/mod.rs +++ b/src/modules/menu/mod.rs @@ -263,7 +263,7 @@ impl Module