From 1521bbb96a6a1840b8844a5191c40e2e507ea112 Mon Sep 17 00:00:00 2001 From: LynithDev <61880709+LynithDev@users.noreply.github.com> Date: Sat, 16 Nov 2024 14:40:41 +0100 Subject: [PATCH] feat: Package inferring from hash --- Cargo.lock | 7 + Cargo.toml | 1 + apps/desktop/src/api/commands/package.rs | 3 +- .../src/ui/pages/cluster/ClusterMods.tsx | 113 ++++---- apps/testing/examples/cluster_packages.rs | 6 +- apps/testing/examples/murmur2_hash.rs | 14 + packages/client/src/bindings.ts | 8 +- packages/core/Cargo.toml | 1 + .../core/src/api/cluster/content/package.rs | 25 +- packages/core/src/api/cluster/create.rs | 4 +- .../src/api/package/content/curseforge.rs | 46 ++- packages/core/src/api/package/content/mod.rs | 21 ++ .../core/src/api/package/content/modrinth.rs | 26 +- packages/core/src/store/mod.rs | 2 +- packages/core/src/store/package.rs | 268 +++++++++++++----- packages/core/src/utils/crypto.rs | 51 ++++ packages/core/src/utils/mod.rs | 1 + 17 files changed, 432 insertions(+), 165 deletions(-) create mode 100644 apps/testing/examples/murmur2_hash.rs create mode 100644 packages/core/src/utils/crypto.rs diff --git a/Cargo.lock b/Cargo.lock index aa81e667..654a9b30 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3336,6 +3336,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "murmur2" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb585ade2549a017db2e35978b77c319214fa4b37cede841e27954dd6e8f3ca8" + [[package]] name = "ndk" version = "0.9.0" @@ -3813,6 +3819,7 @@ dependencies = [ "interpulse", "iota_stronghold", "lazy_static", + "murmur2", "notify", "notify-debouncer-mini", "onelauncher_gamemode", diff --git a/Cargo.toml b/Cargo.toml index 8e62c8b6..d4a2c25a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -133,6 +133,7 @@ async-compression = { version = "0.4.12", features = [ "flate2", "tokio" ] } flate2 = { version = "1.0" } sha1_smol = { version = "1.0", features = [ "std" ] } sha2 = { version = "0.10" } +murmur2 = { version = "0.1.0" } bytes = { version = "1.7" } # # ============= UTILITY ============= # # diff --git a/apps/desktop/src/api/commands/package.rs b/apps/desktop/src/api/commands/package.rs index f59967ac..40690bb6 100644 --- a/apps/desktop/src/api/commands/package.rs +++ b/apps/desktop/src/api/commands/package.rs @@ -213,7 +213,8 @@ pub async fn sync_cluster_packages(cluster_path: ClusterPath) -> Result<(), Stri pub async fn sync_cluster_packages_by_type( cluster_path: ClusterPath, package_type: PackageType, + clear: Option, ) -> Result<(), String> { - package::sync_packages_by_type(&cluster_path, package_type).await?; + package::sync_packages_by_type(&cluster_path, package_type, clear).await?; Ok(()) } diff --git a/apps/frontend/src/ui/pages/cluster/ClusterMods.tsx b/apps/frontend/src/ui/pages/cluster/ClusterMods.tsx index 66b4c72c..38361a6e 100644 --- a/apps/frontend/src/ui/pages/cluster/ClusterMods.tsx +++ b/apps/frontend/src/ui/pages/cluster/ClusterMods.tsx @@ -1,6 +1,6 @@ -import type { ManagedPackage, Package, Providers } from '@onelauncher/client/bindings'; +import type { Package } from '@onelauncher/client/bindings'; import UFuzzy from '@leeoniya/ufuzzy'; -import { FilterFunnel01Icon, SearchMdIcon, Trash03Icon } from '@untitled-theme/icons-solid'; +import { FilterFunnel01Icon, RefreshCw01Icon, SearchMdIcon, Trash03Icon } from '@untitled-theme/icons-solid'; import { bridge } from '~imports'; import Button from '~ui/components/base/Button'; import TextField from '~ui/components/base/TextField'; @@ -8,39 +8,13 @@ import ScrollableContainer from '~ui/components/ScrollableContainer'; import Sidebar from '~ui/components/Sidebar'; import useBrowser from '~ui/hooks/useBrowser'; import useClusterContext from '~ui/hooks/useCluster'; -import useCommand, { tryResult } from '~ui/hooks/useCommand'; -import { createEffect, createResource, createSignal, For, Match, Show, Switch } from 'solid-js'; +import useCommand from '~ui/hooks/useCommand'; +import { createEffect, createSignal, For, Match, Show, Switch } from 'solid-js'; -// TODO: Possibly optimise this as it has 2 cloned lists, and another containing only the names +// TODO: This needs a rewrite. function ClusterMods() { const [cluster] = useClusterContext(); - const [mods, { refetch }] = useCommand(cluster, () => bridge.commands.getClusterPackages(cluster()?.path || '', 'mod')); - const [managedMods] = createResource(mods, async () => { - const list = mods(); - if (!list) - return Promise.resolve(new Map()); - - const providers: Map = new Map(); - - list.forEach((mod) => { - if (mod.meta.type === 'managed') - providers.set(mod.meta.provider, [ - ...(providers.get(mod.meta.provider) || []), - mod.meta.package_id, - ]); - }); - - const formatted: Map = new Map(); - - for (const [provider, packageIds] of providers.entries()) { - const result = await tryResult(() => bridge.commands.getProviderPackages(provider, packageIds)); - formatted.set(provider, result); - } - - return formatted; - }, { - initialValue: new Map(), - }); + const [mods, { refetch: refetchMods }] = useCommand(cluster, () => bridge.commands.getClusterPackages(cluster()?.path || '', 'mod')); // Mods to display, should be a clone of the mods array but sorted const [displayedMods, setDisplayedMods] = createSignal([]); @@ -101,7 +75,15 @@ function ClusterMods() {

Mods

-
+
+