mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-15 09:11:28 +10:00
refactor(download manager): Fully separate & generic download manager
Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
@ -2,7 +2,7 @@ use std::{
|
||||
collections::HashMap,
|
||||
fs::{self, create_dir_all},
|
||||
path::{Path, PathBuf},
|
||||
sync::{LazyLock, Mutex, RwLockWriteGuard},
|
||||
sync::{Arc, LazyLock, Mutex, RwLockWriteGuard},
|
||||
};
|
||||
|
||||
use directories::BaseDirs;
|
||||
@ -12,7 +12,7 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
use tauri::AppHandle;
|
||||
use url::Url;
|
||||
|
||||
use crate::{library::push_application_update, process::process_manager::Platform, state::DownloadStatusManager, DB};
|
||||
use crate::{download_manager::downloadable_metadata::DownloadableMetadata, library::push_game_update, process::process_manager::Platform, state::DownloadStatusManager, DB};
|
||||
|
||||
#[derive(serde::Serialize, Clone, Deserialize)]
|
||||
pub struct DatabaseAuth {
|
||||
@ -60,11 +60,11 @@ pub struct ApplicationVersion {
|
||||
pub struct DatabaseApplications {
|
||||
pub install_dirs: Vec<String>,
|
||||
// Guaranteed to exist if the game also exists in the app state map
|
||||
pub statuses: HashMap<String, ApplicationStatus>,
|
||||
pub versions: HashMap<String, HashMap<String, ApplicationVersion>>,
|
||||
pub statuses: HashMap<DownloadableMetadata, ApplicationStatus>,
|
||||
pub versions: HashMap<DownloadableMetadata, HashMap<String, ApplicationVersion>>,
|
||||
|
||||
#[serde(skip)]
|
||||
pub transient_statuses: HashMap<String, ApplicationTransientStatus>,
|
||||
pub transient_statuses: HashMap<DownloadableMetadata, ApplicationTransientStatus>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
@ -220,9 +220,9 @@ pub fn fetch_download_dir_stats() -> Result<Vec<String>, String> {
|
||||
Ok(directories)
|
||||
}
|
||||
|
||||
pub fn set_application_status<F: FnOnce(&mut RwLockWriteGuard<'_, Database>, &String)>(
|
||||
pub fn set_game_status<F: FnOnce(&mut RwLockWriteGuard<'_, Database>, &Arc<DownloadableMetadata>)>(
|
||||
app_handle: &AppHandle,
|
||||
id: String,
|
||||
id: Arc<DownloadableMetadata>,
|
||||
setter: F,
|
||||
) {
|
||||
let mut db_handle = DB.borrow_data_mut().unwrap();
|
||||
@ -232,5 +232,5 @@ pub fn set_application_status<F: FnOnce(&mut RwLockWriteGuard<'_, Database>, &St
|
||||
|
||||
let status = DownloadStatusManager::fetch_state(&id);
|
||||
|
||||
push_application_update(app_handle, id, status);
|
||||
push_game_update(app_handle, id, status);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user