1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
mod codec;
pub mod config;
pub use self::codec::*;
use const_format::concatcp;
use serde::{Deserialize, Serialize};
use std::{
borrow::Cow,
path::{Path, PathBuf},
};
pub const LOCAL: &str = "~/.local/share/pop-launcher";
pub const LOCAL_PLUGINS: &str = concatcp!(LOCAL, "/plugins");
pub const SYSTEM: &str = "/etc/pop-launcher";
pub const SYSTEM_PLUGINS: &str = concatcp!(SYSTEM, "/plugins");
pub const DISTRIBUTION: &str = "/usr/lib/pop-launcher";
pub const DISTRIBUTION_PLUGINS: &str = concatcp!(DISTRIBUTION, "/plugins");
pub const PLUGIN_PATHS: &[&str] = &[LOCAL_PLUGINS, SYSTEM_PLUGINS, DISTRIBUTION_PLUGINS];
pub fn plugin_paths() -> impl Iterator<Item = Cow<'static, Path>> {
PLUGIN_PATHS.iter().map(|path| {
#[allow(deprecated)]
if let Some(path) = path.strip_prefix("~/") {
let path = std::env::home_dir()
.expect("user does not have home dir")
.join(path);
Cow::Owned(path)
} else {
Cow::Borrowed(Path::new(path))
}
})
}
pub type Generation = u32;
pub type Indice = u32;
#[derive(Debug, Deserialize, Serialize)]
pub struct ContextOption {
pub id: Indice,
pub name: String,
}
#[derive(Debug, Deserialize, Serialize)]
pub enum GpuPreference {
Default,
NonDefault,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum IconSource {
Name(Cow<'static, str>),
Mime(Cow<'static, str>),
}
#[derive(Debug, Deserialize, Serialize)]
pub enum PluginResponse {
Append(PluginSearchResult),
Clear,
Close,
Context {
id: Indice,
options: Vec<ContextOption>,
},
Deactivate,
DesktopEntry {
path: PathBuf,
gpu_preference: GpuPreference,
},
Fill(String),
Finished,
}
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct PluginSearchResult {
pub id: Indice,
pub name: String,
pub description: String,
pub keywords: Option<Vec<String>>,
pub icon: Option<IconSource>,
pub exec: Option<String>,
pub window: Option<(Generation, Indice)>,
}
#[derive(Debug, Deserialize, Serialize)]
pub enum Request {
Activate(Indice),
ActivateContext { id: Indice, context: Indice },
Complete(Indice),
Context(Indice),
Exit,
Interrupt,
Quit(Indice),
Search(String),
}
#[derive(Debug, Deserialize, Serialize)]
pub enum Response {
Close,
Context {
id: Indice,
options: Vec<ContextOption>,
},
DesktopEntry {
path: PathBuf,
gpu_preference: GpuPreference,
},
Update(Vec<SearchResult>),
Fill(String),
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SearchResult {
pub id: Indice,
pub name: String,
pub description: String,
#[serde(
default,
skip_serializing_if = "Option::is_none",
with = "::serde_with::rust::unwrap_or_skip"
)]
pub icon: Option<IconSource>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
with = "::serde_with::rust::unwrap_or_skip"
)]
pub category_icon: Option<IconSource>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
with = "::serde_with::rust::unwrap_or_skip"
)]
pub window: Option<(Generation, Indice)>,
}