diff --git a/apps/desktop/src/api/commands/mod.rs b/apps/desktop/src/api/commands/mod.rs index 3e3d5744..8e6043ec 100644 --- a/apps/desktop/src/api/commands/mod.rs +++ b/apps/desktop/src/api/commands/mod.rs @@ -76,6 +76,7 @@ macro_rules! collect_commands { get_cluster_packages, add_cluster_package, remove_cluster_package, + set_cluster_package_enabled, sync_cluster_packages, sync_cluster_packages_by_type, // Updater diff --git a/apps/desktop/src/api/commands/package.rs b/apps/desktop/src/api/commands/package.rs index 40690bb6..982bc386 100644 --- a/apps/desktop/src/api/commands/package.rs +++ b/apps/desktop/src/api/commands/package.rs @@ -152,7 +152,6 @@ pub async fn download_provider_package( &cluster.cluster_path(), pkg_path, pkg, - Some(mgd_pkg.package_type), ) .await?; @@ -182,11 +181,12 @@ pub async fn get_cluster_packages( #[tauri::command] pub async fn add_cluster_package( cluster_path: ClusterPath, - package_path: PackagePath, + file_name: String, + package_type: PackageType, pkg: Package, - package_type: Option, ) -> Result<(), String> { - package::add_package(&cluster_path, package_path, pkg, package_type).await?; + let package_path = PackagePath::new(package_type, file_name)?; + package::add_package(&cluster_path, package_path, pkg).await?; Ok(()) } @@ -194,10 +194,24 @@ pub async fn add_cluster_package( #[tauri::command] pub async fn remove_cluster_package( cluster_path: ClusterPath, - package_path: PackagePath, + file_name: String, package_type: PackageType, ) -> Result<(), String> { - package::remove_package(&cluster_path, &package_path, package_type).await?; + let package_path = PackagePath::new(package_type, file_name)?; + package::remove_package(&cluster_path, &package_path).await?; + Ok(()) +} + +#[specta::specta] +#[tauri::command] +pub async fn set_cluster_package_enabled( + cluster_path: ClusterPath, + file_name: String, + package_type: PackageType, + enabled: bool, +) -> Result<(), String> { + let package_path = PackagePath::new(package_type, file_name)?; + package::set_package_enabled(&cluster_path, &package_path, enabled).await?; Ok(()) } diff --git a/apps/frontend/src/ui/components/base/Checkbox.tsx b/apps/frontend/src/ui/components/base/Checkbox.tsx index c7de3585..b8660fce 100644 --- a/apps/frontend/src/ui/components/base/Checkbox.tsx +++ b/apps/frontend/src/ui/components/base/Checkbox.tsx @@ -1,5 +1,5 @@ import { CheckIcon } from '@untitled-theme/icons-solid'; -import { createSignal, type JSX, splitProps } from 'solid-js'; +import { createSignal, type JSX, Show, splitProps, untrack } from 'solid-js'; import styles from './Checkbox.module.scss'; type CheckboxProps = JSX.HTMLAttributes & { @@ -11,8 +11,11 @@ function Checkbox(props: CheckboxProps) { const [checked, setChecked] = createSignal(props.defaultChecked || false); const [split, rest] = splitProps(props, ['class', 'defaultChecked', 'onChecked', 'text']); - function toggle() { - const newValue = !checked(); + function toggle(e: MouseEvent) { + e.preventDefault(); + e.stopPropagation(); + + const newValue = !untrack(checked); setChecked(newValue); props.onChecked?.(newValue); } @@ -20,11 +23,13 @@ function Checkbox(props: CheckboxProps) { return (
toggle()} + onClick={toggle} {...rest} >
- + + +
{props.children}
diff --git a/apps/frontend/src/ui/pages/cluster/ClusterMods.tsx b/apps/frontend/src/ui/pages/cluster/ClusterMods.tsx index cb85f7e8..be6358f7 100644 --- a/apps/frontend/src/ui/pages/cluster/ClusterMods.tsx +++ b/apps/frontend/src/ui/pages/cluster/ClusterMods.tsx @@ -3,12 +3,13 @@ import UFuzzy from '@leeoniya/ufuzzy'; import { FilterFunnel01Icon, RefreshCw01Icon, SearchMdIcon, Trash03Icon } from '@untitled-theme/icons-solid'; import { bridge } from '~imports'; import Button from '~ui/components/base/Button'; +import Checkbox from '~ui/components/base/Checkbox'; import TextField from '~ui/components/base/TextField'; 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 from '~ui/hooks/useCommand'; +import useCommand, { tryResult } from '~ui/hooks/useCommand'; import useProcessor from '~ui/hooks/useProcessor'; import { type Accessor, createEffect, createSignal, For, Match, on, Show, Switch, untrack } from 'solid-js'; @@ -206,6 +207,25 @@ function ModEntry(props: ModEntryProps) { } } + async function togglePackage(checked: boolean) { + try { + const path = cluster()?.path; + if (path) { + // eslint-disable-next-line solid/reactivity -- bs lol + await tryResult(() => bridge.commands.setClusterPackageEnabled( + path, + props.pkg.file_name, + 'mod', + checked, + )); + props.refetch(); + } + } + catch (err) { + console.error(err); + } + } + return (
- {/* */} +