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 169c4db commit 1bcc819
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 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
39 changes: 32 additions & 7 deletions plugins/src/desktop_entries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,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 @@ -155,12 +162,14 @@ impl<W: AsyncWrite + Unpin> App<W> {

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(|exe | Action {
name: action.to_string(),
description: name.to_string(),
exec: exec.to_string()
}));
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);
Expand All @@ -184,7 +193,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
path: path.clone(),
prefers_non_default_gpu: entry.prefers_non_default_gpu(),
src,
actions
actions,
};

deduplicator.insert(item);
Expand Down Expand Up @@ -238,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
10 changes: 2 additions & 8 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 Expand Up @@ -91,13 +93,6 @@ pub enum PluginResponse {
Finished,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
pub struct Action {
pub name: String,
pub description: String,
pub exec: String,
}

/// Search information from a plugin to be sorted and filtered by the launcher service.
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct PluginSearchResult {
Expand All @@ -115,7 +110,6 @@ pub struct PluginSearchResult {
pub exec: Option<String>,
/// Designates that this search item refers to a window.
pub window: Option<(Generation, Indice)>,
pub actions: Vec<Action>
}

// Sent to the input pipe of the launcher service, and disseminated to its plugins.
Expand Down

0 comments on commit 1bcc819

Please sign in to comment.