diff --git a/plugins/src/calc/mod.rs b/plugins/src/calc/mod.rs index fe88c71..d46ebdf 100644 --- a/plugins/src/calc/mod.rs +++ b/plugins/src/calc/mod.rs @@ -70,6 +70,8 @@ impl App { let options = vec![ContextOption { id: 0, name: "Qalculate! Manual".into(), + description: "Browse Qalculate! user manual".to_string(), + exec: None, }]; crate::send(&mut self.out, PluginResponse::Context { id: 0, options }).await; diff --git a/plugins/src/desktop_entries/mod.rs b/plugins/src/desktop_entries/mod.rs index 9524d5c..128d034 100644 --- a/plugins/src/desktop_entries/mod.rs +++ b/plugins/src/desktop_entries/mod.rs @@ -16,6 +16,7 @@ use tokio::io::AsyncWrite; struct Item { appid: String, description: String, + actions: Vec, exec: String, icon: Option, keywords: Option>, @@ -25,6 +26,13 @@ struct Item { src: PathSource, } +#[derive(Debug, PartialEq, Eq)] +pub struct Action { + pub name: String, + pub description: String, + pub exec: String, +} + impl Hash for Item { fn hash(&self, state: &mut H) { self.appid.hash(state); @@ -150,6 +158,25 @@ impl App { continue; } + let mut actions = vec![]; + + if let Some(entries) = entry.actions() { + for action in entries.split(';') { + let action = + entry.action_name(action, locale).and_then(|name| { + entry.action_exec(action).map(|exec| Action { + name: action.to_string(), + description: name.to_string(), + exec: exec.to_string(), + }) + }); + + if let Some(action) = action { + actions.push(action); + } + } + } + let item = Item { appid: entry.appid.to_owned(), name: name.to_string(), @@ -166,6 +193,7 @@ impl App { path: path.clone(), prefers_non_default_gpu: entry.prefers_non_default_gpu(), src, + actions, }; deduplicator.insert(item); @@ -219,14 +247,30 @@ impl App { options.push(ContextOption { id: 0, name: (if entry.prefers_non_default_gpu { + "Integrated Graphics" + } else { + "Discrete Graphics" + }) + .to_owned(), + description: (if entry.prefers_non_default_gpu { "Launch Using Integrated Graphics Card" } else { "Launch Using Discrete Graphics Card" }) .to_owned(), + exec: None, }); } + for (idx, action) in entry.actions.iter().enumerate() { + options.push(ContextOption { + id: idx as u32, + name: action.name.to_owned(), + description: action.description.to_owned(), + exec: Some(action.exec.to_string()), + }) + } + if !options.is_empty() { let response = PluginResponse::Context { id, options }; diff --git a/src/lib.rs b/src/lib.rs index 169562f..cf9bb74 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,6 +48,8 @@ pub type Indice = u32; pub struct ContextOption { pub id: Indice, pub name: String, + pub description: String, + pub exec: Option, } #[derive(Debug, Deserialize, Serialize, Clone)]