1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-08-16 14:21:03 +02:00

Improve launch_command

This commit is contained in:
Username404-59 2025-06-22 16:15:33 +02:00
parent a253a23d57
commit a6f63b3bf1
No known key found for this signature in database
GPG key ID: F3A1878B14F5F0D7
5 changed files with 40 additions and 29 deletions

View file

@ -44,9 +44,11 @@ use crate::modules::workspaces::WorkspacesModule;
use crate::modules::{AnyModuleFactory, ModuleFactory, ModuleInfo};
use cfg_if::cfg_if;
use color_eyre::Result;
use color_eyre::{Help, Report, Result};
use serde::Deserialize;
use std::collections::HashMap;
use std::process::{Command, Stdio};
use tracing::error;
#[cfg(feature = "schema")]
use schemars::JsonSchema;
@ -435,3 +437,25 @@ pub const fn default_false() -> bool {
pub const fn default_true() -> bool {
true
}
pub fn default_launch_command() -> String {
String::from("gtk-launch")
}
pub fn launch_command(file_name: &str, str: &str) {
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?")
);
}
}

View file

@ -7,17 +7,18 @@ use self::open_state::OpenState;
use super::{Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, WidgetContext};
use crate::channels::{AsyncSenderExt, BroadcastReceiverExt};
use crate::clients::wayland::{self, ToplevelEvent};
use crate::config::{CommonConfig, EllipsizeMode, LayoutConfig, TruncateMode};
use crate::config::{
CommonConfig, EllipsizeMode, LayoutConfig, TruncateMode, default_launch_command, launch_command,
};
use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt};
use crate::modules::launcher::item::ImageTextButton;
use crate::modules::launcher::pagination::{IconContext, Pagination};
use crate::{arc_mut, lock, module_impl, spawn, write_lock};
use color_eyre::{Help, Report};
use color_eyre::Report;
use gtk::prelude::*;
use gtk::{Button, Orientation};
use indexmap::IndexMap;
use serde::Deserialize;
use std::process::{Command, Stdio};
use std::sync::Arc;
use tokio::sync::mpsc;
use tracing::{debug, error, trace, warn};
@ -164,25 +165,6 @@ 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,

View file

@ -1,6 +1,6 @@
use crate::config::default_launch_command;
use crate::config::{CommonConfig, TruncateMode};
use crate::modules::menu::{MenuEntry, XdgSection};
use crate::modules::launcher::default_launch_command;
use indexmap::IndexMap;
use serde::Deserialize;

View file

@ -262,8 +262,13 @@ impl Module<Button> for MenuModule {
for entry in $entries.values() {
let container1 = container.clone();
let tx = context.tx.clone();
let (button, sub_menu) =
ui::make_entry(entry, tx, &image_provider, truncate_mode, &self.launch_command);
let (button, sub_menu) = ui::make_entry(
entry,
tx,
&image_provider,
truncate_mode,
&self.launch_command,
);
if let Some(sub_menu) = sub_menu.clone() {
sub_menu.set_valign(alignment);

View file

@ -1,9 +1,9 @@
use super::MenuEntry;
use crate::channels::AsyncSenderExt;
use crate::config::TruncateMode;
use crate::config::launch_command;
use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt};
use crate::modules::ModuleUpdateEvent;
use crate::modules::launcher::launch_command;
use crate::script::Script;
use crate::{image, spawn};
use gtk::prelude::*;
@ -16,7 +16,7 @@ pub fn make_entry<R>(
tx: mpsc::Sender<ModuleUpdateEvent<R>>,
image_provider: &image::Provider,
truncate_mode: TruncateMode,
launch_command_str: &String,
launch_command_str: &str,
) -> (Button, Option<gtk::Box>)
where
R: Send + Clone + 'static,
@ -96,7 +96,7 @@ where
{
let sub_menu = sub_menu.clone();
let file_name = sub_entry.file_name.clone();
let command = launch_command_str.clone();
let command = launch_command_str.to_string();
let tx = tx.clone();
button.connect_clicked(move |_button| {