From 963762669c1b5e1f98bd33101533af9e64838b41 Mon Sep 17 00:00:00 2001 From: LynithDev <61880709+LynithDev@users.noreply.github.com> Date: Sun, 2 Jun 2024 22:01:15 +0200 Subject: [PATCH] feat: Specta works! --- desktop/src-tauri/src/api/commands.rs | 49 ++++++++++++++++++++++++--- desktop/src/ui/pages/Home.tsx | 5 +++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/desktop/src-tauri/src/api/commands.rs b/desktop/src-tauri/src/api/commands.rs index 23b63e27..607befbe 100644 --- a/desktop/src-tauri/src/api/commands.rs +++ b/desktop/src-tauri/src/api/commands.rs @@ -1,13 +1,19 @@ -use crate::api; +use std::path::PathBuf; + +use onelauncher::{cluster, data::{Loader, PackageData}}; +use serde::{Deserialize, Serialize}; +use specta::Type; +use uuid::Uuid; #[macro_export] macro_rules! collect_commands { () => { { - use crate::api::commands::*; + use $crate::api::commands::*; tauri_specta::ts::builder() .commands(tauri_specta::collect_commands![ - is_dev + is_dev, + create_cluster ]) } }; @@ -17,4 +23,39 @@ macro_rules! collect_commands { #[tauri::command] pub fn is_dev() -> bool { cfg!(debug_assertions) -} \ No newline at end of file +} + +#[derive(Serialize, Deserialize, Type)] +pub struct CreateCluster { + name: String, + mc_version: String, + mod_loader: Loader, + loader_version: Option, + icon: Option, + icon_url: Option, + package_data: Option, + skip: Option, + skip_watch: Option, +} + +#[specta::specta] +#[tauri::command] +pub async fn create_cluster(props: CreateCluster) -> Result { + let path = cluster::create::create_cluster( + props.name, + props.mc_version, + props.mod_loader, + props.loader_version, + props.icon, + props.icon_url, + props.package_data, + props.skip, + props.skip_watch, + ).await?; + + if let Some(cluster) = cluster::get(&path, None).await? { + Ok(cluster.uuid) + } else { + Err("Cluster does not exist".to_string()) + } +} diff --git a/desktop/src/ui/pages/Home.tsx b/desktop/src/ui/pages/Home.tsx index b8a36f4a..adb8bbc0 100644 --- a/desktop/src/ui/pages/Home.tsx +++ b/desktop/src/ui/pages/Home.tsx @@ -15,6 +15,7 @@ import Button from '../components/base/Button'; import Tag from '../components/base/Tag'; import TextField from '../components/base/TextField'; import ClusterCover from '~ui/components/game/ClusterCover'; +import { bridge } from '~index'; // TODO: Replace this into it's own component // possibly with the core ui lirbary with autogenerated and optimized svgs pls @@ -184,6 +185,10 @@ function HomePage() { // const [clusters, { refetch }] = createResource(getClustersGrouped); async function newInstance() { + // bridge.commands.createCluster({ + + // }); + // await createCluster({ // name: '1.0 cluster', // version: 'a1.0.11',