Skip to content

Commit cd5b4dd

Browse files
committed
feat: add destkop entries actions
1 parent 47852e5 commit cd5b4dd

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use tokio::io::AsyncWrite;
1616
struct Item {
1717
appid: String,
1818
description: String,
19+
actions: Vec<Action>,
1920
exec: String,
2021
icon: Option<String>,
2122
keywords: Option<Vec<String>>,
@@ -25,6 +26,13 @@ struct Item {
2526
src: PathSource,
2627
}
2728

29+
#[derive(Debug, PartialEq, Eq)]
30+
pub struct Action {
31+
pub name: String,
32+
pub description: String,
33+
pub exec: String,
34+
}
35+
2836
impl Hash for Item {
2937
fn hash<H: Hasher>(&self, state: &mut H) {
3038
self.appid.hash(state);
@@ -150,6 +158,25 @@ impl<W: AsyncWrite + Unpin> App<W> {
150158
continue;
151159
}
152160

161+
let mut actions = vec![];
162+
163+
if let Some(entries) = entry.actions() {
164+
for action in entries.split(';') {
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+
});
173+
174+
if let Some(action) = action {
175+
actions.push(action);
176+
}
177+
}
178+
}
179+
153180
let item = Item {
154181
appid: entry.appid.to_owned(),
155182
name: name.to_string(),
@@ -166,6 +193,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
166193
path: path.clone(),
167194
prefers_non_default_gpu: entry.prefers_non_default_gpu(),
168195
src,
196+
actions,
169197
};
170198

171199
deduplicator.insert(item);
@@ -219,14 +247,30 @@ impl<W: AsyncWrite + Unpin> App<W> {
219247
options.push(ContextOption {
220248
id: 0,
221249
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 {
222256
"Launch Using Integrated Graphics Card"
223257
} else {
224258
"Launch Using Discrete Graphics Card"
225259
})
226260
.to_owned(),
261+
exec: None,
227262
});
228263
}
229264

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+
230274
if !options.is_empty() {
231275
let response = PluginResponse::Context { id, options };
232276

src/lib.rs

Lines changed: 2 additions & 0 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)]

0 commit comments

Comments
 (0)