From 4c04c07c618150364e8df2f8d95f78486c7f2c07 Mon Sep 17 00:00:00 2001 From: Pauline Date: Tue, 18 Jun 2024 00:18:19 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(linting):=20more=20fotmattin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/api/cluster/mod.rs | 2 +- core/src/api/java.rs | 8 +- core/src/api/logger.rs | 4 +- core/src/api/package/import/mod.rs | 14 +- core/src/store/credentials.rs | 3 +- core/src/store/minecraft.rs | 5 +- core/src/store/package.rs | 1 - core/src/store/processor.rs | 6 +- core/src/utils/io.rs | 4 +- desktop/src-tauri/src/api/commands.rs | 148 +++++++++--------- desktop/src-tauri/src/api/mod.rs | 16 +- desktop/src-tauri/src/ext/updater.rs | 15 +- desktop/src-tauri/src/lib.rs | 20 +-- desktop/src/ui/App.tsx | 3 +- desktop/src/ui/components/base/Dropdown.tsx | 2 +- desktop/src/ui/components/overlay/Popup.tsx | 2 +- desktop/src/ui/hooks/useCluster.tsx | 2 +- .../pages/settings/game/SettingsAccounts.tsx | 1 - 18 files changed, 123 insertions(+), 133 deletions(-) diff --git a/core/src/api/cluster/mod.rs b/core/src/api/cluster/mod.rs index b9a50054..6d9e660a 100644 --- a/core/src/api/cluster/mod.rs +++ b/core/src/api/cluster/mod.rs @@ -8,8 +8,8 @@ use crate::proxy::ClusterPayloadType; use crate::store::ProcessorChild; // use crate::package::from::{EnvType, PackDependency, PackFile, PackFileHash, PackFormat}; use crate::prelude::{ClusterPath, JavaVersion, PackagePath}; -pub use crate::store::{Cluster, JavaOptions, State}; use crate::store::MinecraftCredentials; +pub use crate::store::{Cluster, JavaOptions, State}; use crate::utils::io::{self, IOError}; diff --git a/core/src/api/java.rs b/core/src/api/java.rs index b6b03e21..6b0cf46a 100644 --- a/core/src/api/java.rs +++ b/core/src/api/java.rs @@ -66,8 +66,8 @@ pub async fn install_java(java_version: u32) -> crate::Result { .await?; let path = state.directories.java_dir().await; - let mut archive = zip::ZipArchive::new(std::io::Cursor::new(file)) - .map_err(IOError::from_zip)?; + let mut archive = + zip::ZipArchive::new(std::io::Cursor::new(file)).map_err(IOError::from_zip)?; if let Some(file) = archive.file_names().next() { if let Some(dir) = file.split('/').next() { @@ -79,9 +79,7 @@ pub async fn install_java(java_version: u32) -> crate::Result { } send_ingress(&ingress, 0.0, Some("extracing java binary")).await?; - archive - .extract(&path) - .map_err(IOError::from_zip)?; + archive.extract(&path).map_err(IOError::from_zip)?; send_ingress(&ingress, 10.0, Some("extracted java binary")).await?; let mut base_path = path.join( download diff --git a/core/src/api/logger.rs b/core/src/api/logger.rs index 1b4ee4da..a7cc8bd7 100644 --- a/core/src/api/logger.rs +++ b/core/src/api/logger.rs @@ -142,9 +142,7 @@ pub async fn get_logs_by_file( .join(&log_file); let metadata = std::fs::metadata(&path)?; - let age = metadata - .created() - .unwrap_or(SystemTime::UNIX_EPOCH); + let age = metadata.created().unwrap_or(SystemTime::UNIX_EPOCH); LogManager::initialize(log_type, age, &cluster_path, log_file, Some(true)).await } diff --git a/core/src/api/package/import/mod.rs b/core/src/api/package/import/mod.rs index ba1e07ce..c0342ae4 100644 --- a/core/src/api/package/import/mod.rs +++ b/core/src/api/package/import/mod.rs @@ -79,9 +79,7 @@ pub async fn import_instances(import: ImportType, path: PathBuf) -> crate::Resul ImportType::TLauncher => "instances".to_string(), ImportType::Technic => "instances".to_string(), ImportType::FTBLauncher => "instances".to_string(), - _ => { - return Err(anyhow::anyhow!("launcher type unknown, cant import").into()) - } + _ => return Err(anyhow::anyhow!("launcher type unknown, cant import").into()), }; let instances_dir = path.join(&instances_path); @@ -97,11 +95,11 @@ pub async fn import_instances(import: ImportType, path: PathBuf) -> crate::Resul { let path = e.path(); if path.is_dir() && is_valid_instance(path.clone(), import).await { - let name = path.file_name(); - if let Some(name) = name { - instances.push(name.to_string_lossy().to_string()); - } - } + let name = path.file_name(); + if let Some(name) = name { + instances.push(name.to_string_lossy().to_string()); + } + } } Ok(instances) diff --git a/core/src/store/credentials.rs b/core/src/store/credentials.rs index abb453a5..52ecfa50 100644 --- a/core/src/store/credentials.rs +++ b/core/src/store/credentials.rs @@ -26,8 +26,7 @@ impl Credentials { ) -> crate::Result { let path = SnapshotPath::from_path(path); let stronghold = iota_stronghold::Stronghold::default(); - let keyprovider = - KeyProvider::try_from(password).map_err(StrongholdError::MemoryError)?; + let keyprovider = KeyProvider::try_from(password).map_err(StrongholdError::MemoryError)?; if path.exists() { stronghold .load_snapshot(&keyprovider, &path) diff --git a/core/src/store/minecraft.rs b/core/src/store/minecraft.rs index dff16dda..161a47ab 100644 --- a/core/src/store/minecraft.rs +++ b/core/src/store/minecraft.rs @@ -1,6 +1,5 @@ //! Handles MSA Authentication flow. -use std::fmt::Write; use base64::Engine; use chrono::{DateTime, Utc}; use p256::ecdsa::signature::Signer; @@ -11,6 +10,7 @@ use serde::{Deserialize, Serialize}; use serde_json::json; use sha2::Digest; use std::collections::HashMap; +use std::fmt::Write; use uuid::Uuid; const AUTH_STORE: &str = "authentication.json"; @@ -878,8 +878,7 @@ async fn send_signed_request( step: MinecraftAuthStep, current_date: DateTime, ) -> Result, MinecraftAuthError> { - let auth = authorization - .map_or(Vec::new(), |v| v.as_bytes().to_vec()); + let auth = authorization.map_or(Vec::new(), |v| v.as_bytes().to_vec()); let body = serde_json::to_vec(&raw_body) .map_err(|source| MinecraftAuthError::SerializeError { step, source })?; let time: u128 = { ((current_date.timestamp() as u128) + 11644473600) * 10000000 }; diff --git a/core/src/store/package.rs b/core/src/store/package.rs index 0594e6a1..26002a45 100644 --- a/core/src/store/package.rs +++ b/core/src/store/package.rs @@ -1,7 +1,6 @@ //! Handlers for Mod metadata that can be displayed in a GUI mod list or exported as a mod pack #[allow(clippy::all)] - use async_zip::tokio::read::fs::ZipFileReader; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; diff --git a/core/src/store/processor.rs b/core/src/store/processor.rs index 6ac4243b..05a11342 100644 --- a/core/src/store/processor.rs +++ b/core/src/store/processor.rs @@ -41,9 +41,9 @@ pub enum IngressProcessType { } impl Default for IngressProcessor { - fn default() -> Self { - Self::new() - } + fn default() -> Self { + Self::new() + } } impl IngressProcessor { diff --git a/core/src/utils/io.rs b/core/src/utils/io.rs index bc3914af..8e8515e3 100644 --- a/core/src/utils/io.rs +++ b/core/src/utils/io.rs @@ -202,9 +202,7 @@ pub fn extract_archive(archive: &PathBuf, dest: &PathBuf) -> crate::Result<()> { pub fn extract_zip(archive: &PathBuf, dest: &PathBuf) -> Result<(), IOError> { let file = File::open(archive).map_err(|err| IOError::with_path(err, archive.as_path()))?; let archive = zip::ZipArchive::new(file).map_err(IOError::from_zip); - archive? - .extract(dest) - .map_err(IOError::from_zip)?; + archive?.extract(dest).map_err(IOError::from_zip)?; Ok(()) } diff --git a/desktop/src-tauri/src/api/commands.rs b/desktop/src-tauri/src/api/commands.rs index 1ad7b513..f834e41e 100644 --- a/desktop/src-tauri/src/api/commands.rs +++ b/desktop/src-tauri/src/api/commands.rs @@ -1,26 +1,31 @@ -use std::{collections::HashMap, path::PathBuf, str::FromStr}; +use std::collections::HashMap; +use std::path::PathBuf; +use std::str::FromStr; use chrono::DateTime; -use onelauncher::{cluster, data::{ClusterMeta, Loader, PackageData}, store::{Cluster, ClusterPath}, State}; +use onelauncher::data::{ClusterMeta, Loader, PackageData}; +use onelauncher::store::{Cluster, ClusterPath}; +use onelauncher::{cluster, State}; use serde::{Deserialize, Serialize}; use specta::Type; use uuid::Uuid; #[macro_export] macro_rules! collect_commands { - () => { - { - use $crate::api::commands::*; - tauri_specta::ts::builder() - .config(specta::ts::ExportConfig::default().bigint(specta::ts::BigIntExportBehavior::BigInt)) - .commands(tauri_specta::collect_commands![ - is_dev, - create_cluster, - get_cluster, - get_clusters - ]) - } - }; + () => {{ + use $crate::api::commands::*; + tauri_specta::ts::builder() + .config( + specta::ts::ExportConfig::default() + .bigint(specta::ts::BigIntExportBehavior::BigInt), + ) + .commands(tauri_specta::collect_commands![ + is_dev, + create_cluster, + get_cluster, + get_clusters + ]) + }}; } #[specta::specta] @@ -31,7 +36,7 @@ pub fn is_dev() -> bool { #[derive(Serialize, Deserialize, Type)] pub struct CreateCluster { - name: String, + name: String, mc_version: String, mod_loader: Loader, loader_version: Option, @@ -45,75 +50,76 @@ pub struct CreateCluster { #[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?; + 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()) - } + if let Some(cluster) = cluster::get(&path, None).await? { + Ok(cluster.uuid) + } else { + Err("Cluster does not exist".to_string()) + } } fn placeholder_cluster() -> Cluster { - let path = ClusterPath("test".into()); - Cluster { - uuid: Uuid::from_str("56d1cbcf-1961-4477-b263-80e3b1c7a9d1").unwrap(), - stage: onelauncher::store::ClusterStage::Installed, - path: path.0, - meta: ClusterMeta { - created_at: DateTime::from_timestamp_millis(1718297861712).unwrap(), - modified_at: DateTime::from_timestamp_millis(1718297861712).unwrap(), - group: vec![], - icon: None, - icon_url: None, - loader: Loader::Vanilla, - loader_version: None, - mc_version: "1.8.9".into(), - name: "Test Cluster".into(), - overall_played: 58195, - recently_played: 0, - package_data: None, - played_at: None - }, - memory: None, - java: None, - resolution: None, - force_fullscreen: None, - init_hooks: None, - packages: HashMap::new(), - update: None - } + let path = ClusterPath("test".into()); + Cluster { + uuid: Uuid::from_str("56d1cbcf-1961-4477-b263-80e3b1c7a9d1").unwrap(), + stage: onelauncher::store::ClusterStage::Installed, + path: path.0, + meta: ClusterMeta { + created_at: DateTime::from_timestamp_millis(1718297861712).unwrap(), + modified_at: DateTime::from_timestamp_millis(1718297861712).unwrap(), + group: vec![], + icon: None, + icon_url: None, + loader: Loader::Vanilla, + loader_version: None, + mc_version: "1.8.9".into(), + name: "Test Cluster".into(), + overall_played: 58195, + recently_played: 0, + package_data: None, + played_at: None, + }, + memory: None, + java: None, + resolution: None, + force_fullscreen: None, + init_hooks: None, + packages: HashMap::new(), + update: None, + } } #[specta::specta] #[tauri::command] pub async fn get_cluster(uuid: Uuid) -> Result { - Ok(placeholder_cluster()) + Ok(placeholder_cluster()) - // match cluster::get_by_uuid(uuid, None).await? { - // Some(cluster) => Ok(cluster), - // None => Err("Cluster does not exist".into()) - // } + // match cluster::get_by_uuid(uuid, None).await? { + // Some(cluster) => Ok(cluster), + // None => Err("Cluster does not exist".into()) + // } } #[specta::specta] #[tauri::command] pub async fn get_clusters() -> Result, String> { - let mut map = HashMap::::new(); - let cluster = placeholder_cluster(); - map.insert(cluster.cluster_path(), cluster); + let mut map = HashMap::::new(); + let cluster = placeholder_cluster(); + map.insert(cluster.cluster_path(), cluster); - Ok(map) - - // cluster::list(None).await.map_err(|op| op.into()) + Ok(map) + + // cluster::list(None).await.map_err(|op| op.into()) } diff --git a/desktop/src-tauri/src/api/mod.rs b/desktop/src-tauri/src/api/mod.rs index d67bc477..878322b6 100644 --- a/desktop/src-tauri/src/api/mod.rs +++ b/desktop/src-tauri/src/api/mod.rs @@ -20,20 +20,20 @@ pub type Result = std::result::Result; #[derive(thiserror::Error, Debug, Serialize, specta::Type)] pub enum OneLauncherSerializableError { - #[error("{0}")] - CommonError(String), + #[error("{0}")] + CommonError(String), } impl From for OneLauncherSerializableError { - fn from(value: OneLauncherError) -> Self { - Self::CommonError(value.to_string()) - } + fn from(value: OneLauncherError) -> Self { + Self::CommonError(value.to_string()) + } } impl From for OneLauncherSerializableError { - fn from(value: onelauncher::Error) -> Self { - Self::CommonError(value.to_string()) - } + fn from(value: onelauncher::Error) -> Self { + Self::CommonError(value.to_string()) + } } #[derive(thiserror::Error, Debug)] diff --git a/desktop/src-tauri/src/ext/updater.rs b/desktop/src-tauri/src/ext/updater.rs index 54d19862..29e7f37b 100644 --- a/desktop/src-tauri/src/ext/updater.rs +++ b/desktop/src-tauri/src/ext/updater.rs @@ -1,18 +1,19 @@ -use tauri::{plugin::TauriPlugin, Manager, Runtime}; +use tauri::plugin::TauriPlugin; +use tauri::{Manager, Runtime}; use tauri_plugin_updater::{Update as TauriPluginUpdate, UpdaterExt}; use tokio::sync::Mutex; #[derive(Debug, Clone, serde::Serialize)] pub struct Update { - pub version: String, + pub version: String, } impl Update { - fn new(update: &TauriPluginUpdate) -> Self { - Self { - version: update.version.clone(), - } - } + fn new(update: &TauriPluginUpdate) -> Self { + Self { + version: update.version.clone(), + } + } } #[derive(Default)] diff --git a/desktop/src-tauri/src/lib.rs b/desktop/src-tauri/src/lib.rs index d344c28f..da3274f8 100644 --- a/desktop/src-tauri/src/lib.rs +++ b/desktop/src-tauri/src/lib.rs @@ -35,9 +35,7 @@ pub async fn run() { .await; } -pub async fn run_app( - setup: F, -) { +pub async fn run_app(setup: F) { let builder = tauri::Builder::default() .plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_single_instance::init(|app, argv, cwd| { @@ -55,22 +53,20 @@ pub async fn run_app( Ok(()) }); - let builder = builder - .plugin(api::init()) - .invoke_handler({ - let builder = collect_commands!(); + let builder = builder.plugin(api::init()).invoke_handler({ + let builder = collect_commands!(); - #[cfg(debug_assertions)] - let builder = builder.path("../src/bindings.ts"); + #[cfg(debug_assertions)] + let builder = builder.path("../src/bindings.ts"); - builder.build().unwrap() - }); + builder.build().unwrap() + }); let app = builder .build(tauri::tauri_build_context!()) .expect("failed to build tauri application"); - initialize_state(app.app_handle().clone()).await; + initialize_state(app.app_handle().clone()).await; app.run(|_app_handle, _event| {}) } diff --git a/desktop/src/ui/App.tsx b/desktop/src/ui/App.tsx index cbf0b623..17e03bbf 100644 --- a/desktop/src/ui/App.tsx +++ b/desktop/src/ui/App.tsx @@ -8,11 +8,10 @@ import NotificationOverlay from './components/overlay/notifications/Notification import { bridge } from '~index'; function App(props: ParentProps) { - if (!bridge.commands.isDev()) { + if (!bridge.commands.isDev()) document.addEventListener('contextmenu', (event) => { event.preventDefault(); }); - } return (
diff --git a/desktop/src/ui/components/base/Dropdown.tsx b/desktop/src/ui/components/base/Dropdown.tsx index 95502f77..c7626071 100644 --- a/desktop/src/ui/components/base/Dropdown.tsx +++ b/desktop/src/ui/components/base/Dropdown.tsx @@ -14,7 +14,7 @@ function Dropdown(props: DropdownProps) { const [split, rest] = splitProps(props, ['children', 'class', 'text', 'onChange', 'selected']); const [visible, setVisible] = createSignal(false); - // eslint-disable-next-line solid/reactivity + // eslint-disable-next-line solid/reactivity -- todo const [selected, setSelected] = createSignal(split.selected || 0); let ref!: HTMLDivElement; diff --git a/desktop/src/ui/components/overlay/Popup.tsx b/desktop/src/ui/components/overlay/Popup.tsx index 5c73302d..1be96176 100644 --- a/desktop/src/ui/components/overlay/Popup.tsx +++ b/desktop/src/ui/components/overlay/Popup.tsx @@ -7,7 +7,7 @@ import type { Setter } from 'solid-js'; import { Portal } from 'solid-js/web'; -// eslint-disable-next-line ts/no-namespace +// eslint-disable-next-line ts/no-namespace -- todo declare namespace Popup { type PopupProps = Omit[0], 'children'> & ParentProps & { visible: Accessor; diff --git a/desktop/src/ui/hooks/useCluster.tsx b/desktop/src/ui/hooks/useCluster.tsx index 1a54bced..2b85cd26 100644 --- a/desktop/src/ui/hooks/useCluster.tsx +++ b/desktop/src/ui/hooks/useCluster.tsx @@ -14,7 +14,7 @@ export function getCluster(uuid: string | undefined | null): Resource | } export function ClusterProvider(props: ParentProps & { uuid: string | undefined }) { - // eslint-disable-next-line solid/reactivity + // eslint-disable-next-line solid/reactivity -- todo const cluster = getCluster(props.uuid); return ( diff --git a/desktop/src/ui/pages/settings/game/SettingsAccounts.tsx b/desktop/src/ui/pages/settings/game/SettingsAccounts.tsx index c8082a2d..cb3429f4 100644 --- a/desktop/src/ui/pages/settings/game/SettingsAccounts.tsx +++ b/desktop/src/ui/pages/settings/game/SettingsAccounts.tsx @@ -4,7 +4,6 @@ import Button from '~ui/components/base/Button'; import Tooltip from '~ui/components/base/Tooltip'; import PlayerHead from '~ui/components/game/PlayerHead'; import ScrollableContainer from '~ui/components/ScrollableContainer'; -import SettingsRow from '~ui/components/SettingsRow'; import Sidebar from '~ui/components/Sidebar'; const Accounts: {