zerolaunch_plugin_api/services/resource/
app_resource.rs1use dashmap::DashMap;
2use std::path::PathBuf;
3
4pub struct AppResourceService {
8 icon_paths: DashMap<String, String>,
10 icons_dir: String,
12}
13
14impl AppResourceService {
15 pub fn new(icons_dir: String) -> Self {
22 let icon_paths = DashMap::new();
23
24 let icons_dir_path = PathBuf::from(&icons_dir);
25
26 let icons = [
27 ("tray_icon", "128x128@2x.png"),
29 ("web_pages", "web_pages.png"),
30 ("tips", "tips.png"),
31 ("terminal", "terminal.png"),
32 ("settings", "settings.png"),
33 ("refresh", "refresh.png"),
34 ("register", "register.png"),
35 ("game", "game.png"),
36 ("exit", "exit.png"),
37 ];
38
39 for (name, filename) in icons {
40 let path = icons_dir_path.join(filename);
41 icon_paths.insert(name.to_string(), path.to_string_lossy().to_string());
42 }
43
44 Self {
45 icon_paths,
46 icons_dir,
47 }
48 }
49
50 pub fn get_icon_path(&self, name: &str) -> Option<String> {
57 self.icon_paths.get(name).map(|v| v.value().clone())
58 }
59
60 pub fn icons_dir(&self) -> &str {
64 &self.icons_dir
65 }
66}