You've already forked AstralRinth
forked from didirus/AstralRinth
Profile mods page (#119)
* Finish profile mods page * commit missing * finish pr * Run lint
This commit is contained in:
@@ -125,7 +125,9 @@ pub async fn install(path: &Path) -> crate::Result<()> {
|
|||||||
|
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
#[theseus_macros::debug_pin]
|
#[theseus_macros::debug_pin]
|
||||||
pub async fn update_all(profile_path: &Path) -> crate::Result<()> {
|
pub async fn update_all(
|
||||||
|
profile_path: &Path,
|
||||||
|
) -> crate::Result<HashMap<PathBuf, PathBuf>> {
|
||||||
if let Some(profile) = get(profile_path, None).await? {
|
if let Some(profile) = get(profile_path, None).await? {
|
||||||
let loading_bar = init_loading(
|
let loading_bar = init_loading(
|
||||||
LoadingBarType::ProfileUpdate {
|
LoadingBarType::ProfileUpdate {
|
||||||
@@ -137,24 +139,49 @@ pub async fn update_all(profile_path: &Path) -> crate::Result<()> {
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
let keys = profile
|
||||||
|
.projects
|
||||||
|
.into_iter()
|
||||||
|
.filter(|(_, project)| {
|
||||||
|
matches!(
|
||||||
|
&project.metadata,
|
||||||
|
ProjectMetadata::Modrinth {
|
||||||
|
update_version: Some(_),
|
||||||
|
..
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.map(|x| x.0)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let len = keys.len();
|
||||||
|
|
||||||
|
let map = Arc::new(RwLock::new(HashMap::new()));
|
||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
loading_try_for_each_concurrent(
|
loading_try_for_each_concurrent(
|
||||||
futures::stream::iter(profile.projects.keys())
|
futures::stream::iter(keys).map(Ok::<PathBuf, crate::Error>),
|
||||||
.map(Ok::<&PathBuf, crate::Error>),
|
|
||||||
None,
|
None,
|
||||||
Some(&loading_bar),
|
Some(&loading_bar),
|
||||||
100.0,
|
100.0,
|
||||||
profile.projects.keys().len(),
|
len,
|
||||||
None,
|
None,
|
||||||
|project| async move {
|
|project| async {
|
||||||
let _ = update_project(profile_path, project).await?;
|
let map = map.clone();
|
||||||
|
|
||||||
Ok(())
|
async move {
|
||||||
|
let new_path =
|
||||||
|
update_project(profile_path, &project).await?;
|
||||||
|
|
||||||
|
map.write().await.insert(project, new_path);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
.await
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(Arc::try_unwrap(map).unwrap().into_inner())
|
||||||
} else {
|
} else {
|
||||||
Err(crate::ErrorKind::UnmanagedProfileError(
|
Err(crate::ErrorKind::UnmanagedProfileError(
|
||||||
profile_path.display().to_string(),
|
profile_path.display().to_string(),
|
||||||
@@ -271,11 +298,9 @@ pub async fn add_project_from_path(
|
|||||||
pub async fn toggle_disable_project(
|
pub async fn toggle_disable_project(
|
||||||
profile: &Path,
|
profile: &Path,
|
||||||
project: &Path,
|
project: &Path,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<PathBuf> {
|
||||||
if let Some(profile) = get(profile, None).await? {
|
if let Some(profile) = get(profile, None).await? {
|
||||||
profile.toggle_disable_project(project).await?;
|
Ok(profile.toggle_disable_project(project).await?)
|
||||||
|
|
||||||
Ok(())
|
|
||||||
} else {
|
} else {
|
||||||
Err(crate::ErrorKind::UnmanagedProfileError(
|
Err(crate::ErrorKind::UnmanagedProfileError(
|
||||||
profile.display().to_string(),
|
profile.display().to_string(),
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ impl Profile {
|
|||||||
let paths = profile.get_profile_project_paths()?;
|
let paths = profile.get_profile_project_paths()?;
|
||||||
|
|
||||||
let projects = crate::state::infer_data_from_files(
|
let projects = crate::state::infer_data_from_files(
|
||||||
profile,
|
profile.clone(),
|
||||||
paths,
|
paths,
|
||||||
state.directories.caches_dir(),
|
state.directories.caches_dir(),
|
||||||
&state.io_semaphore,
|
&state.io_semaphore,
|
||||||
@@ -205,6 +205,14 @@ impl Profile {
|
|||||||
if let Some(profile) = new_profiles.0.get_mut(&path) {
|
if let Some(profile) = new_profiles.0.get_mut(&path) {
|
||||||
profile.projects = projects;
|
profile.projects = projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit_profile(
|
||||||
|
profile.uuid,
|
||||||
|
profile.path,
|
||||||
|
&profile.metadata.name,
|
||||||
|
ProfilePayloadType::Synced,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
} else {
|
} else {
|
||||||
tracing::warn!(
|
tracing::warn!(
|
||||||
"Unable to fetch single profile projects: path {path:?} invalid",
|
"Unable to fetch single profile projects: path {path:?} invalid",
|
||||||
@@ -409,7 +417,7 @@ impl Profile {
|
|||||||
pub async fn toggle_disable_project(
|
pub async fn toggle_disable_project(
|
||||||
&self,
|
&self,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<PathBuf> {
|
||||||
let state = State::get().await?;
|
let state = State::get().await?;
|
||||||
if let Some(mut project) = {
|
if let Some(mut project) = {
|
||||||
let mut profiles = state.profiles.write().await;
|
let mut profiles = state.profiles.write().await;
|
||||||
@@ -425,6 +433,12 @@ impl Profile {
|
|||||||
|
|
||||||
if path.extension().map_or(false, |ext| ext == "disabled") {
|
if path.extension().map_or(false, |ext| ext == "disabled") {
|
||||||
project.disabled = false;
|
project.disabled = false;
|
||||||
|
new_path.set_file_name(
|
||||||
|
path.file_name()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_string_lossy()
|
||||||
|
.replace(".disabled", ""),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
new_path.set_file_name(format!(
|
new_path.set_file_name(format!(
|
||||||
"{}.disabled",
|
"{}.disabled",
|
||||||
@@ -437,17 +451,17 @@ impl Profile {
|
|||||||
|
|
||||||
let mut profiles = state.profiles.write().await;
|
let mut profiles = state.profiles.write().await;
|
||||||
if let Some(profile) = profiles.0.get_mut(&self.path) {
|
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 {
|
} else {
|
||||||
return Err(crate::ErrorKind::InputError(format!(
|
Err(crate::ErrorKind::InputError(format!(
|
||||||
"Project path does not exist: {:?}",
|
"Project path does not exist: {:?}",
|
||||||
path
|
path
|
||||||
))
|
))
|
||||||
.into());
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn remove_project(
|
pub async fn remove_project(
|
||||||
|
|||||||
@@ -355,7 +355,7 @@ pub async fn infer_data_from_files(
|
|||||||
return_projects.insert(
|
return_projects.insert(
|
||||||
path,
|
path,
|
||||||
Project {
|
Project {
|
||||||
disabled: false,
|
disabled: file_name.ends_with(".disabled"),
|
||||||
metadata: ProjectMetadata::Modrinth {
|
metadata: ProjectMetadata::Modrinth {
|
||||||
project: Box::new(project.clone()),
|
project: Box::new(project.clone()),
|
||||||
version: Box::new(version.clone()),
|
version: Box::new(version.clone()),
|
||||||
@@ -364,9 +364,17 @@ pub async fn infer_data_from_files(
|
|||||||
.filter(|x| x.team_id == project.team)
|
.filter(|x| x.team_id == project.team)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
update_version: update_versions
|
update_version: if let Some(value) =
|
||||||
.get(&hash)
|
update_versions.get(&hash)
|
||||||
.map(|val| Box::new(val.clone())),
|
{
|
||||||
|
if value.id != version.id {
|
||||||
|
Some(Box::new(value.clone()))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
incompatible: !version.loaders.contains(
|
incompatible: !version.loaders.contains(
|
||||||
&profile
|
&profile
|
||||||
.metadata
|
.metadata
|
||||||
@@ -404,7 +412,7 @@ pub async fn infer_data_from_files(
|
|||||||
path.clone(),
|
path.clone(),
|
||||||
Project {
|
Project {
|
||||||
sha512: hash,
|
sha512: hash,
|
||||||
disabled: path.ends_with(".disabled"),
|
disabled: file_name.ends_with(".disabled"),
|
||||||
metadata: ProjectMetadata::Unknown,
|
metadata: ProjectMetadata::Unknown,
|
||||||
file_name,
|
file_name,
|
||||||
},
|
},
|
||||||
@@ -458,7 +466,7 @@ pub async fn infer_data_from_files(
|
|||||||
path.clone(),
|
path.clone(),
|
||||||
Project {
|
Project {
|
||||||
sha512: hash,
|
sha512: hash,
|
||||||
disabled: path.ends_with(".disabled"),
|
disabled: file_name.ends_with(".disabled"),
|
||||||
file_name,
|
file_name,
|
||||||
metadata: ProjectMetadata::Inferred {
|
metadata: ProjectMetadata::Inferred {
|
||||||
title: Some(
|
title: Some(
|
||||||
@@ -524,7 +532,7 @@ pub async fn infer_data_from_files(
|
|||||||
path.clone(),
|
path.clone(),
|
||||||
Project {
|
Project {
|
||||||
sha512: hash,
|
sha512: hash,
|
||||||
disabled: path.ends_with(".disabled"),
|
disabled: file_name.ends_with(".disabled"),
|
||||||
file_name,
|
file_name,
|
||||||
metadata: ProjectMetadata::Inferred {
|
metadata: ProjectMetadata::Inferred {
|
||||||
title: Some(if pack.name.is_empty() {
|
title: Some(if pack.name.is_empty() {
|
||||||
@@ -589,7 +597,7 @@ pub async fn infer_data_from_files(
|
|||||||
path.clone(),
|
path.clone(),
|
||||||
Project {
|
Project {
|
||||||
sha512: hash,
|
sha512: hash,
|
||||||
disabled: path.ends_with(".disabled"),
|
disabled: file_name.ends_with(".disabled"),
|
||||||
file_name,
|
file_name,
|
||||||
metadata: ProjectMetadata::Inferred {
|
metadata: ProjectMetadata::Inferred {
|
||||||
title: Some(pack.name.unwrap_or(pack.id)),
|
title: Some(pack.name.unwrap_or(pack.id)),
|
||||||
@@ -654,7 +662,7 @@ pub async fn infer_data_from_files(
|
|||||||
path.clone(),
|
path.clone(),
|
||||||
Project {
|
Project {
|
||||||
sha512: hash,
|
sha512: hash,
|
||||||
disabled: path.ends_with(".disabled"),
|
disabled: file_name.ends_with(".disabled"),
|
||||||
file_name,
|
file_name,
|
||||||
metadata: ProjectMetadata::Inferred {
|
metadata: ProjectMetadata::Inferred {
|
||||||
title: Some(
|
title: Some(
|
||||||
@@ -719,7 +727,7 @@ pub async fn infer_data_from_files(
|
|||||||
path.clone(),
|
path.clone(),
|
||||||
Project {
|
Project {
|
||||||
sha512: hash,
|
sha512: hash,
|
||||||
disabled: path.ends_with(".disabled"),
|
disabled: file_name.ends_with(".disabled"),
|
||||||
file_name,
|
file_name,
|
||||||
metadata: ProjectMetadata::Inferred {
|
metadata: ProjectMetadata::Inferred {
|
||||||
title: None,
|
title: None,
|
||||||
@@ -739,7 +747,7 @@ pub async fn infer_data_from_files(
|
|||||||
path.clone(),
|
path.clone(),
|
||||||
Project {
|
Project {
|
||||||
sha512: hash,
|
sha512: hash,
|
||||||
disabled: path.ends_with(".disabled"),
|
disabled: file_name.ends_with(".disabled"),
|
||||||
file_name,
|
file_name,
|
||||||
metadata: ProjectMetadata::Unknown,
|
metadata: ProjectMetadata::Unknown,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::api::Result;
|
use crate::api::Result;
|
||||||
use daedalus::modded::LoaderVersion;
|
use daedalus::modded::LoaderVersion;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use theseus::prelude::*;
|
use theseus::prelude::*;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
@@ -32,7 +33,7 @@ pub async fn profile_get(
|
|||||||
#[theseus_macros::debug_pin]
|
#[theseus_macros::debug_pin]
|
||||||
pub async fn profile_list(
|
pub async fn profile_list(
|
||||||
clear_projects: Option<bool>,
|
clear_projects: Option<bool>,
|
||||||
) -> Result<std::collections::HashMap<PathBuf, Profile>> {
|
) -> Result<HashMap<PathBuf, Profile>> {
|
||||||
let res = profile::list(clear_projects).await?;
|
let res = profile::list(clear_projects).await?;
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
@@ -71,9 +72,10 @@ pub async fn profile_install(path: &Path) -> Result<()> {
|
|||||||
/// invoke('profile_update_all')
|
/// invoke('profile_update_all')
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
#[theseus_macros::debug_pin]
|
#[theseus_macros::debug_pin]
|
||||||
pub async fn profile_update_all(path: &Path) -> Result<()> {
|
pub async fn profile_update_all(
|
||||||
profile::update_all(path).await?;
|
path: &Path,
|
||||||
Ok(())
|
) -> Result<HashMap<PathBuf, PathBuf>> {
|
||||||
|
Ok(profile::update_all(path).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates a specified project
|
/// Updates a specified project
|
||||||
@@ -83,9 +85,8 @@ pub async fn profile_update_all(path: &Path) -> Result<()> {
|
|||||||
pub async fn profile_update_project(
|
pub async fn profile_update_project(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
project_path: &Path,
|
project_path: &Path,
|
||||||
) -> Result<()> {
|
) -> Result<PathBuf> {
|
||||||
profile::update_project(path, project_path).await?;
|
Ok(profile::update_project(path, project_path).await?)
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds a project to a profile from a version ID
|
// Adds a project to a profile from a version ID
|
||||||
@@ -96,8 +97,7 @@ pub async fn profile_add_project_from_version(
|
|||||||
path: &Path,
|
path: &Path,
|
||||||
version_id: String,
|
version_id: String,
|
||||||
) -> Result<PathBuf> {
|
) -> Result<PathBuf> {
|
||||||
let res = profile::add_project_from_version(path, version_id).await?;
|
Ok(profile::add_project_from_version(path, version_id).await?)
|
||||||
Ok(res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds a project to a profile from a path
|
// Adds a project to a profile from a path
|
||||||
@@ -121,9 +121,8 @@ pub async fn profile_add_project_from_path(
|
|||||||
pub async fn profile_toggle_disable_project(
|
pub async fn profile_toggle_disable_project(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
project_path: &Path,
|
project_path: &Path,
|
||||||
) -> Result<()> {
|
) -> Result<PathBuf> {
|
||||||
profile::toggle_disable_project(path, project_path).await?;
|
Ok(profile::toggle_disable_project(path, project_path).await?)
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removes a project from a profile
|
// Removes a project from a profile
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ onUnmounted(() => unlisten())
|
|||||||
<PlayIcon />
|
<PlayIcon />
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="modLoading === true && playing === false" class="cta loading-cta">
|
<div v-else-if="modLoading === true && playing === false" class="cta loading-cta">
|
||||||
<AnimatedLogo class="loading" />
|
<AnimatedLogo class="loading-indicator" />
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-else-if="playing === true"
|
v-else-if="playing === true"
|
||||||
@@ -210,6 +210,18 @@ onUnmounted(() => unlisten())
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
.loading-indicator {
|
||||||
|
width: 2.5rem !important;
|
||||||
|
height: 2.5rem !important;
|
||||||
|
|
||||||
|
svg {
|
||||||
|
width: 2.5rem !important;
|
||||||
|
height: 2.5rem !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
.instance-small-card {
|
.instance-small-card {
|
||||||
background-color: var(--color-bg) !important;
|
background-color: var(--color-bg) !important;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -329,16 +341,6 @@ onUnmounted(() => unlisten())
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
.loading {
|
|
||||||
width: 2.5rem !important;
|
|
||||||
height: 2.5rem !important;
|
|
||||||
|
|
||||||
svg {
|
|
||||||
width: 2.5rem !important;
|
|
||||||
height: 2.5rem !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -373,6 +373,22 @@ const handleInstanceSwitch = async (value) => {
|
|||||||
|
|
||||||
<style src="vue-multiselect/dist/vue-multiselect.css"></style>
|
<style src="vue-multiselect/dist/vue-multiselect.css"></style>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
.filter-checkbox {
|
||||||
|
margin-bottom: 0.3rem;
|
||||||
|
font-size: 1rem;
|
||||||
|
|
||||||
|
svg {
|
||||||
|
display: flex;
|
||||||
|
align-self: center;
|
||||||
|
justify-self: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.checkbox {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<style lang="scss" scoped>
|
||||||
.project-type-dropdown {
|
.project-type-dropdown {
|
||||||
width: 100% !important;
|
width: 100% !important;
|
||||||
}
|
}
|
||||||
@@ -394,7 +410,8 @@ const handleInstanceSwitch = async (value) => {
|
|||||||
|
|
||||||
.iconified-input {
|
.iconified-input {
|
||||||
input {
|
input {
|
||||||
max-width: 20rem !important;
|
max-width: none !important;
|
||||||
|
flex-basis: auto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,21 +478,6 @@ const handleInstanceSwitch = async (value) => {
|
|||||||
margin-bottom: 0.5rem;
|
margin-bottom: 0.5rem;
|
||||||
font-size: 1.16rem;
|
font-size: 1.16rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.filter-checkbox {
|
|
||||||
margin-bottom: 0.3rem;
|
|
||||||
font-size: 1rem;
|
|
||||||
|
|
||||||
svg {
|
|
||||||
display: flex;
|
|
||||||
align-self: center;
|
|
||||||
justify-self: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
button.checkbox {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.search {
|
.search {
|
||||||
|
|||||||
@@ -349,6 +349,17 @@ const setJavaInstall = (javaInstall) => {
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
.testing-loader {
|
||||||
|
height: 1rem !important;
|
||||||
|
width: 1rem !important;
|
||||||
|
|
||||||
|
svg {
|
||||||
|
height: inherit !important;
|
||||||
|
width: inherit !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<style lang="scss" scoped>
|
||||||
.concurrent-downloads {
|
.concurrent-downloads {
|
||||||
width: 80% !important;
|
width: 80% !important;
|
||||||
}
|
}
|
||||||
@@ -451,16 +462,6 @@ const setJavaInstall = (javaInstall) => {
|
|||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.testing-loader {
|
|
||||||
height: 1rem !important;
|
|
||||||
width: 1rem !important;
|
|
||||||
|
|
||||||
svg {
|
|
||||||
height: inherit !important;
|
|
||||||
width: inherit !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-success {
|
.test-success {
|
||||||
color: var(--color-green);
|
color: var(--color-green);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
<Button v-else-if="loading === true && playing === false" disabled class="instance-button"
|
<Button v-else-if="loading === true && playing === false" disabled class="instance-button"
|
||||||
>Loading...</Button
|
>Loading...</Button
|
||||||
>
|
>
|
||||||
|
<!--TODO: https://github.com/tauri-apps/tauri/issues/4062 -->
|
||||||
<Button class="instance-button" icon-only @click="open({ defaultPath: instance.path })">
|
<Button class="instance-button" icon-only @click="open({ defaultPath: instance.path })">
|
||||||
<OpenFolderIcon />
|
<OpenFolderIcon />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
class="dropdown"
|
class="dropdown"
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
<Button color="primary" @click="searchMod()">
|
<Button color="primary" @click="router.push({ path: '/browse/mod' })">
|
||||||
<PlusIcon />
|
<PlusIcon />
|
||||||
<span class="no-wrap"> Add Content </span>
|
<span class="no-wrap"> Add Content </span>
|
||||||
</Button>
|
</Button>
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
<div class="table">
|
<div class="table">
|
||||||
<div class="table-row table-head">
|
<div class="table-row table-head">
|
||||||
<div class="table-cell table-text">
|
<div class="table-cell table-text">
|
||||||
<Button color="success" icon-only>
|
<Button icon-only :disabled="!projects.some((x) => x.outdated)" @click="updateAll">
|
||||||
<UpdatedIcon />
|
<UpdatedIcon />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -36,11 +36,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<div v-for="mod in search" :key="mod.file_name" class="table-row">
|
<div v-for="mod in search" :key="mod.file_name" class="table-row">
|
||||||
<div class="table-cell table-text">
|
<div class="table-cell table-text">
|
||||||
<Button v-if="mod.outdated" icon-only>
|
<AnimatedLogo v-if="mod.updating" class="btn icon-only updating-indicator"></AnimatedLogo>
|
||||||
<UpdatedIcon />
|
<Button v-else :disabled="!mod.outdated" icon-only @click="updateProject(mod)">
|
||||||
</Button>
|
<UpdatedIcon v-if="mod.outdated" />
|
||||||
<Button v-else disabled icon-only>
|
<CheckIcon v-else />
|
||||||
<CheckIcon />
|
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div class="table-cell table-text name-cell">
|
<div class="table-cell table-text name-cell">
|
||||||
@@ -56,14 +55,15 @@
|
|||||||
<div class="table-cell table-text">{{ mod.version }}</div>
|
<div class="table-cell table-text">{{ mod.version }}</div>
|
||||||
<div class="table-cell table-text">{{ mod.author }}</div>
|
<div class="table-cell table-text">{{ mod.author }}</div>
|
||||||
<div class="table-cell table-text manage">
|
<div class="table-cell table-text manage">
|
||||||
<Button icon-only>
|
<Button icon-only @click="removeMod(mod)">
|
||||||
<TrashIcon />
|
<TrashIcon />
|
||||||
</Button>
|
</Button>
|
||||||
<input
|
<input
|
||||||
id="switch-1"
|
id="switch-1"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
class="switch stylized-toggle"
|
class="switch stylized-toggle"
|
||||||
:checked="mod.disabled"
|
:checked="!mod.disabled"
|
||||||
|
@change="toggleDisableMod(mod)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -81,10 +81,17 @@ import {
|
|||||||
SearchIcon,
|
SearchIcon,
|
||||||
UpdatedIcon,
|
UpdatedIcon,
|
||||||
DropdownSelect,
|
DropdownSelect,
|
||||||
|
AnimatedLogo,
|
||||||
} from 'omorphia'
|
} from 'omorphia'
|
||||||
import { computed, ref, shallowRef } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { convertFileSrc } from '@tauri-apps/api/tauri'
|
import { convertFileSrc } from '@tauri-apps/api/tauri'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
|
import {
|
||||||
|
remove_project,
|
||||||
|
toggle_disable_project,
|
||||||
|
update_all,
|
||||||
|
update_project,
|
||||||
|
} from '@/helpers/profile.js'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
@@ -97,11 +104,12 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const projects = shallowRef([])
|
const projects = ref([])
|
||||||
for (const project of Object.values(props.instance.projects)) {
|
for (const [path, project] of Object.entries(props.instance.projects)) {
|
||||||
if (project.metadata.type === 'modrinth') {
|
if (project.metadata.type === 'modrinth') {
|
||||||
let owner = project.metadata.members.find((x) => x.role === 'Owner')
|
let owner = project.metadata.members.find((x) => x.role === 'Owner')
|
||||||
projects.value.push({
|
projects.value.push({
|
||||||
|
path,
|
||||||
name: project.metadata.project.title,
|
name: project.metadata.project.title,
|
||||||
slug: project.metadata.project.slug,
|
slug: project.metadata.project.slug,
|
||||||
author: owner ? owner.user.username : null,
|
author: owner ? owner.user.username : null,
|
||||||
@@ -109,10 +117,12 @@ for (const project of Object.values(props.instance.projects)) {
|
|||||||
file_name: project.file_name,
|
file_name: project.file_name,
|
||||||
icon: project.metadata.project.icon_url,
|
icon: project.metadata.project.icon_url,
|
||||||
disabled: project.disabled,
|
disabled: project.disabled,
|
||||||
outdated: project.metadata.update_version,
|
updateVersion: project.metadata.update_version,
|
||||||
|
outdated: !!project.metadata.update_version,
|
||||||
})
|
})
|
||||||
} else if (project.metadata.type === 'inferred') {
|
} else if (project.metadata.type === 'inferred') {
|
||||||
projects.value.push({
|
projects.value.push({
|
||||||
|
path,
|
||||||
name: project.metadata.title ?? project.file_name,
|
name: project.metadata.title ?? project.file_name,
|
||||||
author: project.metadata.authors[0],
|
author: project.metadata.authors[0],
|
||||||
version: project.metadata.version,
|
version: project.metadata.version,
|
||||||
@@ -123,6 +133,7 @@ for (const project of Object.values(props.instance.projects)) {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
projects.value.push({
|
projects.value.push({
|
||||||
|
path,
|
||||||
name: project.file_name,
|
name: project.file_name,
|
||||||
author: '',
|
author: '',
|
||||||
version: null,
|
version: null,
|
||||||
@@ -145,7 +156,7 @@ const search = computed(() => {
|
|||||||
return updateSort(filtered, sortFilter.value)
|
return updateSort(filtered, sortFilter.value)
|
||||||
})
|
})
|
||||||
|
|
||||||
const updateSort = (projects, sort) => {
|
function updateSort(projects, sort) {
|
||||||
switch (sort) {
|
switch (sort) {
|
||||||
case 'Version':
|
case 'Version':
|
||||||
return projects.slice().sort((a, b) => {
|
return projects.slice().sort((a, b) => {
|
||||||
@@ -180,8 +191,49 @@ const updateSort = (projects, sort) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchMod = () => {
|
async function updateAll() {
|
||||||
router.push({ path: '/browse/mod' })
|
const setProjects = []
|
||||||
|
for (const [i, project] of projects.value.entries()) {
|
||||||
|
if (project.outdated) {
|
||||||
|
project.updating = true
|
||||||
|
setProjects.push(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const paths = await update_all(props.instance.path)
|
||||||
|
|
||||||
|
for (const [oldVal, newVal] of Object.entries(paths)) {
|
||||||
|
const index = projects.value.findIndex((x) => x.path === oldVal)
|
||||||
|
projects.value[index].path = newVal
|
||||||
|
projects.value[index].outdated = false
|
||||||
|
|
||||||
|
if (projects.value[index].updateVersion) {
|
||||||
|
projects.value[index].version = projects.value[index].updateVersion.version_number
|
||||||
|
projects.value[index].updateVersion = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const project of setProjects) {
|
||||||
|
projects.value[project].updating = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateProject(mod) {
|
||||||
|
mod.updating = true
|
||||||
|
mod.path = await update_project(props.instance.path, mod.path)
|
||||||
|
mod.updating = false
|
||||||
|
|
||||||
|
mod.outdated = false
|
||||||
|
mod.version = mod.updateVersion.version_number
|
||||||
|
mod.updateVersion = null
|
||||||
|
}
|
||||||
|
|
||||||
|
async function toggleDisableMod(mod) {
|
||||||
|
mod.path = await toggle_disable_project(props.instance.path, mod.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeMod(mod) {
|
||||||
|
await remove_project(props.instance.path, mod.path)
|
||||||
|
projects.value = projects.value.filter((x) => mod.path !== x.path)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -241,3 +293,10 @@ const searchMod = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<style lang="scss">
|
||||||
|
.updating-indicator {
|
||||||
|
svg {
|
||||||
|
margin-left: 0.5rem !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user