-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
114 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,80 @@ | ||
use std::path::PathBuf; | ||
use std::{ | ||
collections::{HashMap, HashSet}, | ||
fs::remove_file, | ||
path::PathBuf, | ||
}; | ||
|
||
use zbus::names::{OwnedUniqueName, UniqueName}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct EntryCatalog { | ||
pub owned_resources: HashMap<OwnedUniqueName, (Vec<DesktopEntry>, Vec<IconEntry>)>, | ||
pub change_handlers: HashSet<OwnedUniqueName>, | ||
} | ||
|
||
impl EntryCatalog { | ||
pub fn new() -> Self { | ||
Self { | ||
owned_resources: HashMap::new(), | ||
change_handlers: HashSet::new(), | ||
} | ||
} | ||
|
||
pub fn add_desktop_entry(&mut self, name: OwnedUniqueName, entry: DesktopEntry) { | ||
if !self.owned_resources.contains_key(&name) { | ||
self.owned_resources | ||
.insert(name.clone(), (Vec::new(), Vec::new())); | ||
} | ||
self.owned_resources.get_mut(&name).unwrap().0.push(entry); | ||
} | ||
|
||
pub fn add_icon(&mut self, name: OwnedUniqueName, entry: IconEntry) { | ||
if !self.owned_resources.contains_key(&name) { | ||
self.owned_resources | ||
.insert(name.clone(), (Vec::new(), Vec::new())); | ||
} | ||
self.owned_resources.get_mut(&name).unwrap().1.push(entry); | ||
} | ||
|
||
pub fn remove_owner(&mut self, name: OwnedUniqueName) { | ||
if !self.owned_resources.contains_key(&name) { | ||
return; | ||
} | ||
let (entries, icons) = self.owned_resources.get(&name).unwrap(); | ||
for entry in entries { | ||
let _ = entry.clone().delete_self(); | ||
} | ||
for icon in icons { | ||
let _ = icon.clone().delete_self(); | ||
} | ||
|
||
self.owned_resources.remove(&name); | ||
log::info!("Removed owner with name {:?}", name); | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct DesktopEntry { | ||
pub appid: String, | ||
pub path: PathBuf, | ||
} | ||
|
||
impl DesktopEntry {} | ||
impl DesktopEntry { | ||
fn delete_self(self) -> Result<(), std::io::Error> { | ||
remove_file(&self.path)?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct IconEntry { | ||
pub icon_name: String, | ||
pub icon_path: PathBuf, | ||
} | ||
|
||
impl IconEntry {} | ||
impl IconEntry { | ||
fn delete_self(self) -> Result<(), std::io::Error> { | ||
remove_file(&self.icon_path)?; | ||
Ok(()) | ||
} | ||
} |