From 8f928d63059a1f7ef41a692b76192b00fc99d36e Mon Sep 17 00:00:00 2001 From: LynithDev <61880709+LynithDev@users.noreply.github.com> Date: Tue, 23 Jul 2024 20:56:40 +0200 Subject: [PATCH] feat: Added more commands + made sure minecraft launches --- apps/desktop/src-tauri/build.rs | 41 ++++++++----- .../permissions/onelauncher/default.toml | 21 +++++-- apps/desktop/src-tauri/src/api/commands.rs | 58 +++++++++++++++++-- .../src/ui/pages/cluster/ClusterOverview.tsx | 4 ++ crates/core/src/api/cluster/create.rs | 8 +-- crates/core/src/game/arguments.rs | 2 +- crates/core/src/store/clusters.rs | 4 ++ 7 files changed, 110 insertions(+), 28 deletions(-) diff --git a/apps/desktop/src-tauri/build.rs b/apps/desktop/src-tauri/build.rs index 02f8e137..1b4f17d9 100644 --- a/apps/desktop/src-tauri/build.rs +++ b/apps/desktop/src-tauri/build.rs @@ -5,21 +5,34 @@ fn main() { .plugin( "onelauncher", tauri_build::InlinedPlugin::new().commands(&[ - "begin_msa", - "finish_msa", - "get_users", - "get_user", - "remove_user", - "launch_cluster", - "create_cluster", + // User + "begin_msa", + "finish_msa", + "get_users", + "get_user", + "remove_user", + + // Cluster + "create_cluster", "remove_cluster", - "get_clusters", - "get_cluster", - "get_manifest", - "get_settings", - "set_settings", - "get_program_info", - "get_minecraft_versions" + "get_cluster", + "get_clusters", + "run_cluster", + + // Processor + "get_running_clusters", + "get_processes_by_path", + "kill_process", + + // Settings + "get_settings", + "set_settings", + + // Metadata + "get_minecraft_versions", + + // Other + "get_program_info", ]), ), ) diff --git a/apps/desktop/src-tauri/permissions/onelauncher/default.toml b/apps/desktop/src-tauri/permissions/onelauncher/default.toml index 28fe4c82..9e4b1469 100644 --- a/apps/desktop/src-tauri/permissions/onelauncher/default.toml +++ b/apps/desktop/src-tauri/permissions/onelauncher/default.toml @@ -1,19 +1,32 @@ [default] description = "Default permissions for the plugin" permissions = [ + # User "allow-begin-msa", "allow-finish-msa", "allow-get-users", "allow-get-user", "allow-remove-user", - "allow-launch-cluster", + + # Cluster "allow-create-cluster", "allow-remove-cluster", - "allow-get-clusters", "allow-get-cluster", - "allow-get-manifest", + "allow-get-clusters", + "allow-run-cluster", + + # Processor + "allow-get-running-clusters", + "allow-get-processes-by-path", + "allow-kill-process", + + # Settings "allow-get-settings", "allow-set-settings", + + # Metadata + "allow-get-minecraft-versions", + + # Other "allow-get-program-info", - "allow-get-minecraft-versions" ] diff --git a/apps/desktop/src-tauri/src/api/commands.rs b/apps/desktop/src-tauri/src/api/commands.rs index 995d710a..df78e850 100644 --- a/apps/desktop/src-tauri/src/api/commands.rs +++ b/apps/desktop/src-tauri/src/api/commands.rs @@ -3,8 +3,8 @@ use std::path::PathBuf; use interpulse::api::minecraft::Version; use onelauncher::constants::{NATIVE_ARCH, TARGET_OS, VERSION}; use onelauncher::data::{Loader, MinecraftCredentials, PackageData, Settings}; -use onelauncher::store::{Cluster, MinecraftLogin}; -use onelauncher::{cluster, minecraft, settings}; +use onelauncher::store::{Cluster, ClusterPath, MinecraftLogin}; +use onelauncher::{cluster, minecraft, processor, settings}; use serde::{Deserialize, Serialize}; use specta::Type; use uuid::Uuid; @@ -19,19 +19,34 @@ macro_rules! collect_commands { .bigint(specta::ts::BigIntExportBehavior::BigInt), ) .commands(tauri_specta::collect_commands![ - begin_msa, + // User + begin_msa, finish_msa, get_users, get_user, remove_user, + + // Cluster create_cluster, remove_cluster, get_cluster, get_clusters, + run_cluster, + + // Processor + get_running_clusters, + get_processes_by_path, + kill_process, + + // Settings get_settings, set_settings, + + // Metadata + get_minecraft_versions, + + // Other get_program_info, - get_minecraft_versions ]) }}; } @@ -75,10 +90,43 @@ pub async fn create_cluster(props: CreateCluster) -> Result { #[specta::specta] #[tauri::command] pub async fn remove_cluster(uuid: Uuid) -> Result<(), String> { - let path = cluster::get_by_uuid(uuid, None).await?.ok_or("Cluster does not exist")?.cluster_path(); + let path = ClusterPath::find_by_uuid(uuid).await?; Ok(cluster::remove(&path).await?) } +#[specta::specta] +#[tauri::command] +pub async fn run_cluster(uuid: Uuid) -> Result<(Uuid, u32), String> { + let path = ClusterPath::find_by_uuid(uuid).await?; + let c_lock = cluster::run(&path).await?; + + let p_uuid = c_lock.read().await.uuid; + let p_pid = c_lock.read().await.current_child.read().await.id().unwrap_or(0); + + // processor::wait_for(&mut proc).await?; + + Ok((p_uuid, p_pid)) +} + +#[specta::specta] +#[tauri::command] +pub async fn get_running_clusters() -> Result, String> { + Ok(processor::get_running_clusters().await?) +} + +#[specta::specta] +#[tauri::command] +pub async fn get_processes_by_path(path: ClusterPath) -> Result, String> { + Ok(processor::get_uuids_by_cluster_path(path).await?) +} + +#[specta::specta] +#[tauri::command] +pub async fn kill_process(uuid: Uuid) -> Result<(), String> { + processor::kill_by_uuid(uuid).await?; + Ok(()) +} + // #[specta::specta] // #[tauri::command] // pub fn update_cluster(cluster: Cluster) -> Result<(), String> { diff --git a/apps/desktop/src/ui/pages/cluster/ClusterOverview.tsx b/apps/desktop/src/ui/pages/cluster/ClusterOverview.tsx index aa5e6cfa..2cecebbd 100644 --- a/apps/desktop/src/ui/pages/cluster/ClusterOverview.tsx +++ b/apps/desktop/src/ui/pages/cluster/ClusterOverview.tsx @@ -100,6 +100,10 @@ function DeleteModal(props: DeleteModalProps) { } function Banner(props: Cluster & { showDeletePrompt: () => void }) { + function launch() { + + } + return (
diff --git a/crates/core/src/api/cluster/create.rs b/crates/core/src/api/cluster/create.rs index 2a53d4c2..7adcb49a 100644 --- a/crates/core/src/api/cluster/create.rs +++ b/crates/core/src/api/cluster/create.rs @@ -108,12 +108,12 @@ pub async fn create_cluster( } if !skip.unwrap_or(false) { - let clone = cluster.clone(); - tokio::task::spawn(async move { - if let Err(err) = crate::game::install_minecraft(&clone, None, false).await { + // let cluster = cluster.clone(); + // tokio::task::spawn(async move { + if let Err(err) = crate::game::install_minecraft(&cluster, None, false).await { tracing::error!("failed to install Minecraft while creating cluster {}: {}", cluster.uuid, err); } - }); + // }); } State::sync().await?; diff --git a/crates/core/src/game/arguments.rs b/crates/core/src/game/arguments.rs index 970ce19b..d458e634 100644 --- a/crates/core/src/game/arguments.rs +++ b/crates/core/src/game/arguments.rs @@ -212,7 +212,7 @@ fn parse_minecraft_argument( .replace("${user_properties}", "{}") .replace("${user_type}", "msa") .replace("${version_name}", version) - .replace("${asset_index_name}", asset_index) + .replace("${assets_index_name}", asset_index) .replace( "${game_directory}", &dunce::canonicalize(game_directory) diff --git a/crates/core/src/store/clusters.rs b/crates/core/src/store/clusters.rs index d9886fc9..7eb37d20 100644 --- a/crates/core/src/store/clusters.rs +++ b/crates/core/src/store/clusters.rs @@ -53,6 +53,10 @@ impl ClusterPath { ClusterPath(path.into()) } + pub async fn find_by_uuid(uuid: Uuid) -> crate::Result { + Ok(crate::cluster::get_by_uuid(uuid, None).await?.ok_or(anyhow::anyhow!("Cluster does not exist"))?.cluster_path()) + } + /// Get the full [`PathBuf`] of the current cluster path. pub async fn full_path(&self) -> crate::Result { let state = State::get().await?;