Skip to content

Commit 1bcc819

Browse files
committed
feat: add destkop entries actions
1 parent 169c4db commit 1bcc819

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

plugins/src/calc/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ impl App {
7070
let options = vec![ContextOption {
7171
id: 0,
7272
name: "Qalculate! Manual".into(),
73+
description: "Browse Qalculate! user manual".to_string(),
74+
exec: None,
7375
}];
7476

7577
crate::send(&mut self.out, PluginResponse::Context { id: 0, options }).await;

plugins/src/desktop_entries/mod.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ struct Item {
2626
src: PathSource,
2727
}
2828

29+
#[derive(Debug, PartialEq, Eq)]
30+
pub struct Action {
31+
pub name: String,
32+
pub description: String,
33+
pub exec: String,
34+
}
35+
2936
impl Hash for Item {
3037
fn hash<H: Hasher>(&self, state: &mut H) {
3138
self.appid.hash(state);
@@ -155,12 +162,14 @@ impl<W: AsyncWrite + Unpin> App<W> {
155162

156163
if let Some(entries) = entry.actions() {
157164
for action in entries.split(';') {
158-
let action = entry.action_name(action, locale)
159-
.and_then(|name| entry.action_exec(action).map(|exe | Action {
160-
name: action.to_string(),
161-
description: name.to_string(),
162-
exec: exec.to_string()
163-
}));
165+
let action =
166+
entry.action_name(action, locale).and_then(|name| {
167+
entry.action_exec(action).map(|exec| Action {
168+
name: action.to_string(),
169+
description: name.to_string(),
170+
exec: exec.to_string(),
171+
})
172+
});
164173

165174
if let Some(action) = action {
166175
actions.push(action);
@@ -184,7 +193,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
184193
path: path.clone(),
185194
prefers_non_default_gpu: entry.prefers_non_default_gpu(),
186195
src,
187-
actions
196+
actions,
188197
};
189198

190199
deduplicator.insert(item);
@@ -238,14 +247,30 @@ impl<W: AsyncWrite + Unpin> App<W> {
238247
options.push(ContextOption {
239248
id: 0,
240249
name: (if entry.prefers_non_default_gpu {
250+
"Integrated Graphics"
251+
} else {
252+
"Discrete Graphics"
253+
})
254+
.to_owned(),
255+
description: (if entry.prefers_non_default_gpu {
241256
"Launch Using Integrated Graphics Card"
242257
} else {
243258
"Launch Using Discrete Graphics Card"
244259
})
245260
.to_owned(),
261+
exec: None,
246262
});
247263
}
248264

265+
for (idx, action) in entry.actions.iter().enumerate() {
266+
options.push(ContextOption {
267+
id: idx as u32,
268+
name: action.name.to_owned(),
269+
description: action.description.to_owned(),
270+
exec: Some(action.exec.to_string()),
271+
})
272+
}
273+
249274
if !options.is_empty() {
250275
let response = PluginResponse::Context { id, options };
251276

src/lib.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ pub type Indice = u32;
4848
pub struct ContextOption {
4949
pub id: Indice,
5050
pub name: String,
51+
pub description: String,
52+
pub exec: Option<String>,
5153
}
5254

5355
#[derive(Debug, Deserialize, Serialize, Clone)]
@@ -91,13 +93,6 @@ pub enum PluginResponse {
9193
Finished,
9294
}
9395

94-
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
95-
pub struct Action {
96-
pub name: String,
97-
pub description: String,
98-
pub exec: String,
99-
}
100-
10196
/// Search information from a plugin to be sorted and filtered by the launcher service.
10297
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
10398
pub struct PluginSearchResult {
@@ -115,7 +110,6 @@ pub struct PluginSearchResult {
115110
pub exec: Option<String>,
116111
/// Designates that this search item refers to a window.
117112
pub window: Option<(Generation, Indice)>,
118-
pub actions: Vec<Action>
119113
}
120114

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

0 commit comments

Comments
 (0)