mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-08-24 23:32:04 +10:00
156 refactor into workspaces (#157)
* chore: Major refactoring Still needs a massive go-over because there shouldn't be anything referencing tauri in any of the workspaces except the original one. Process manager has been refactored as an example Signed-off-by: quexeky <git@quexeky.dev> * fix: Remote tauri dependency from process Signed-off-by: quexeky <git@quexeky.dev> * refactor: Improvements to src-tauri Signed-off-by: quexeky <git@quexeky.dev> * refactor: Builds, but some logic still left to move back Signed-off-by: quexeky <git@quexeky.dev> * refactor: Finish refactor Signed-off-by: quexeky <git@quexeky.dev> * chore: Run cargo clippy && cargo fmt Signed-off-by: quexeky <git@quexeky.dev> * refactor: Move everything into src-tauri Signed-off-by: quexeky <git@quexeky.dev> --------- Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
use database::{GameDownloadStatus, borrow_db_checked};
|
||||
use download_manager::{
|
||||
DOWNLOAD_MANAGER, downloadable::Downloadable, error::ApplicationDownloadError,
|
||||
};
|
||||
use games::downloads::download_agent::GameDownloadAgent;
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn download_game(
|
||||
game_id: String,
|
||||
game_version: String,
|
||||
install_dir: usize,
|
||||
) -> Result<(), ApplicationDownloadError> {
|
||||
let sender = { DOWNLOAD_MANAGER.get_sender().clone() };
|
||||
|
||||
let game_download_agent = GameDownloadAgent::new_from_index(
|
||||
game_id.clone(),
|
||||
game_version.clone(),
|
||||
install_dir,
|
||||
sender,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let game_download_agent =
|
||||
Arc::new(Box::new(game_download_agent) as Box<dyn Downloadable + Send + Sync>);
|
||||
|
||||
DOWNLOAD_MANAGER
|
||||
.queue_download(game_download_agent.clone())
|
||||
.unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn resume_download(game_id: String) -> Result<(), ApplicationDownloadError> {
|
||||
let s = borrow_db_checked()
|
||||
.applications
|
||||
.game_statuses
|
||||
.get(&game_id)
|
||||
.unwrap()
|
||||
.clone();
|
||||
|
||||
let (version_name, install_dir) = match s {
|
||||
GameDownloadStatus::Remote {} => unreachable!(),
|
||||
GameDownloadStatus::SetupRequired { .. } => unreachable!(),
|
||||
GameDownloadStatus::Installed { .. } => unreachable!(),
|
||||
GameDownloadStatus::PartiallyInstalled {
|
||||
version_name,
|
||||
install_dir,
|
||||
} => (version_name, install_dir),
|
||||
};
|
||||
|
||||
let sender = DOWNLOAD_MANAGER.get_sender();
|
||||
let parent_dir: PathBuf = install_dir.into();
|
||||
|
||||
let game_download_agent = Arc::new(Box::new(
|
||||
GameDownloadAgent::new(
|
||||
game_id,
|
||||
version_name.clone(),
|
||||
parent_dir
|
||||
.parent()
|
||||
.unwrap_or_else(|| {
|
||||
panic!("Failed to get parent directry of {}", parent_dir.display())
|
||||
})
|
||||
.to_path_buf(),
|
||||
sender,
|
||||
)
|
||||
.await?,
|
||||
) as Box<dyn Downloadable + Send + Sync>);
|
||||
|
||||
DOWNLOAD_MANAGER
|
||||
.queue_download(game_download_agent)
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user