mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-17 14:51:04 +02:00
Add a launch_command setting
(and put duplicate code in a function)
This commit is contained in:
parent
81ce2c169f
commit
931807e326
4 changed files with 34 additions and 27 deletions
|
@ -108,6 +108,9 @@ pub struct LauncherModule {
|
||||||
#[serde(default, flatten)]
|
#[serde(default, flatten)]
|
||||||
layout: LayoutConfig,
|
layout: LayoutConfig,
|
||||||
|
|
||||||
|
#[serde(default = "default_launch_command")]
|
||||||
|
launch_command: String,
|
||||||
|
|
||||||
/// See [common options](module-level-options#common-options).
|
/// See [common options](module-level-options#common-options).
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub common: Option<CommonConfig>,
|
pub common: Option<CommonConfig>,
|
||||||
|
@ -158,6 +161,25 @@ fn default_icon_page_forward() -> String {
|
||||||
String::from("")
|
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 {
|
const fn default_truncate_popup() -> TruncateMode {
|
||||||
TruncateMode::Length {
|
TruncateMode::Length {
|
||||||
mode: EllipsizeMode::Middle,
|
mode: EllipsizeMode::Middle,
|
||||||
|
@ -373,25 +395,14 @@ impl Module<gtk::Box> for LauncherModule {
|
||||||
let wl = context.client::<wayland::Client>();
|
let wl = context.client::<wayland::Client>();
|
||||||
|
|
||||||
let desktop_files = context.ironbar.desktop_files();
|
let desktop_files = context.ironbar.desktop_files();
|
||||||
|
let launch_command_str: String = self.launch_command.clone();
|
||||||
|
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
while let Some(event) = rx.recv().await {
|
while let Some(event) = rx.recv().await {
|
||||||
if let ItemEvent::OpenItem(app_id) = event {
|
if let ItemEvent::OpenItem(app_id) = event {
|
||||||
match desktop_files.find(&app_id).await {
|
match desktop_files.find(&app_id).await {
|
||||||
Ok(Some(file)) => {
|
Ok(Some(file)) => {
|
||||||
if let Err(err) = Command::new("gtk-launch")
|
launch_command(&file.file_name, &launch_command_str);
|
||||||
.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?")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(None) => warn!("Could not find applications file for {}", app_id),
|
Ok(None) => warn!("Could not find applications file for {}", app_id),
|
||||||
Err(err) => error!("Failed to find parse file for {}: {}", app_id, err),
|
Err(err) => error!("Failed to find parse file for {}: {}", app_id, err),
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::config::{CommonConfig, TruncateMode};
|
use crate::config::{CommonConfig, TruncateMode};
|
||||||
use crate::modules::menu::{MenuEntry, XdgSection};
|
use crate::modules::menu::{MenuEntry, XdgSection};
|
||||||
|
use crate::modules::launcher::default_launch_command;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
@ -123,6 +124,9 @@ pub struct MenuModule {
|
||||||
/// See [common options](module-level-options#common-options).
|
/// See [common options](module-level-options#common-options).
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub common: Option<CommonConfig>,
|
pub common: Option<CommonConfig>,
|
||||||
|
|
||||||
|
#[serde(default = "default_launch_command")]
|
||||||
|
pub launch_command: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for MenuModule {
|
impl Default for MenuModule {
|
||||||
|
@ -139,6 +143,7 @@ impl Default for MenuModule {
|
||||||
label_icon: None,
|
label_icon: None,
|
||||||
label_icon_size: default_menu_popup_icon_size(),
|
label_icon_size: default_menu_popup_icon_size(),
|
||||||
common: Some(CommonConfig::default()),
|
common: Some(CommonConfig::default()),
|
||||||
|
launch_command: default_launch_command(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,7 +263,7 @@ impl Module<Button> for MenuModule {
|
||||||
let container1 = container.clone();
|
let container1 = container.clone();
|
||||||
let tx = context.tx.clone();
|
let tx = context.tx.clone();
|
||||||
let (button, sub_menu) =
|
let (button, sub_menu) =
|
||||||
ui::make_entry(entry, tx, &image_provider, truncate_mode);
|
ui::make_entry(entry, tx, &image_provider, truncate_mode, &self.launch_command);
|
||||||
|
|
||||||
if let Some(sub_menu) = sub_menu.clone() {
|
if let Some(sub_menu) = sub_menu.clone() {
|
||||||
sub_menu.set_valign(alignment);
|
sub_menu.set_valign(alignment);
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::channels::AsyncSenderExt;
|
||||||
use crate::config::TruncateMode;
|
use crate::config::TruncateMode;
|
||||||
use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt};
|
use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt};
|
||||||
use crate::modules::ModuleUpdateEvent;
|
use crate::modules::ModuleUpdateEvent;
|
||||||
|
use crate::modules::launcher::launch_command;
|
||||||
use crate::script::Script;
|
use crate::script::Script;
|
||||||
use crate::{image, spawn};
|
use crate::{image, spawn};
|
||||||
use color_eyre::{Help, Report};
|
use color_eyre::{Help, Report};
|
||||||
|
@ -17,6 +18,7 @@ pub fn make_entry<R>(
|
||||||
tx: mpsc::Sender<ModuleUpdateEvent<R>>,
|
tx: mpsc::Sender<ModuleUpdateEvent<R>>,
|
||||||
image_provider: &image::Provider,
|
image_provider: &image::Provider,
|
||||||
truncate_mode: TruncateMode,
|
truncate_mode: TruncateMode,
|
||||||
|
launch_command_str: &String,
|
||||||
) -> (Button, Option<gtk::Box>)
|
) -> (Button, Option<gtk::Box>)
|
||||||
where
|
where
|
||||||
R: Send + Clone + 'static,
|
R: Send + Clone + 'static,
|
||||||
|
@ -96,22 +98,11 @@ where
|
||||||
{
|
{
|
||||||
let sub_menu = sub_menu.clone();
|
let sub_menu = sub_menu.clone();
|
||||||
let file_name = sub_entry.file_name.clone();
|
let file_name = sub_entry.file_name.clone();
|
||||||
|
let command = launch_command_str.clone();
|
||||||
let tx = tx.clone();
|
let tx = tx.clone();
|
||||||
|
|
||||||
button.connect_clicked(move |_button| {
|
button.connect_clicked(move |_button| {
|
||||||
if let Err(err) = Command::new("gtk-launch")
|
launch_command(&file_name, &command);
|
||||||
.arg(&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?")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub_menu.hide();
|
sub_menu.hide();
|
||||||
tx.send_spawn(ModuleUpdateEvent::ClosePopup);
|
tx.send_spawn(ModuleUpdateEvent::ClosePopup);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue