1mod config;
19mod db;
21mod desktop_entry;
23mod runner;
25mod scan;
27pub mod hot_reload;
28
29use directories_next::ProjectDirs;
30use lazy_static::lazy_static;
31use serde::{Deserialize, Serialize};
32use std::fmt;
33use std::{
34 cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd},
35 path::PathBuf,
36};
37use uuid::Uuid;
38
39pub use crate::config::Config;
40pub use crate::db::AppsDB;
41
42pub mod error {
44 pub use crate::db::AppDBError;
45 pub use crate::desktop_entry::EntryParseError;
46 pub use crate::runner::RunError;
47 pub use crate::scan::ScanError;
48}
49
50lazy_static! {
51 static ref DIRS: ProjectDirs =
57 ProjectDirs::from("dev", "Ben Aaron Goldberg", "Poki-Launcher")
58 .unwrap();
59 pub static ref DB_PATH: PathBuf = {
61 let data_dir = DIRS.data_dir();
62 let mut db_path = data_dir.to_path_buf();
63 db_path.push("apps.db");
64 db_path
65 };
66 pub static ref CFG_PATH: PathBuf = {
68 let config_dir = DIRS.config_dir();
69 config_dir.join("poki-launcher.hjson")
70 };
71}
72
73#[derive(Debug, Default, Clone, Serialize, Deserialize)]
75pub struct App {
76 pub name: String,
78 pub(crate) exec: Vec<String>,
80 score: f32,
82 pub uuid: String,
85 pub icon: String,
89 pub(crate) terminal: bool,
91}
92
93impl App {
94 pub fn new(
96 name: String,
97 icon: String,
98 exec: Vec<String>,
99 terminal: bool,
100 ) -> App {
101 App {
102 name,
103 icon,
104 exec,
105 uuid: Uuid::new_v4().to_string(),
106 score: 0.0,
107 terminal,
108 }
109 }
110
111 pub fn merge(&mut self, other: &App) {
113 self.name = other.name.clone();
114 self.icon = other.icon.clone();
115 self.exec = other.exec.clone();
116 }
117}
118
119impl PartialEq for App {
120 fn eq(&self, other: &Self) -> bool {
121 self.name == other.name
122 && self.exec == other.exec
123 && self.icon == other.icon
124 }
125}
126
127impl Eq for App {}
128
129impl Ord for App {
130 fn cmp(&self, other: &Self) -> Ordering {
131 self.name
132 .cmp(&other.name)
133 .then(self.exec.cmp(&other.exec))
134 .then(self.icon.cmp(&other.icon))
135 }
136}
137
138impl PartialOrd for App {
139 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
140 Some(self.cmp(other))
141 }
142}
143
144impl fmt::Display for App {
145 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
146 write!(f, "{}", self.name)
147 }
148}