Skip to content

Commit

Permalink
feat: add destkop entries actions
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed May 27, 2022
1 parent 47852e5 commit cd5b4dd
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plugins/src/calc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
44 changes: 44 additions & 0 deletions plugins/src/desktop_entries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use tokio::io::AsyncWrite;
struct Item {
appid: String,
description: String,
actions: Vec<Action>,
exec: String,
icon: Option<String>,
keywords: Option<Vec<String>>,
Expand All @@ -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<H: Hasher>(&self, state: &mut H) {
self.appid.hash(state);
Expand Down Expand Up @@ -150,6 +158,25 @@ impl<W: AsyncWrite + Unpin> App<W> {
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(),
Expand All @@ -166,6 +193,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
path: path.clone(),
prefers_non_default_gpu: entry.prefers_non_default_gpu(),
src,
actions,
};

deduplicator.insert(item);
Expand Down Expand Up @@ -219,14 +247,30 @@ impl<W: AsyncWrite + Unpin> App<W> {
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 };

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub type Indice = u32;
pub struct ContextOption {
pub id: Indice,
pub name: String,
pub description: String,
pub exec: Option<String>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
Expand Down

0 comments on commit cd5b4dd

Please sign in to comment.