summaryrefslogtreecommitdiff
path: root/src/types.rs
blob: 5636fe91af0f72051e1b804fe6b04969da3d956d (plain)
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
use serde::Serialize;
use std::path::PathBuf;
use tokio::fs;

use crate::{index_dir};

#[derive(Debug, Serialize)]
pub struct AppImage {
    pub file_path: PathBuf,
    pub executable: String,
    pub source: Source,
}

#[derive(Debug, Serialize)]
pub struct Source {
    pub identifier: String,
    pub meta: SourceMetadata,
}

#[derive(Debug, Serialize)]
pub struct SourceMetadata {
    pub url: String,
}

impl AppImage {
    pub async fn save_to_index(&self, appname: &str) -> Result<(), Box<dyn std::error::Error>> {
        let index_file = &index_dir().join(format!("{appname}.json"));

        let json = serde_json::to_string_pretty(self)?;
        fs::write(index_file, json).await?;

        Ok(())
    }
}