From 0817218375d3fe6d16a9c62caf06ccbefd9e347b Mon Sep 17 00:00:00 2001 From: Christian Friedow Date: Mon, 1 Apr 2024 14:05:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20terminal=20application=20l?= =?UTF-8?q?aunching?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/plugin/applications.rs | 97 ++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 33 deletions(-) diff --git a/client/src/plugin/applications.rs b/client/src/plugin/applications.rs index 13de89c..f656d46 100644 --- a/client/src/plugin/applications.rs +++ b/client/src/plugin/applications.rs @@ -5,33 +5,34 @@ pub struct ApplicationsPlugin { entries: Vec, } -fn read_desktop_entry(path: &std::path::PathBuf) -> anyhow::Result { - let pathstr = path.to_str().unwrap_or(""); - let bytes = std::fs::read_to_string(path)?; - let desktop_entry = freedesktop_desktop_entry::DesktopEntry::decode(path, &bytes)?; +fn read_desktop_entry( + path: &std::path::PathBuf, + terminal_command: Option, +) -> Option { + let bytes_result = std::fs::read_to_string(path); + if let Err(reading_error) = bytes_result { + log::warn!(target: "applications", "Desktop entry at path '{:?}' will be hidden because reading it failed: {}", path, reading_error); + return None; + } + let bytes = bytes_result.unwrap(); + + let desktop_entry_result = freedesktop_desktop_entry::DesktopEntry::decode(path, &bytes); + if let Err(parsing_error) = desktop_entry_result { + log::warn!(target: "applications", "Desktop entry at path '{:?}' will be hidden because parsing it failed: {}", path, parsing_error); + return None; + } + let desktop_entry = desktop_entry_result.unwrap(); if !is_visible(&desktop_entry) { - return Err(anyhow::anyhow!( - "Desktop entry at path '{}' is hidden.", - pathstr - )); + log::info!(target: "applications", "Desktop entry at path '{:?}' will be hidden because of its properties.", path); + return None; } let locale = std::env::var("LANG").unwrap_or(String::from("en_US")); - let title = desktop_entry - .name(Some(&locale)) - .context(format!( - "Desktop entry at path '{}' is missing the 'name' field.", - pathstr - ))? - .to_string(); - - let cmd = desktop_entry - .exec() - .context(format!( - "Desktop entry at path '{}' is missing the 'exec' field.", - pathstr - ))? + let title = desktop_entry.name(Some(&locale))?.to_string(); + + let mut cmd: Vec = desktop_entry + .exec()? .split_ascii_whitespace() .filter_map(|s| { if s.starts_with('%') { @@ -42,13 +43,23 @@ fn read_desktop_entry(path: &std::path::PathBuf) -> anyhow::Result