mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2026-07-24 17:03:14 +10:00
refactor: Converting useGame to DownloadableMetadata
Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
use std::{
|
||||
fs::{self, create_dir_all},
|
||||
io::{self, copy},
|
||||
path::{Path, PathBuf},
|
||||
sync::{mpsc::Sender, Arc, Mutex},
|
||||
u64, usize,
|
||||
usize,
|
||||
};
|
||||
|
||||
use log::{debug, error, warn};
|
||||
@@ -65,7 +63,7 @@ impl URLDownloader {
|
||||
}
|
||||
}
|
||||
|
||||
fn download(&self, app_handle: &AppHandle) -> Result<bool, ApplicationDownloadError> {
|
||||
fn download(&self, _app_handle: &AppHandle) -> Result<bool, ApplicationDownloadError> {
|
||||
// TODO: Fix these unwraps and implement From<io::Error> for ApplicationDownloadError
|
||||
let client = reqwest::blocking::Client::builder()
|
||||
.redirect(Policy::default())
|
||||
@@ -80,8 +78,6 @@ impl URLDownloader {
|
||||
.unwrap_or(usize::MAX);
|
||||
let response = client.get(&self.url).send().unwrap();
|
||||
|
||||
println!("{:?}, content length: {}", response, content_length);
|
||||
|
||||
self.set_progress_object_params(content_length);
|
||||
|
||||
let progress = self.progress.get(0);
|
||||
@@ -159,7 +155,7 @@ impl Downloadable for URLDownloader {
|
||||
.remove(&self.metadata());
|
||||
}
|
||||
|
||||
fn on_complete(&self, app_handle: &tauri::AppHandle) {
|
||||
fn on_complete(&self, _app_handle: &tauri::AppHandle) {
|
||||
println!("Completed url download");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
use std::sync::Mutex;
|
||||
|
||||
use crate::{database::models::data::DownloadableMetadata, AppState};
|
||||
use crate::{
|
||||
database::models::data::{DownloadType, DownloadableMetadata},
|
||||
download_manager::download_manager::QueueMetadata,
|
||||
AppState,
|
||||
};
|
||||
|
||||
#[tauri::command]
|
||||
pub fn pause_downloads(state: tauri::State<'_, Mutex<AppState>>) {
|
||||
@@ -29,3 +33,28 @@ pub fn move_download_in_queue(
|
||||
pub fn cancel_game(state: tauri::State<'_, Mutex<AppState>>, meta: DownloadableMetadata) {
|
||||
state.lock().unwrap().download_manager.cancel(meta)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_queue_metadata(
|
||||
state: tauri::State<'_, Mutex<AppState>>,
|
||||
meta: DownloadableMetadata,
|
||||
) -> Option<QueueMetadata> {
|
||||
match meta.download_type {
|
||||
DownloadType::Game => {
|
||||
let state = state.lock().unwrap();
|
||||
let game = state.games.get(&meta.id).unwrap();
|
||||
Some(QueueMetadata {
|
||||
cover: game.m_cover_object_id.clone(),
|
||||
m_short_description: game.m_short_description.clone(),
|
||||
name: game.m_name.clone(),
|
||||
})
|
||||
}
|
||||
DownloadType::Tool => Some(QueueMetadata {
|
||||
cover: "IDK Man".to_string(),
|
||||
m_short_description: "This is a tool".to_string(),
|
||||
name: "Download".to_string(),
|
||||
}),
|
||||
DownloadType::DLC => unimplemented!(),
|
||||
DownloadType::Mod => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,14 @@ pub enum DownloadStatus {
|
||||
Error,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct QueueMetadata {
|
||||
pub cover: String,
|
||||
pub m_short_description: String,
|
||||
pub name: String
|
||||
}
|
||||
|
||||
/// Accessible front-end for the DownloadManager
|
||||
///
|
||||
/// The system works entirely through signals, both internally and externally,
|
||||
|
||||
@@ -4,7 +4,7 @@ use tauri::AppHandle;
|
||||
|
||||
use crate::{
|
||||
database::models::data::DownloadableMetadata,
|
||||
error::application_download_error::ApplicationDownloadError,
|
||||
error::{application_download_error::ApplicationDownloadError, remote_access_error::RemoteAccessError},
|
||||
};
|
||||
|
||||
use super::{
|
||||
@@ -23,3 +23,4 @@ pub trait Downloadable: Send + Sync {
|
||||
fn on_incomplete(&self, app_handle: &AppHandle);
|
||||
fn on_cancelled(&self, app_handle: &AppHandle);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ use crate::download_manager::util::progress_object::{ProgressHandle, ProgressObj
|
||||
use crate::error::application_download_error::ApplicationDownloadError;
|
||||
use crate::error::remote_access_error::RemoteAccessError;
|
||||
use crate::games::downloads::manifest::{DropDownloadContext, DropManifest};
|
||||
use crate::games::library::{on_game_complete, push_game_update, GameUpdateEvent};
|
||||
use crate::games::library::{on_game_complete, push_game_update, Game, GameUpdateEvent};
|
||||
use crate::remote::cache::get_cached_object;
|
||||
use crate::remote::requests::make_request;
|
||||
use crate::DB;
|
||||
use log::{debug, error, info};
|
||||
|
||||
@@ -31,14 +31,14 @@ pub struct FetchGameStruct {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Game {
|
||||
id: String,
|
||||
m_name: String,
|
||||
m_short_description: String,
|
||||
pub m_name: String,
|
||||
pub m_short_description: String,
|
||||
m_description: String,
|
||||
// mDevelopers
|
||||
// mPublishers
|
||||
m_icon_object_id: String,
|
||||
m_banner_object_id: String,
|
||||
m_cover_object_id: String,
|
||||
pub m_cover_object_id: String,
|
||||
m_image_library_object_ids: Vec<String>,
|
||||
m_image_carousel_object_ids: Vec<String>,
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ mod error;
|
||||
mod process;
|
||||
mod remote;
|
||||
|
||||
use crate::{client::commands::queue_url_download, database::db::DatabaseImpls};
|
||||
use crate::{client::commands::queue_url_download, database::db::DatabaseImpls, download_manager::commands::get_queue_metadata};
|
||||
use client::{
|
||||
autostart::{get_autostart_enabled, sync_autostart_on_startup, toggle_autostart},
|
||||
cleanup::{cleanup_and_exit, quit},
|
||||
@@ -265,6 +265,7 @@ pub fn run() {
|
||||
cancel_game,
|
||||
uninstall_game,
|
||||
queue_url_download,
|
||||
get_queue_metadata,
|
||||
// Processes
|
||||
launch_game,
|
||||
kill_game,
|
||||
|
||||
Reference in New Issue
Block a user