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
mod config;
mod db;
mod desktop_entry;
mod runner;
mod scan;
pub mod hot_reload;
use directories_next::ProjectDirs;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use std::fmt;
use std::{
cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd},
path::PathBuf,
};
use uuid::Uuid;
pub use crate::config::Config;
pub use crate::db::AppsDB;
pub mod error {
pub use crate::db::AppDBError;
pub use crate::desktop_entry::EntryParseError;
pub use crate::runner::RunError;
pub use crate::scan::ScanError;
}
lazy_static! {
static ref DIRS: ProjectDirs =
ProjectDirs::from("dev", "Ben Aaron Goldberg", "Poki-Launcher")
.unwrap();
pub static ref DB_PATH: PathBuf = {
let data_dir = DIRS.data_dir();
let mut db_path = data_dir.to_path_buf();
db_path.push("apps.db");
db_path
};
pub static ref CFG_PATH: PathBuf = {
let config_dir = DIRS.config_dir();
config_dir.join("poki-launcher.hjson")
};
}
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct App {
pub name: String,
pub(crate) exec: Vec<String>,
score: f32,
pub uuid: String,
pub icon: String,
pub(crate) terminal: bool,
}
impl App {
pub fn new(
name: String,
icon: String,
exec: Vec<String>,
terminal: bool,
) -> App {
App {
name,
icon,
exec,
uuid: Uuid::new_v4().to_string(),
score: 0.0,
terminal,
}
}
pub fn merge(&mut self, other: &App) {
self.name = other.name.clone();
self.icon = other.icon.clone();
self.exec = other.exec.clone();
}
}
impl PartialEq for App {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
&& self.exec == other.exec
&& self.icon == other.icon
}
}
impl Eq for App {}
impl Ord for App {
fn cmp(&self, other: &Self) -> Ordering {
self.name
.cmp(&other.name)
.then(self.exec.cmp(&other.exec))
.then(self.icon.cmp(&other.icon))
}
}
impl PartialOrd for App {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl fmt::Display for App {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.name)
}
}