feat(download manager): only allow downloads for supported platforms

This commit is contained in:
DecDuck
2024-12-15 16:15:11 +11:00
parent 52436942eb
commit 269dcbb6f3
11 changed files with 107 additions and 59 deletions

View File

@ -0,0 +1,45 @@
use std::{collections::HashMap, sync::LazyLock};
use serde::{Deserialize, Serialize};
pub struct ProcessManager {
current_platform: Platform,
}
impl ProcessManager {
pub fn new() -> Self {
ProcessManager {
current_platform: if cfg!(windows) {
Platform::Windows
} else {
Platform::Linux
},
}
}
pub fn valid_platform(&self, platform: &Platform) -> Result<bool, String> {
let current = &self.current_platform;
let valid_platforms = PROCESS_COMPATABILITY_MATRIX
.get(current)
.ok_or("Incomplete platform compatability matrix.")?;
Ok(valid_platforms.contains(platform))
}
}
#[derive(Eq, Hash, PartialEq, Serialize, Deserialize, Clone)]
pub enum Platform {
Windows,
Linux,
}
pub type ProcessCompatabilityMatrix = HashMap<Platform, Vec<Platform>>;
pub static PROCESS_COMPATABILITY_MATRIX: LazyLock<ProcessCompatabilityMatrix> =
LazyLock::new(|| {
let mut matrix: ProcessCompatabilityMatrix = HashMap::new();
matrix.insert(Platform::Windows, vec![Platform::Windows]);
matrix.insert(Platform::Linux, vec![Platform::Linux]); // TODO: add Proton support
return matrix;
});