From 5f0ac537a442e4023a4f6d2a87c5804cee27b0fc Mon Sep 17 00:00:00 2001 From: Jai A Date: Thu, 18 May 2023 15:44:31 -0700 Subject: [PATCH 1/4] Finish profile mods page --- theseus_gui/src-tauri/src/api/profile.rs | 23 +++--- theseus_gui/src/components/ui/Instance.vue | 24 +++--- theseus_gui/src/pages/Browse.vue | 34 ++++---- theseus_gui/src/pages/Settings.vue | 21 ++--- theseus_gui/src/pages/instance/Index.vue | 1 + theseus_gui/src/pages/instance/Mods.vue | 93 ++++++++++++++++++---- 6 files changed, 131 insertions(+), 65 deletions(-) diff --git a/theseus_gui/src-tauri/src/api/profile.rs b/theseus_gui/src-tauri/src/api/profile.rs index 351c31476..e86589671 100644 --- a/theseus_gui/src-tauri/src/api/profile.rs +++ b/theseus_gui/src-tauri/src/api/profile.rs @@ -1,6 +1,7 @@ use crate::api::Result; use daedalus::modded::LoaderVersion; use serde::{Deserialize, Serialize}; +use std::collections::HashMap; use std::path::{Path, PathBuf}; use theseus::prelude::*; use uuid::Uuid; @@ -29,7 +30,7 @@ pub async fn profile_get( #[tauri::command] pub async fn profile_list( clear_projects: Option, -) -> Result> { +) -> Result> { let res = profile::list(clear_projects).await?; Ok(res) } @@ -65,9 +66,10 @@ pub async fn profile_install(path: &Path) -> Result<()> { /// Updates all of the profile's projects /// invoke('profile_update_all') #[tauri::command] -pub async fn profile_update_all(path: &Path) -> Result<()> { - profile::update_all(path).await?; - Ok(()) +pub async fn profile_update_all( + path: &Path, +) -> Result> { + Ok(profile::update_all(path).await?) } /// Updates a specified project @@ -76,9 +78,8 @@ pub async fn profile_update_all(path: &Path) -> Result<()> { pub async fn profile_update_project( path: &Path, project_path: &Path, -) -> Result<()> { - profile::update_project(path, project_path).await?; - Ok(()) +) -> Result { + Ok(profile::update_project(path, project_path).await?) } // Adds a project to a profile from a version ID @@ -88,8 +89,7 @@ pub async fn profile_add_project_from_version( path: &Path, version_id: String, ) -> Result { - let res = profile::add_project_from_version(path, version_id).await?; - Ok(res) + Ok(profile::add_project_from_version(path, version_id).await?) } // Adds a project to a profile from a path @@ -111,9 +111,8 @@ pub async fn profile_add_project_from_path( pub async fn profile_toggle_disable_project( path: &Path, project_path: &Path, -) -> Result<()> { - profile::toggle_disable_project(path, project_path).await?; - Ok(()) +) -> Result { + Ok(profile::toggle_disable_project(path, project_path).await?) } // Removes a project from a profile diff --git a/theseus_gui/src/components/ui/Instance.vue b/theseus_gui/src/components/ui/Instance.vue index 44dfd1bfc..d33fd1a47 100644 --- a/theseus_gui/src/components/ui/Instance.vue +++ b/theseus_gui/src/components/ui/Instance.vue @@ -193,7 +193,7 @@ onUnmounted(() => unlisten())
- +
unlisten()) + + + + + From ef9411ce0d2cb753216e9490afd2308883127963 Mon Sep 17 00:00:00 2001 From: Jai A Date: Thu, 18 May 2023 15:44:56 -0700 Subject: [PATCH 2/4] commit missing --- theseus/src/api/profile.rs | 100 +++++++++++++++--------- theseus/src/state/profiles.rs | 28 +++++-- theseus/src/state/projects.rs | 30 ++++--- theseus_gui/src/pages/instance/Mods.vue | 13 ++- 4 files changed, 107 insertions(+), 64 deletions(-) diff --git a/theseus/src/api/profile.rs b/theseus/src/api/profile.rs index c1417ed8f..0092d7275 100644 --- a/theseus/src/api/profile.rs +++ b/theseus/src/api/profile.rs @@ -123,45 +123,69 @@ pub async fn install(path: &Path) -> crate::Result<()> { Ok(()) } -pub async fn update_all(profile_path: &Path) -> crate::Result<()> { - Box::pin(async move { - if let Some(profile) = get(profile_path, None).await? { - let loading_bar = init_loading( - LoadingBarType::ProfileUpdate { - profile_path: profile.path.clone(), - profile_name: profile.metadata.name.clone(), - }, - 100.0, - "Updating profile", - ) - .await?; +pub async fn update_all( + profile_path: &Path, +) -> crate::Result> { + if let Some(profile) = get(profile_path, None).await? { + let loading_bar = init_loading( + LoadingBarType::ProfileUpdate { + profile_path: profile.path.clone(), + profile_name: profile.metadata.name.clone(), + }, + 100.0, + "Updating profile", + ) + .await?; - use futures::StreamExt; - loading_try_for_each_concurrent( - futures::stream::iter(profile.projects.keys()) - .map(Ok::<&PathBuf, crate::Error>), - None, - Some(&loading_bar), - 100.0, - profile.projects.keys().len(), - None, - |project| async move { - let _ = update_project(profile_path, project).await?; + let keys = profile + .projects + .into_iter() + .filter(|(_, project)| { + matches!( + &project.metadata, + ProjectMetadata::Modrinth { + update_version: Some(_), + .. + } + ) + }) + .map(|x| x.0) + .collect::>(); + let len = keys.len(); + + let map = Arc::new(RwLock::new(HashMap::new())); + + use futures::StreamExt; + loading_try_for_each_concurrent( + futures::stream::iter(keys).map(Ok::), + None, + Some(&loading_bar), + 100.0, + len, + None, + |project| async { + let map = map.clone(); + + async move { + let new_path = + update_project(profile_path, &project).await?; + + map.write().await.insert(project, new_path); Ok(()) - }, - ) - .await?; + } + .await + }, + ) + .await?; - Ok(()) - } else { - Err(crate::ErrorKind::UnmanagedProfileError( - profile_path.display().to_string(), - ) - .as_error()) - } - }) - .await + Ok(Arc::try_unwrap(map).unwrap().into_inner()) + } else { + Err(crate::ErrorKind::UnmanagedProfileError( + profile_path.display().to_string(), + ) + .as_error()) + } } pub async fn update_project( @@ -270,11 +294,9 @@ pub async fn add_project_from_path( pub async fn toggle_disable_project( profile: &Path, project: &Path, -) -> crate::Result<()> { +) -> crate::Result { if let Some(profile) = get(profile, None).await? { - profile.toggle_disable_project(project).await?; - - Ok(()) + Ok(profile.toggle_disable_project(project).await?) } else { Err(crate::ErrorKind::UnmanagedProfileError( profile.display().to_string(), diff --git a/theseus/src/state/profiles.rs b/theseus/src/state/profiles.rs index 0e463377d..2ba746747 100644 --- a/theseus/src/state/profiles.rs +++ b/theseus/src/state/profiles.rs @@ -193,7 +193,7 @@ impl Profile { let paths = profile.get_profile_project_paths()?; let projects = crate::state::infer_data_from_files( - profile, + profile.clone(), paths, state.directories.caches_dir(), &state.io_semaphore, @@ -205,6 +205,14 @@ impl Profile { if let Some(profile) = new_profiles.0.get_mut(&path) { profile.projects = projects; } + + emit_profile( + profile.uuid, + profile.path, + &profile.metadata.name, + ProfilePayloadType::Synced, + ) + .await?; } else { tracing::warn!( "Unable to fetch single profile projects: path {path:?} invalid", @@ -401,7 +409,7 @@ impl Profile { pub async fn toggle_disable_project( &self, path: &Path, - ) -> crate::Result<()> { + ) -> crate::Result { let state = State::get().await?; if let Some(mut project) = { let mut profiles = state.profiles.write().await; @@ -417,6 +425,12 @@ impl Profile { if path.extension().map_or(false, |ext| ext == "disabled") { project.disabled = false; + new_path.set_file_name( + path.file_name() + .unwrap_or_default() + .to_string_lossy() + .replace(".disabled", ""), + ); } else { new_path.set_file_name(format!( "{}.disabled", @@ -429,17 +443,17 @@ impl Profile { let mut profiles = state.profiles.write().await; if let Some(profile) = profiles.0.get_mut(&self.path) { - profile.projects.insert(new_path, project); + profile.projects.insert(new_path.clone(), project); } + + Ok(new_path) } else { - return Err(crate::ErrorKind::InputError(format!( + Err(crate::ErrorKind::InputError(format!( "Project path does not exist: {:?}", path )) - .into()); + .into()) } - - Ok(()) } pub async fn remove_project( diff --git a/theseus/src/state/projects.rs b/theseus/src/state/projects.rs index ea8fbb977..aba4f548c 100644 --- a/theseus/src/state/projects.rs +++ b/theseus/src/state/projects.rs @@ -351,7 +351,7 @@ pub async fn infer_data_from_files( return_projects.insert( path, Project { - disabled: false, + disabled: file_name.ends_with(".disabled"), metadata: ProjectMetadata::Modrinth { project: Box::new(project.clone()), version: Box::new(version.clone()), @@ -360,9 +360,17 @@ pub async fn infer_data_from_files( .filter(|x| x.team_id == project.team) .cloned() .collect::>(), - update_version: update_versions - .get(&hash) - .map(|val| Box::new(val.clone())), + update_version: if let Some(value) = + update_versions.get(&hash) + { + if value.id != version.id { + Some(Box::new(value.clone())) + } else { + None + } + } else { + None + }, incompatible: !version.loaders.contains( &profile .metadata @@ -400,7 +408,7 @@ pub async fn infer_data_from_files( path.clone(), Project { sha512: hash, - disabled: path.ends_with(".disabled"), + disabled: file_name.ends_with(".disabled"), metadata: ProjectMetadata::Unknown, file_name, }, @@ -454,7 +462,7 @@ pub async fn infer_data_from_files( path.clone(), Project { sha512: hash, - disabled: path.ends_with(".disabled"), + disabled: file_name.ends_with(".disabled"), file_name, metadata: ProjectMetadata::Inferred { title: Some( @@ -520,7 +528,7 @@ pub async fn infer_data_from_files( path.clone(), Project { sha512: hash, - disabled: path.ends_with(".disabled"), + disabled: file_name.ends_with(".disabled"), file_name, metadata: ProjectMetadata::Inferred { title: Some(if pack.name.is_empty() { @@ -585,7 +593,7 @@ pub async fn infer_data_from_files( path.clone(), Project { sha512: hash, - disabled: path.ends_with(".disabled"), + disabled: file_name.ends_with(".disabled"), file_name, metadata: ProjectMetadata::Inferred { title: Some(pack.name.unwrap_or(pack.id)), @@ -650,7 +658,7 @@ pub async fn infer_data_from_files( path.clone(), Project { sha512: hash, - disabled: path.ends_with(".disabled"), + disabled: file_name.ends_with(".disabled"), file_name, metadata: ProjectMetadata::Inferred { title: Some( @@ -715,7 +723,7 @@ pub async fn infer_data_from_files( path.clone(), Project { sha512: hash, - disabled: path.ends_with(".disabled"), + disabled: file_name.ends_with(".disabled"), file_name, metadata: ProjectMetadata::Inferred { title: None, @@ -735,7 +743,7 @@ pub async fn infer_data_from_files( path.clone(), Project { sha512: hash, - disabled: path.ends_with(".disabled"), + disabled: file_name.ends_with(".disabled"), file_name, metadata: ProjectMetadata::Unknown, }, diff --git a/theseus_gui/src/pages/instance/Mods.vue b/theseus_gui/src/pages/instance/Mods.vue index 612a79b59..68d126741 100644 --- a/theseus_gui/src/pages/instance/Mods.vue +++ b/theseus_gui/src/pages/instance/Mods.vue @@ -81,17 +81,17 @@ import { SearchIcon, UpdatedIcon, DropdownSelect, - AnimatedLogo + AnimatedLogo, } from 'omorphia' -import {computed, ref} from 'vue' +import { computed, ref } from 'vue' import { convertFileSrc } from '@tauri-apps/api/tauri' import { useRouter } from 'vue-router' import { remove_project, toggle_disable_project, update_all, - update_project -} from "@/helpers/profile.js"; + update_project, +} from '@/helpers/profile.js' const router = useRouter() @@ -118,7 +118,7 @@ for (const [path, project] of Object.entries(props.instance.projects)) { icon: project.metadata.project.icon_url, disabled: project.disabled, updateVersion: project.metadata.update_version, - outdated: !!project.metadata.update_version + outdated: !!project.metadata.update_version, }) } else if (project.metadata.type === 'inferred') { projects.value.push({ @@ -204,7 +204,7 @@ async function updateAll() { console.log(paths) for (const [oldVal, newVal] of Object.entries(paths)) { - const index = projects.value.findIndex((x) => x.path = oldVal) + const index = projects.value.findIndex((x) => (x.path = oldVal)) projects.value[index].path = newVal projects.value[index].outdated = false @@ -293,7 +293,6 @@ async function removeMod(mod) { padding-left: 0.5rem; } } -