1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-08-17 14:51:04 +02:00

Rename launch_command to open_program & move it to desktop_file.rs

This commit is contained in:
Username404-59 2025-06-22 18:31:22 +02:00
parent 8dfca4303d
commit d891893101
No known key found for this signature in database
GPG key ID: F3A1878B14F5F0D7
4 changed files with 28 additions and 27 deletions

View file

@ -1,12 +1,13 @@
use crate::spawn;
use color_eyre::Result;
use color_eyre::{Help, Report, Result};
use std::collections::HashMap;
use std::env;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::sync::Arc;
use tokio::io::{AsyncBufReadExt, BufReader};
use tokio::sync::Mutex;
use tracing::debug;
use tracing::{debug, error};
use walkdir::{DirEntry, WalkDir};
#[derive(Debug, Clone)]
@ -323,6 +324,25 @@ fn files(dir: &Path) -> Vec<PathBuf> {
.collect()
}
/// Starts a `.desktop` file with the provided formatted command.
pub fn open_program(file_name: &str, str: &str) {
let expanded = str.replace("{app_name}", file_name);
let launch_command_parts: Vec<&str> = expanded.split_whitespace().collect();
if let Err(err) = Command::new(&launch_command_parts[0])
.args(&launch_command_parts[1..])
.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?")
);
}
}
#[cfg(test)]
mod tests {
use super::*;