From 0dd1365fa41945eb2acfcbdc1e5a986bafc831e2 Mon Sep 17 00:00:00 2001 From: LynithDev <61880709+LynithDev@users.noreply.github.com> Date: Thu, 28 Mar 2024 21:12:32 +0100 Subject: [PATCH] feat: Rebrand 'Instance' to 'Cluster' --- onelauncher/src/game/client.rs | 65 ++++++++++--------- onelauncher/src/game/vanilla.rs | 6 +- onelauncher/src/utils/dirs.rs | 4 +- src-tauri/build.rs | 6 +- .../permissions/onelauncher/default.toml | 6 +- src-tauri/src/api/game.rs | 18 ++--- src-tauri/src/api/mod.rs | 6 +- src/bridge/game.ts | 49 +++++++------- src/index.tsx | 12 ++-- src/types/game.d.ts | 6 +- src/ui/pages/Home.tsx | 58 ++++++++--------- .../ClusterMods.tsx} | 4 +- .../ClusterOverview.tsx} | 4 +- src/ui/pages/{instances => cluster}/index.tsx | 8 +-- 14 files changed, 123 insertions(+), 129 deletions(-) rename src/ui/pages/{instances/InstanceMods.tsx => cluster/ClusterMods.tsx} (55%) rename src/ui/pages/{instances/InstanceOverview.tsx => cluster/ClusterOverview.tsx} (51%) rename src/ui/pages/{instances => cluster}/index.tsx (79%) diff --git a/onelauncher/src/game/client.rs b/onelauncher/src/game/client.rs index 30ed7444..68c6af43 100644 --- a/onelauncher/src/game/client.rs +++ b/onelauncher/src/game/client.rs @@ -32,7 +32,7 @@ pub struct Manifest { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct Instance { +pub struct Cluster { pub id: Uuid, pub created_at: DateTime, pub name: String, @@ -57,17 +57,17 @@ impl ClientType { pub fn get_impl<'a>( client: &'a ClientType, - instance: &'a Instance, + cluster: &'a Cluster, manifest: &'a Manifest, ) -> Box + 'a> { Box::new(match client { - ClientType::Vanilla(_) => vanilla::VanillaClient::new(instance, manifest), + ClientType::Vanilla(_) => vanilla::VanillaClient::new(cluster, manifest), }) } #[async_trait] pub trait ClientTrait<'a>: Send + Sync { - fn new(instance: &'a Instance, manifest: &'a Manifest) -> Self + fn new(cluster: &'a Cluster, manifest: &'a Manifest) -> Self where Self: Sized; @@ -79,9 +79,10 @@ pub trait ClientTrait<'a>: Send + Sync { async fn install_natives(&self) -> crate::Result<()>; async fn install_assets(&self) -> crate::Result<()>; - fn get_instance(&self) -> &'a Instance + fn get_cluster(&self) -> &'a Cluster where Self: Sized; + fn get_manifest(&self) -> &'a Manifest where Self: Sized; @@ -97,7 +98,7 @@ macro_rules! create_game_client { #[derive(Debug, Clone)] pub struct $client<'a> { - pub instance: &'a crate::game::client::Instance, + pub cluster: &'a crate::game::client::Cluster, pub manifest: &'a crate::game::client::Manifest, $(pub $name: $type),* } @@ -107,11 +108,11 @@ macro_rules! create_game_client { #[macro_export] macro_rules! impl_game_client { () => { - fn get_instance(&self) -> &'a crate::game::client::Instance + fn get_cluster(&self) -> &'a crate::game::client::Cluster where Self: Sized, { - self.instance + self.cluster } fn get_manifest(&self) -> &'a crate::game::client::Manifest @@ -125,54 +126,54 @@ macro_rules! impl_game_client { #[derive(Debug, thiserror::Error)] pub enum ClientManagerError { - #[error("Instance not found")] - InstanceNotFound, + #[error("Cluster not found")] + ClusterNotFound, #[error("Manifest not found")] ManifestNotFound, } pub struct ClientManager { - instances: HashMap, + clusters: HashMap, manifests: HashMap, } impl ClientManager { pub fn new() -> crate::Result { - let instances = load_and_serialize::(&dirs::instances_dir()?)?; + let clusters = load_and_serialize::(&dirs::clusters_dir()?)?; let manifests = load_and_serialize::(&dirs::manifests_dir()?)?; Ok(Self { - instances, + clusters, manifests, }) } pub fn get_impl_uuid<'a>(&'a self, uuid: Uuid) -> crate::Result + 'a>> { - let instance = self.get_instance(uuid)?; + let cluster = self.get_cluster(uuid)?; let manifest = self.get_manifest(uuid)?; - Ok(get_impl(&instance.client, &instance, &manifest)) + Ok(get_impl(&cluster.client, &cluster, &manifest)) } - pub fn get_instances(&self) -> Vec<&Instance> { - self.instances.values().collect() + pub fn get_clusters(&self) -> Vec<&Cluster> { + self.clusters.values().collect() } - pub fn get_instances_owned(&self) -> Vec { - self.instances.values().cloned().collect() + pub fn get_clusters_owned(&self) -> Vec { + self.clusters.values().cloned().collect() } - pub fn get_instance(&self, uuid: Uuid) -> crate::Result<&Instance> { - self.instances + pub fn get_cluster(&self, uuid: Uuid) -> crate::Result<&Cluster> { + self.clusters .get(&uuid) - .ok_or(ClientManagerError::InstanceNotFound.into()) + .ok_or(ClientManagerError::ClusterNotFound.into()) } - pub fn get_instance_mut(&mut self, uuid: Uuid) -> crate::Result<&mut Instance> { - self.instances + pub fn get_cluster_mut(&mut self, uuid: Uuid) -> crate::Result<&mut Cluster> { + self.clusters .get_mut(&uuid) - .ok_or(ClientManagerError::InstanceNotFound.into()) + .ok_or(ClientManagerError::ClusterNotFound.into()) } pub fn get_manifest(&self, uuid: Uuid) -> crate::Result<&Manifest> { @@ -187,7 +188,7 @@ impl ClientManager { .ok_or(ClientManagerError::ManifestNotFound.into()) } - pub async fn create_instance( + pub async fn create_cluster( &mut self, name: String, version: String, @@ -218,8 +219,8 @@ impl ClientManager { )?; self.manifests.insert(uuid, manifest); - // Save the instance - let instance = Instance { + // Save the cluster + let cluster = Cluster { id: uuid, created_at: Local::now(), name, @@ -229,10 +230,10 @@ impl ClientManager { }; save( - &dirs::instances_dir()?.join(format!("{}.json", uuid)), - &instance, + &dirs::clusters_dir()?.join(format!("{}.json", uuid)), + &cluster, )?; - self.instances.insert(uuid, instance); + self.clusters.insert(uuid, cluster); Ok(uuid) } @@ -292,7 +293,7 @@ where let parsed = match serde_json::from_str::(&content) { Ok(parsed) => parsed, Err(_) => { - eprintln!("Couldn't parse file content as JSON: '{:?}'", content); + eprintln!("Couldn't parse file '{}' content as JSON", path.display()); continue; } }; diff --git a/onelauncher/src/game/vanilla.rs b/onelauncher/src/game/vanilla.rs index 1f563394..97b7f4c4 100644 --- a/onelauncher/src/game/vanilla.rs +++ b/onelauncher/src/game/vanilla.rs @@ -1,5 +1,5 @@ use super::{ - client::{ClientTrait, Instance, Manifest, Version}, + client::{ClientTrait, Cluster, Manifest, Version}, minecraft::MinecraftManifest, }; use crate::{ @@ -22,8 +22,8 @@ create_game_client! { impl<'a> ClientTrait<'a> for VanillaClient<'a> { impl_game_client!(); - fn new(instance: &'a Instance, manifest: &'a Manifest) -> Self { - VanillaClient { instance, manifest } + fn new(cluster: &'a Cluster, manifest: &'a Manifest) -> Self { + VanillaClient { cluster, manifest } } async fn launch(&self) -> crate::Result<()> { diff --git a/onelauncher/src/utils/dirs.rs b/onelauncher/src/utils/dirs.rs index 54edbff5..bce9f719 100644 --- a/onelauncher/src/utils/dirs.rs +++ b/onelauncher/src/utils/dirs.rs @@ -22,8 +22,8 @@ pub fn java_dir() -> crate::Result { Ok(app_config_dir()?.join("java")) } -pub fn instances_dir() -> crate::Result { - Ok(app_config_dir()?.join("instances")) +pub fn clusters_dir() -> crate::Result { + Ok(app_config_dir()?.join("clusters")) } pub fn manifests_dir() -> crate::Result { diff --git a/src-tauri/build.rs b/src-tauri/build.rs index e739fd85..6ccf4925 100644 --- a/src-tauri/build.rs +++ b/src-tauri/build.rs @@ -6,9 +6,9 @@ fn main() { InlinedPlugin::new().commands(&[ "login_msa", "refresh_client_manager", - "create_instance", - "get_instances", - "get_instance", + "create_cluster", + "get_clusters", + "get_cluster", "get_manifest", ]), )); diff --git a/src-tauri/permissions/onelauncher/default.toml b/src-tauri/permissions/onelauncher/default.toml index af03ad78..1361f0e9 100644 --- a/src-tauri/permissions/onelauncher/default.toml +++ b/src-tauri/permissions/onelauncher/default.toml @@ -2,9 +2,9 @@ description = "Default permissions for the plugin" permissions = [ "allow-refresh-client-manager", - "allow-create-instance", - "allow-get-instances", - "allow-get-instance", + "allow-create-cluster", + "allow-get-clusters", + "allow-get-cluster", "allow-get-manifest", "allow-login-msa", ] diff --git a/src-tauri/src/api/game.rs b/src-tauri/src/api/game.rs index 41eebbaf..c72a65be 100644 --- a/src-tauri/src/api/game.rs +++ b/src-tauri/src/api/game.rs @@ -1,4 +1,4 @@ -use onelauncher::game::client::{ClientType, Instance, Manifest}; +use onelauncher::game::client::{ClientType, Cluster, Manifest}; use tauri::State; use tokio::sync::Mutex; use uuid::Uuid; @@ -6,7 +6,7 @@ use uuid::Uuid; use super::GameManagerState; #[tauri::command] -pub async fn create_instance( +pub async fn create_cluster( state: State<'_, Mutex>, name: String, version: String, @@ -16,26 +16,26 @@ pub async fn create_instance( ) -> Result { let manager = &mut state.lock().await.client_manager; let uuid = manager - .create_instance(name, version, cover, group, client) + .create_cluster(name, version, cover, group, client) .await?; Ok(uuid) } #[tauri::command] -pub async fn get_instances( +pub async fn get_clusters( state: State<'_, Mutex>, -) -> Result, String> { +) -> Result, String> { let manager = &mut state.lock().await.client_manager; - Ok(manager.get_instances_owned()) + Ok(manager.get_clusters_owned()) } #[tauri::command] -pub async fn get_instance( +pub async fn get_cluster( state: State<'_, Mutex>, uuid: Uuid, -) -> Result { +) -> Result { let manager = &mut state.lock().await.client_manager; - let instance = manager.get_instance(uuid)?; + let instance = manager.get_cluster(uuid)?; Ok(instance.clone()) } diff --git a/src-tauri/src/api/mod.rs b/src-tauri/src/api/mod.rs index ecbe4aeb..485e6a53 100644 --- a/src-tauri/src/api/mod.rs +++ b/src-tauri/src/api/mod.rs @@ -23,9 +23,9 @@ pub fn init() -> TauriPlugin { }) .invoke_handler(tauri::generate_handler![ auth::login_msa, - game::create_instance, - game::get_instances, - game::get_instance, + game::create_cluster, + game::get_clusters, + game::get_cluster, game::get_manifest, refresh_client_manager, ]) diff --git a/src/bridge/game.ts b/src/bridge/game.ts index 6d4005a7..2e726cc6 100644 --- a/src/bridge/game.ts +++ b/src/bridge/game.ts @@ -1,7 +1,7 @@ import { invoke } from '@tauri-apps/api/core'; -export async function getInstance(uuid: string): Promise { - return await invoke('plugin:onelauncher|get_instance', { +export async function getCluster(uuid: string): Promise { + return await invoke('plugin:onelauncher|get_cluster', { uuid, }); } @@ -12,22 +12,22 @@ export async function getManifest(uuid: string): Promise { }); } -export async function getInstancesWithManifests(): Promise { - const instances = await getInstances(); +export async function getClustersWithManifests(): Promise { + const clusters = await getClusters(); - return Promise.all(instances.map(async instance => ({ - instance, - manifest: await getManifest(instance.id), + return Promise.all(clusters.map(async cluster => ({ + cluster, + manifest: await getManifest(cluster.id), }))); } -export async function getGroupedInstances(): Promise> { - const instances = await getInstancesWithManifests(); - const map = new Map(); +export async function getClustersGrouped(): Promise> { + const clusters = await getClustersWithManifests(); + const map = new Map(); - instances.forEach((instance, index) => { - const groupName = instance.instance.group || 'Unnamed'; - const value = { ...instance, index }; + clusters.forEach((cluster, index) => { + const groupName = cluster.cluster.group || 'Unnamed'; + const value = { ...cluster, index }; if (map.has(groupName)) map.get(groupName)!.push(value); @@ -38,24 +38,19 @@ export async function getGroupedInstances(): Promise { - return await invoke('plugin:onelauncher|get_instances'); +export async function getClusters(): Promise { + return await invoke('plugin:onelauncher|get_clusters'); } -export async function createInstance(instance: Omit & { version: string }): Promise { +export async function createCluster(cluster: Omit & { version: string }): Promise { return await invoke( - 'plugin:onelauncher|create_instance', + 'plugin:onelauncher|create_cluster', { - name: instance.name, - version: instance.version, - client: instance.client, - // cover: instance.cover, - // group: instance.group, - }, - { - headers: { - Accept: 'text/plain', - }, + name: cluster.name, + version: cluster.version, + client: cluster.client, + // cover: cluster.cover, + // group: cluster.group, }, ); } diff --git a/src/index.tsx b/src/index.tsx index d696ff77..d92951fc 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -8,18 +8,18 @@ import App from './ui/App'; import HomePage from './ui/pages/Home'; import BrowserPage from './ui/pages/Browser'; import UpdatesPage from './ui/pages/Updates'; -import InstancePage from './ui/pages/instances'; -import InstanceOverview from './ui/pages/instances/InstanceOverview'; -import InstanceMods from './ui/pages/instances/InstanceMods'; +import ClusterPage from './ui/pages/cluster'; +import ClusterOverview from './ui/pages/cluster/ClusterOverview'; +import ClusterMods from './ui/pages/cluster/ClusterMods'; render(() => ( - - - + + + ), document.getElementById('root') as HTMLElement); diff --git a/src/types/game.d.ts b/src/types/game.d.ts index 7c3ca779..5e25c09c 100644 --- a/src/types/game.d.ts +++ b/src/types/game.d.ts @@ -1,6 +1,6 @@ declare namespace Core { - export interface InstanceWithManifest { - instance: Instance, + export interface ClusterWithManifest { + cluster: Cluster, manifest: Manifest, } @@ -16,7 +16,7 @@ declare namespace Core { }, } - export interface Instance { + export interface Cluster { id: string, createdAt: number, name: string, diff --git a/src/ui/pages/Home.tsx b/src/ui/pages/Home.tsx index e4052ee1..9799fc22 100644 --- a/src/ui/pages/Home.tsx +++ b/src/ui/pages/Home.tsx @@ -1,7 +1,6 @@ import { CheckIcon, DotsVerticalIcon, - Download01Icon, EyeIcon, PlayIcon, PlusIcon, @@ -16,8 +15,7 @@ import Tag from '../components/base/Tag'; import TextField from '../components/base/TextField'; import defaultCover from '../../assets/images/default_instance_cover.jpg'; import ContextMenu from '../components/overlay/ContextMenu'; -import { createInstance, getGroupedInstances, getInstancesWithManifests } from '../../bridge/game'; -import Modal from '../components/overlay/Modal'; +import { createCluster, getClustersGrouped } from '../../bridge/game'; // TODO: Replace this into it's own component // possibly with the core ui lirbary with autogenerated and optimized svgs pls @@ -63,14 +61,14 @@ function Banner() { ); } -interface InstanceCardContextMenuProps { +interface ClusterCardContextMenuProps { pos: Accessor<{ x: number; y: number }>; contextMenuVisible: Accessor; setContextMenuVisible: Setter; id: string; } -function InstanceCardContextMenu(props: InstanceCardContextMenuProps) { +function ClusterCardContextMenu(props: ClusterCardContextMenuProps) { const navigate = useNavigate(); return ( @@ -83,7 +81,7 @@ function InstanceCardContextMenu(props: InstanceCardContextMenuProps) { icon={} text="View" onClick={() => { - navigate(`/instances/?id=${props.id}`); + navigate(`/clusters/?id=${props.id}`); }} /> @@ -106,14 +104,14 @@ declare module 'solid-js' { } } -function InstanceCard(props: Core.InstanceWithManifest) { +function ClusterCard(props: Core.ClusterWithManifest) { const navigate = useNavigate(); const [pos, setPos] = createSignal({ x: 0, y: 0 }); const [contextMenuVisible, setContextMenuVisible] = createSignal(false); let ref!: HTMLDivElement; - function openInstancePage(_e: MouseEvent) { - navigate(`/instances/?id=${props.instance.id}`); + function openClusterPage(_e: MouseEvent) { + navigate(`/clusters/?id=${props.cluster.id}`); } function openContextMenu(e: MouseEvent) { @@ -129,7 +127,7 @@ function InstanceCard(props: Core.InstanceWithManifest) { return ( <>
openInstancePage(e)} + onClick={e => openClusterPage(e)} onMouseDown={e => onMouseDown(e)} onContextMenu={e => openContextMenu(e)} ref={ref} @@ -141,16 +139,16 @@ function InstanceCard(props: Core.InstanceWithManifest) { style={{ '-webkit-transform': 'translateZ(0)' }} >
-

{props.instance.name}

+

{props.cluster.name}

- {props.instance.client.type} + {props.cluster.client.type} {' '} {props.manifest.manifest.id} {/* {' '} @@ -162,38 +160,38 @@ function InstanceCard(props: Core.InstanceWithManifest) {

- ); } -interface InstanceGroupProps { +interface ClusterGroupProps { title: string; - instances: Core.InstanceWithManifest[]; + clusters: Core.ClusterWithManifest[]; } -function InstanceGroup(props: InstanceGroupProps) { +function ClusterGroup(props: ClusterGroupProps) { return (

{props.title}

- {item => } + {item => }
); } function HomePage() { - const [instances, { refetch }] = createResource(getGroupedInstances); + const [clusters, { refetch }] = createResource(getClustersGrouped); async function newInstance() { - await createInstance({ - name: 'New Instance', + await createCluster({ + name: 'New Cluster', version: '1.8.9', client: { type: 'Vanilla', @@ -217,22 +215,22 @@ function HomePage() {