feat: Added more commands + made sure minecraft launches

This commit is contained in:
LynithDev 2024-07-23 20:56:40 +02:00
parent 316f1fc48a
commit 8f928d6305
7 changed files with 110 additions and 28 deletions

View file

@ -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",
]),
),
)

View file

@ -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"
]

View file

@ -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<Uuid, String> {
#[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<Vec<Cluster>, String> {
Ok(processor::get_running_clusters().await?)
}
#[specta::specta]
#[tauri::command]
pub async fn get_processes_by_path(path: ClusterPath) -> Result<Vec<Uuid>, 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> {

View file

@ -100,6 +100,10 @@ function DeleteModal(props: DeleteModalProps) {
}
function Banner(props: Cluster & { showDeletePrompt: () => void }) {
function launch() {
}
return (
<div class="flex flex-row bg-component-bg rounded-xl p-2.5 gap-x-2.5">
<div class="w-48 rounded-lg overflow-hidden border border-gray-10">

View file

@ -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?;

View file

@ -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)

View file

@ -53,6 +53,10 @@ impl ClusterPath {
ClusterPath(path.into())
}
pub async fn find_by_uuid(uuid: Uuid) -> crate::Result<Self> {
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<PathBuf> {
let state = State::get().await?;