diff options
Diffstat (limited to 'src/types.rs')
| -rw-r--r-- | src/types.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/types.rs b/src/types.rs index f0cbfd4..be3f3ed 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,24 +1,24 @@ use futures_util::StreamExt; -use serde::Serialize; +use serde::{Serialize, Deserialize}; use std::path::PathBuf; use tokio::{fs, io::AsyncWriteExt}; use crate::{appimages_dir, index_dir, make_progress_bar}; -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, Deserialize)] pub struct AppImage { pub file_path: PathBuf, pub executable: String, pub source: Source, } -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, Deserialize)] pub struct Source { pub identifier: String, pub meta: SourceMetadata, } -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, Deserialize)] pub struct SourceMetadata { pub url: String, } @@ -92,4 +92,15 @@ impl AppImage { Ok(()) } + pub async fn remove(&self) -> Result<(), Box<dyn std::error::Error>> { + let home = std::env::var("HOME")?; + let symlink_path = PathBuf::from(home).join(".local/bin").join(&self.executable); + let index_path = index_dir().join(format!("{}.json", &self.executable)); + + fs::remove_file(&self.file_path).await?; + fs::remove_file(symlink_path).await?; + fs::remove_file(index_path).await?; + + Ok(()) + } } |
