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
35
36
37
38
39
use std::collections::HashMap;
use std::path::PathBuf;
use crate::host::FpmHost;
use async_trait::async_trait;
use crate::error::Error;
use crate::font::{DefinedFontInstallSpec, DefinedFontVariantSpec, FontDescription, FontInstallSpec};

#[derive(PartialEq, Eq)]
pub enum RefreshOutput {
    AlreadyUpToDate,
    Downloaded
}

#[async_trait]
pub trait Source<'host>: Send + Sync {
    fn id(&self) -> &'host str;
    fn name(&self) -> &'host str;

    fn set_host(&mut self, host: &'host dyn FpmHost);

    async fn refresh(&self, force_refresh: bool) -> Result<RefreshOutput, Error>;
    async fn resolve_font(&self, spec: &FontInstallSpec) -> Result<(DefinedFontInstallSpec, FontDescription), Error>;
    async fn download_font(&self, spec: &DefinedFontInstallSpec, dir: &PathBuf) -> Result<HashMap<DefinedFontVariantSpec, PathBuf>, Error>;
    fn description(&self) -> SourceDescription {
        SourceDescription {
            id: self.id().to_string(),
            name: self.id().to_string()
        }
    }
}

#[derive(Clone, Debug)]
pub struct SourceDescription {
    pub id: String,
    pub name: String
}
pub trait SourceExt {
    fn description(&self) -> SourceDescription;
}