Fix syncing, repairing, add edit method (#111)

* Fix syncing, repairing, add edit method

* comp err

* temp push up

* fixes

* fix more

* add frontend
This commit is contained in:
Geometrically
2023-05-11 10:26:00 -07:00
committed by GitHub
parent 71cf2c53f5
commit 7a0798d9d0
24 changed files with 501 additions and 352 deletions

View File

@@ -29,6 +29,6 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: yarn install --immutable --immutable-cache --check-cache run: yarn install --immutable --immutable-cache --check-cache
- name: Run Lint - name: Run Lint
run: npm run lint run: yarn run lint
- name: Build - name: Build
run: npm run build run: yarn run build

View File

@@ -5,7 +5,9 @@ use crate::event::emit::{
loading_try_for_each_concurrent, loading_try_for_each_concurrent,
}; };
use crate::event::{LoadingBarId, LoadingBarType}; use crate::event::{LoadingBarId, LoadingBarType};
use crate::state::{LinkedData, ModrinthProject, ModrinthVersion, SideType}; use crate::state::{
LinkedData, ModrinthProject, ModrinthVersion, ProfileInstallStage, SideType,
};
use crate::util::fetch::{ use crate::util::fetch::{
fetch, fetch_advanced, fetch_json, fetch_mirrors, write, write_cached_icon, fetch, fetch_advanced, fetch_json, fetch_mirrors, write, write_cached_icon,
}; };
@@ -76,13 +78,28 @@ enum PackDependency {
pub async fn install_pack_from_version_id( pub async fn install_pack_from_version_id(
version_id: String, version_id: String,
title: Option<String>, title: String,
icon_url: Option<String>,
) -> crate::Result<PathBuf> { ) -> crate::Result<PathBuf> {
let state = State::get().await?; let state = State::get().await?;
Box::pin(async move { Box::pin(async move {
let profile = crate::api::profile_create::profile_create(
title.clone(),
"1.19.4".to_string(),
ModLoader::Vanilla,
None,
None,
icon_url.clone(),
None,
Some(true),
)
.await?;
let loading_bar = init_loading( let loading_bar = init_loading(
LoadingBarType::PackFileDownload { LoadingBarType::PackFileDownload {
profile_path: profile.clone(),
pack_name: title, pack_name: title,
icon: icon_url,
pack_version: version_id.clone(), pack_version: version_id.clone(),
}, },
100.0, 100.0,
@@ -171,6 +188,7 @@ pub async fn install_pack_from_version_id(
Some(version.project_id), Some(version.project_id),
Some(version.id), Some(version.id),
Some(loading_bar), Some(loading_bar),
profile,
) )
.await .await
}) })
@@ -178,9 +196,36 @@ pub async fn install_pack_from_version_id(
} }
pub async fn install_pack_from_file(path: PathBuf) -> crate::Result<PathBuf> { pub async fn install_pack_from_file(path: PathBuf) -> crate::Result<PathBuf> {
let file = fs::read(path).await?; let file = fs::read(&path).await?;
install_pack(bytes::Bytes::from(file), None, None, None, None, None).await let file_name = path
.file_name()
.unwrap_or_default()
.to_string_lossy()
.to_string();
let profile = crate::api::profile_create::profile_create(
file_name,
"1.19.4".to_string(),
ModLoader::Vanilla,
None,
None,
None,
None,
Some(true),
)
.await?;
install_pack(
bytes::Bytes::from(file),
None,
None,
None,
None,
None,
profile,
)
.await
} }
async fn install_pack( async fn install_pack(
@@ -190,6 +235,7 @@ async fn install_pack(
project_id: Option<String>, project_id: Option<String>,
version_id: Option<String>, version_id: Option<String>,
existing_loading_bar: Option<LoadingBarId>, existing_loading_bar: Option<LoadingBarId>,
profile: PathBuf,
) -> crate::Result<PathBuf> { ) -> crate::Result<PathBuf> {
let state = &State::get().await?; let state = &State::get().await?;
@@ -261,25 +307,38 @@ async fn install_pack(
.into()); .into());
}; };
let profile_raw = crate::api::profile_create::profile_create( let loader_version =
override_title.unwrap_or_else(|| pack.name.clone()), crate::profile_create::get_loader_version_from_loader(
game_version.clone(), game_version.clone(),
mod_loader.unwrap_or(ModLoader::Vanilla), mod_loader.unwrap_or(ModLoader::Vanilla),
loader_version.cloned(), loader_version.cloned(),
icon, )
Some(LinkedData { .await?;
crate::api::profile::edit(&profile, |prof| {
prof.metadata.name =
override_title.clone().unwrap_or_else(|| pack.name.clone());
prof.install_stage = ProfileInstallStage::PackInstalling;
prof.metadata.linked_data = Some(LinkedData {
project_id: project_id.clone(), project_id: project_id.clone(),
version_id: version_id.clone(), version_id: version_id.clone(),
}), });
Some(true), prof.metadata.icon = icon.clone();
) prof.metadata.game_version = game_version.clone();
prof.metadata.loader_version = loader_version.clone();
async { Ok(()) }
})
.await?; .await?;
let profile = profile_raw.clone(); State::sync().await?;
let profile = profile.clone();
let result = async { let result = async {
let loading_bar = init_or_edit_loading( let loading_bar = init_or_edit_loading(
existing_loading_bar, existing_loading_bar,
LoadingBarType::PackDownload { LoadingBarType::PackDownload {
profile_path: profile.clone(),
pack_name: pack.name.clone(), pack_name: pack.name.clone(),
icon,
pack_id: project_id, pack_id: project_id,
pack_version: version_id, pack_version: version_id,
}, },
@@ -413,7 +472,7 @@ async fn install_pack(
emit_loading( emit_loading(
&loading_bar, &loading_bar,
29.9, 29.9,
Some("Done extacting overrides"), Some("Done extracting overrides"),
) )
.await?; .await?;
@@ -429,19 +488,21 @@ async fn install_pack(
)?; )?;
} }
Ok::<PathBuf, crate::Error>(profile) Ok::<PathBuf, crate::Error>(profile.clone())
} }
.await; .await;
match result { match result {
Ok(profile) => Ok(profile), Ok(profile) => Ok(profile),
Err(err) => { Err(err) => {
let _ = crate::api::profile::remove(&profile_raw).await; let _ = crate::api::profile::remove(&profile).await;
Err(err) Err(err)
} }
} }
} else { } else {
let _ = crate::api::profile::remove(&profile).await;
Err(crate::Error::from(crate::ErrorKind::InputError( Err(crate::Error::from(crate::ErrorKind::InputError(
"No pack manifest found in mrpack".to_string(), "No pack manifest found in mrpack".to_string(),
))) )))

View File

@@ -98,7 +98,7 @@ pub async fn sync(path: &Path) -> crate::Result<()> {
> = state.profiles.write().await; > = state.profiles.write().await;
if let Some(profile) = profiles.0.get_mut(path) { if let Some(profile) = profiles.0.get_mut(path) {
profile.sync().await?; profile.sync_projects().await?;
Ok(()) Ok(())
} else { } else {
Err(crate::ErrorKind::UnmanagedProfileError( Err(crate::ErrorKind::UnmanagedProfileError(
@@ -117,24 +117,18 @@ pub async fn sync(path: &Path) -> crate::Result<()> {
/// Installs/Repairs a profile /// Installs/Repairs a profile
#[tracing::instrument] #[tracing::instrument]
pub async fn install(path: &Path) -> crate::Result<()> { pub async fn install(path: &Path) -> crate::Result<()> {
let state = State::get().await?; let profile = get(path).await?;
let result = {
let mut profiles: tokio::sync::RwLockWriteGuard<
crate::state::Profiles,
> = state.profiles.write().await;
if let Some(profile) = profiles.0.get_mut(path) { if let Some(profile) = profile {
crate::launcher::install_minecraft(profile, None).await?; crate::launcher::install_minecraft(&profile, None).await?;
Ok(()) } else {
} else { return Err(crate::ErrorKind::UnmanagedProfileError(
Err(crate::ErrorKind::UnmanagedProfileError( path.display().to_string(),
path.display().to_string(), )
) .as_error());
.as_error()) }
}
};
State::sync().await?; State::sync().await?;
result Ok(())
} }
pub async fn update_all(profile_path: &Path) -> crate::Result<()> { pub async fn update_all(profile_path: &Path) -> crate::Result<()> {
@@ -145,7 +139,7 @@ pub async fn update_all(profile_path: &Path) -> crate::Result<()> {
if let Some(profile) = profiles.0.get_mut(profile_path) { if let Some(profile) = profiles.0.get_mut(profile_path) {
let loading_bar = init_loading( let loading_bar = init_loading(
LoadingBarType::ProfileUpdate { LoadingBarType::ProfileUpdate {
profile_uuid: profile.uuid, profile_path: profile.path.clone(),
profile_name: profile.metadata.name.clone(), profile_name: profile.metadata.name.clone(),
}, },
100.0, 100.0,
@@ -162,11 +156,15 @@ pub async fn update_all(profile_path: &Path) -> crate::Result<()> {
100.0, 100.0,
profile.projects.keys().len(), profile.projects.keys().len(),
None, None,
|project| update_project(profile_path, project, Some(true)), |project| async move {
let _ = update_project(profile_path, project).await?;
Ok(())
},
) )
.await?; .await?;
profile.sync().await?; profile.sync_projects().await?;
Ok(()) Ok(())
} else { } else {
@@ -182,8 +180,7 @@ pub async fn update_all(profile_path: &Path) -> crate::Result<()> {
pub async fn update_project( pub async fn update_project(
profile_path: &Path, profile_path: &Path,
project_path: &Path, project_path: &Path,
should_not_sync: Option<bool>, ) -> crate::Result<PathBuf> {
) -> crate::Result<()> {
let state = State::get().await?; let state = State::get().await?;
let mut profiles = state.profiles.write().await; let mut profiles = state.profiles.write().await;
@@ -194,21 +191,33 @@ pub async fn update_project(
.. ..
} = &project.metadata } = &project.metadata
{ {
let path = profile let (path, new_version) = profile
.add_project_version(update_version.id.clone()) .add_project_version(update_version.id.clone())
.await?; .await?;
if path != project_path { if path != project_path {
profile.remove_project(project_path).await?; profile.remove_project(project_path, Some(true)).await?;
} }
if !should_not_sync.unwrap_or(false) { let value = profile.projects.remove(project_path);
profile.sync().await?; if let Some(mut project) = value {
if let ProjectMetadata::Modrinth {
ref mut version, ..
} = project.metadata
{
*version = Box::new(new_version);
}
profile.projects.insert(path.clone(), project);
} }
return Ok(path);
} }
} }
Ok(()) Err(crate::ErrorKind::InputError(
"This project cannot be updated!".to_string(),
)
.as_error())
} else { } else {
Err(crate::ErrorKind::UnmanagedProfileError( Err(crate::ErrorKind::UnmanagedProfileError(
profile_path.display().to_string(), profile_path.display().to_string(),
@@ -227,13 +236,23 @@ pub async fn replace_project(
let mut profiles = state.profiles.write().await; let mut profiles = state.profiles.write().await;
if let Some(profile) = profiles.0.get_mut(profile_path) { if let Some(profile) = profiles.0.get_mut(profile_path) {
let path = profile.add_project_version(version_id).await?; let (path, new_version) =
profile.add_project_version(version_id).await?;
if path != project { if path != project {
profile.remove_project(project).await?; profile.remove_project(project, Some(true)).await?;
} }
profile.sync().await?; let value = profile.projects.remove(project);
if let Some(mut project) = value {
if let ProjectMetadata::Modrinth {
ref mut version, ..
} = project.metadata
{
*version = Box::new(new_version);
}
profile.projects.insert(path.clone(), project);
}
Ok(path) Ok(path)
} else { } else {
@@ -254,9 +273,9 @@ pub async fn add_project_from_version(
let mut profiles = state.profiles.write().await; let mut profiles = state.profiles.write().await;
if let Some(profile) = profiles.0.get_mut(profile_path) { if let Some(profile) = profiles.0.get_mut(profile_path) {
let path = profile.add_project_version(version_id).await?; let (path, _) = profile.add_project_version(version_id).await?;
profile.sync().await?; Profile::sync_projects_task(profile.path.clone());
Ok(path) Ok(path)
} else { } else {
@@ -293,7 +312,7 @@ pub async fn add_project_from_path(
) )
.await?; .await?;
profile.sync().await?; Profile::sync_projects_task(profile.path.clone());
Ok(path) Ok(path)
} else { } else {
@@ -335,7 +354,7 @@ pub async fn remove_project(
let mut profiles = state.profiles.write().await; let mut profiles = state.profiles.write().await;
if let Some(profile) = profiles.0.get_mut(profile) { if let Some(profile) = profiles.0.get_mut(profile) {
profile.remove_project(project).await?; profile.remove_project(project, None).await?;
Ok(()) Ok(())
} else { } else {

View File

@@ -33,6 +33,7 @@ pub async fn profile_create_empty() -> crate::Result<PathBuf> {
None, // the icon for the profile None, // the icon for the profile
None, None,
None, None,
None,
) )
.await .await
} }
@@ -40,20 +41,20 @@ pub async fn profile_create_empty() -> crate::Result<PathBuf> {
// Creates a profile at the given filepath and adds it to the in-memory state // Creates a profile at the given filepath and adds it to the in-memory state
// Returns filepath at which it can be accessed in the State // Returns filepath at which it can be accessed in the State
#[tracing::instrument] #[tracing::instrument]
#[allow(clippy::too_many_arguments)]
pub async fn profile_create( pub async fn profile_create(
name: String, // the name of the profile, and relative path name: String, // the name of the profile, and relative path
game_version: String, // the game version of the profile game_version: String, // the game version of the profile
modloader: ModLoader, // the modloader to use modloader: ModLoader, // the modloader to use
loader_version: Option<String>, // the modloader version to use, set to "latest", "stable", or the ID of your chosen loader. defaults to latest loader_version: Option<String>, // the modloader version to use, set to "latest", "stable", or the ID of your chosen loader. defaults to latest
icon: Option<PathBuf>, // the icon for the profile icon: Option<PathBuf>, // the icon for the profile
icon_url: Option<String>, // the URL icon for a profile (ONLY USED FOR TEMPORARY PROFILES)
linked_data: Option<LinkedData>, // the linked project ID (mainly for modpacks)- used for updating linked_data: Option<LinkedData>, // the linked project ID (mainly for modpacks)- used for updating
skip_install_profile: Option<bool>, skip_install_profile: Option<bool>,
) -> crate::Result<PathBuf> { ) -> crate::Result<PathBuf> {
trace!("Creating new profile. {}", name); trace!("Creating new profile. {}", name);
let state = State::get().await?; let state = State::get().await?;
Box::pin(async move { Box::pin(async move {
let metadata = state.metadata.read().await;
let uuid = Uuid::new_v4(); let uuid = Uuid::new_v4();
let path = state.directories.profiles_dir().join(uuid.to_string()); let path = state.directories.profiles_dir().join(uuid.to_string());
if path.exists() { if path.exists() {
@@ -82,66 +83,8 @@ pub async fn profile_create(
"Creating profile at path {}", "Creating profile at path {}",
&canonicalize(&path)?.display() &canonicalize(&path)?.display()
); );
let loader = if modloader != ModLoader::Vanilla {
let loader = modloader; get_loader_version_from_loader(game_version.clone(), modloader, loader_version).await?
let loader = if loader != ModLoader::Vanilla {
let version = loader_version.unwrap_or_else(|| "latest".to_string());
let filter = |it: &LoaderVersion| match version.as_str() {
"latest" => true,
"stable" => it.stable,
id => it.id == *id || format!("{}-{}", game_version, id) == it.id,
};
let loader_data = match loader {
ModLoader::Forge => &metadata.forge,
ModLoader::Fabric => &metadata.fabric,
ModLoader::Quilt => &metadata.quilt,
_ => {
return Err(ProfileCreationError::NoManifest(
loader.to_string(),
)
.into())
}
};
let loaders = &loader_data
.game_versions
.iter()
.find(|it| {
it.id.replace(
daedalus::modded::DUMMY_REPLACE_STRING,
&game_version,
) == game_version
})
.ok_or_else(|| {
ProfileCreationError::ModloaderUnsupported(
loader.to_string(),
game_version.clone(),
)
})?
.loaders;
let loader_version = loaders
.iter()
.cloned()
.find(filter)
.or(
// If stable was searched for but not found, return latest by default
if version == "stable" {
loaders.iter().next().cloned()
} else {
None
},
)
.ok_or_else(|| {
ProfileCreationError::InvalidVersionModloader(
version,
loader.to_string(),
)
})?;
Some((loader_version, loader))
} else { } else {
None None
}; };
@@ -161,8 +104,9 @@ pub async fn profile_create(
) )
.await?; .await?;
} }
if let Some((loader_version, loader)) = loader { profile.metadata.icon_url = icon_url;
profile.metadata.loader = loader; if let Some(loader_version) = loader {
profile.metadata.loader = modloader;
profile.metadata.loader_version = Some(loader_version); profile.metadata.loader_version = Some(loader_version);
} }
@@ -203,6 +147,71 @@ pub async fn profile_create(
}).await }).await
} }
pub(crate) async fn get_loader_version_from_loader(
game_version: String,
loader: ModLoader,
loader_version: Option<String>,
) -> crate::Result<Option<LoaderVersion>> {
let state = State::get().await?;
let metadata = state.metadata.read().await;
let version = loader_version.unwrap_or_else(|| "latest".to_string());
let filter = |it: &LoaderVersion| match version.as_str() {
"latest" => true,
"stable" => it.stable,
id => it.id == *id || format!("{}-{}", game_version, id) == it.id,
};
let loader_data = match loader {
ModLoader::Forge => &metadata.forge,
ModLoader::Fabric => &metadata.fabric,
ModLoader::Quilt => &metadata.quilt,
_ => {
return Err(
ProfileCreationError::NoManifest(loader.to_string()).into()
)
}
};
let loaders = &loader_data
.game_versions
.iter()
.find(|it| {
it.id
.replace(daedalus::modded::DUMMY_REPLACE_STRING, &game_version)
== game_version
})
.ok_or_else(|| {
ProfileCreationError::ModloaderUnsupported(
loader.to_string(),
game_version.clone(),
)
})?
.loaders;
let loader_version = loaders
.iter()
.cloned()
.find(filter)
.or(
// If stable was searched for but not found, return latest by default
if version == "stable" {
loaders.iter().next().cloned()
} else {
None
},
)
.ok_or_else(|| {
ProfileCreationError::InvalidVersionModloader(
version,
loader.to_string(),
)
})?;
Ok(Some(loader_version))
}
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub enum ProfileCreationError { pub enum ProfileCreationError {
#[error("Profile .json exists: {0}")] #[error("Profile .json exists: {0}")]

View File

@@ -148,20 +148,24 @@ impl Drop for LoadingBar {
pub enum LoadingBarType { pub enum LoadingBarType {
StateInit, StateInit,
PackFileDownload { PackFileDownload {
pack_name: Option<String>, profile_path: PathBuf,
pack_name: String,
icon: Option<String>,
pack_version: String, pack_version: String,
}, },
PackDownload { PackDownload {
profile_path: PathBuf,
pack_name: String, pack_name: String,
icon: Option<PathBuf>,
pack_id: Option<String>, pack_id: Option<String>,
pack_version: Option<String>, pack_version: Option<String>,
}, },
MinecraftDownload { MinecraftDownload {
profile_uuid: Uuid, profile_path: PathBuf,
profile_name: String, profile_name: String,
}, },
ProfileUpdate { ProfileUpdate {
profile_uuid: Uuid, profile_path: PathBuf,
profile_name: String, profile_name: String,
}, },
} }
@@ -187,6 +191,7 @@ pub struct ProcessPayload {
pub message: String, pub message: String,
} }
#[derive(Serialize, Clone, Debug)] #[derive(Serialize, Clone, Debug)]
#[serde(rename_all = "snake_case")]
pub enum ProcessPayloadType { pub enum ProcessPayloadType {
Launched, Launched,
Updated, // eg: if the MinecraftChild changes to its post-command process instead of the Minecraft process Updated, // eg: if the MinecraftChild changes to its post-command process instead of the Minecraft process

View File

@@ -1,6 +1,7 @@
//! Logic for launching Minecraft //! Logic for launching Minecraft
use crate::event::emit::{emit_loading, init_or_edit_loading}; use crate::event::emit::{emit_loading, init_or_edit_loading};
use crate::event::{LoadingBarId, LoadingBarType}; use crate::event::{LoadingBarId, LoadingBarType};
use crate::state::ProfileInstallStage;
use crate::{ use crate::{
process, process,
state::{self as st, MinecraftChild}, state::{self as st, MinecraftChild},
@@ -59,9 +60,18 @@ pub async fn install_minecraft(
existing_loading_bar: Option<LoadingBarId>, existing_loading_bar: Option<LoadingBarId>,
) -> crate::Result<()> { ) -> crate::Result<()> {
Box::pin(async move { Box::pin(async move {
crate::api::profile::edit(&profile.path, |prof| {
prof.install_stage = ProfileInstallStage::Installing;
async { Ok(()) }
})
.await?;
State::sync().await?;
let state = State::get().await?; let state = State::get().await?;
let instance_path = &canonicalize(&profile.path)?; let instance_path = &canonicalize(&profile.path)?;
let metadata = state.metadata.read().await; let metadata = state.metadata.read().await;
let version = metadata let version = metadata
.minecraft .minecraft
.versions .versions
@@ -85,7 +95,7 @@ pub async fn install_minecraft(
LoadingBarType::MinecraftDownload { LoadingBarType::MinecraftDownload {
// If we are downloading minecraft for a profile, provide its name and uuid // If we are downloading minecraft for a profile, provide its name and uuid
profile_name: profile.metadata.name.clone(), profile_name: profile.metadata.name.clone(),
profile_uuid: profile.uuid, profile_path: profile.path.clone(),
}, },
100.0, 100.0,
"Downloading Minecraft", "Downloading Minecraft",
@@ -202,11 +212,11 @@ pub async fn install_minecraft(
} }
crate::api::profile::edit(&profile.path, |prof| { crate::api::profile::edit(&profile.path, |prof| {
prof.installed = true; prof.install_stage = ProfileInstallStage::Installed;
async { Ok(()) } async { Ok(()) }
}) })
.await?; .await?;
State::sync().await?; State::sync().await?;
emit_loading( emit_loading(
&loading_bar, &loading_bar,
@@ -232,7 +242,16 @@ pub async fn launch_minecraft(
profile: &Profile, profile: &Profile,
) -> crate::Result<Arc<tokio::sync::RwLock<MinecraftChild>>> { ) -> crate::Result<Arc<tokio::sync::RwLock<MinecraftChild>>> {
Box::pin(async move { Box::pin(async move {
if !profile.installed { if profile.install_stage == ProfileInstallStage::PackInstalling
|| profile.install_stage == ProfileInstallStage::Installing
{
return Err(crate::ErrorKind::LauncherError(
"Profile is still installing".to_string(),
)
.into());
}
if profile.install_stage != ProfileInstallStage::Installed {
install_minecraft(profile, None).await?; install_minecraft(profile, None).await?;
} }

View File

@@ -4,11 +4,12 @@ use crate::data::DirectoryInfo;
use crate::event::emit::emit_profile; use crate::event::emit::emit_profile;
use crate::event::ProfilePayloadType; use crate::event::ProfilePayloadType;
use crate::state::projects::Project; use crate::state::projects::Project;
use crate::state::{ModrinthVersion, ProjectType}; use crate::state::{ModrinthVersion, ProjectMetadata, ProjectType};
use crate::util::fetch::{ use crate::util::fetch::{
fetch, fetch_json, write, write_cached_icon, IoSemaphore, fetch, fetch_json, write, write_cached_icon, IoSemaphore,
}; };
use crate::State; use crate::State;
use daedalus::get_hash;
use daedalus::modded::LoaderVersion; use daedalus::modded::LoaderVersion;
use dunce::canonicalize; use dunce::canonicalize;
use futures::prelude::*; use futures::prelude::*;
@@ -29,12 +30,28 @@ pub(crate) struct Profiles(pub HashMap<PathBuf, Profile>);
// TODO: possibly add defaults to some of these values // TODO: possibly add defaults to some of these values
pub const CURRENT_FORMAT_VERSION: u32 = 1; pub const CURRENT_FORMAT_VERSION: u32 = 1;
#[derive(
Serialize, Deserialize, Clone, Copy, Debug, Default, Eq, PartialEq,
)]
#[serde(rename_all = "snake_case")]
pub enum ProfileInstallStage {
/// Profile is installed
Installed,
/// Profile's minecraft game is still installing
Installing,
/// Profile created for pack, but the pack hasn't been fully installed yet
PackInstalling,
/// Profile is not installed
#[default]
NotInstalled,
}
// Represent a Minecraft instance. // Represent a Minecraft instance.
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Profile { pub struct Profile {
pub uuid: Uuid, // todo: will be used in restructure to refer to profiles pub uuid: Uuid, // todo: will be used in restructure to refer to profiles
#[serde(default)] #[serde(default)]
pub installed: bool, pub install_stage: ProfileInstallStage,
pub path: PathBuf, pub path: PathBuf,
pub metadata: ProfileMetadata, pub metadata: ProfileMetadata,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@@ -53,6 +70,8 @@ pub struct ProfileMetadata {
pub name: String, pub name: String,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub icon: Option<PathBuf>, pub icon: Option<PathBuf>,
#[serde(skip_serializing_if = "Option::is_none")]
pub icon_url: Option<String>,
pub game_version: String, pub game_version: String,
#[serde(default)] #[serde(default)]
pub loader: ModLoader, pub loader: ModLoader,
@@ -127,11 +146,12 @@ impl Profile {
Ok(Self { Ok(Self {
uuid, uuid,
installed: false, install_stage: ProfileInstallStage::NotInstalled,
path: canonicalize(path)?, path: canonicalize(path)?,
metadata: ProfileMetadata { metadata: ProfileMetadata {
name, name,
icon: None, icon: None,
icon_url: None,
game_version: version, game_version: version,
loader: ModLoader::Vanilla, loader: ModLoader::Vanilla,
loader_version: None, loader_version: None,
@@ -160,7 +180,7 @@ impl Profile {
Ok(self) Ok(self)
} }
pub async fn sync(&mut self) -> crate::Result<()> { pub async fn sync_projects(&mut self) -> crate::Result<()> {
let state = State::get().await?; let state = State::get().await?;
let paths = self.get_profile_project_paths()?; let paths = self.get_profile_project_paths()?;
@@ -186,6 +206,45 @@ impl Profile {
Ok(()) Ok(())
} }
pub fn sync_projects_task(path: PathBuf) {
tokio::task::spawn(async move {
let res = async {
let state = State::get().await?;
let profile = crate::api::profile::get(&path).await?;
if let Some(profile) = profile {
let paths = profile.get_profile_project_paths()?;
let projects = crate::state::infer_data_from_files(
profile,
paths,
state.directories.caches_dir(),
&state.io_semaphore,
&state.fetch_semaphore,
)
.await?;
let mut new_profiles = state.profiles.write().await;
if let Some(profile) = new_profiles.0.get_mut(&path) {
profile.projects = projects;
}
}
Ok::<(), crate::Error>(())
}
.await;
match res {
Ok(()) => {}
Err(err) => {
tracing::warn!(
"Unable to fetch single profile projects: {err}"
)
}
};
});
}
pub fn get_profile_project_paths(&self) -> crate::Result<Vec<PathBuf>> { pub fn get_profile_project_paths(&self) -> crate::Result<Vec<PathBuf>> {
let mut files = Vec::new(); let mut files = Vec::new();
let mut read_paths = |path: &str| { let mut read_paths = |path: &str| {
@@ -212,7 +271,7 @@ impl Profile {
pub async fn add_project_version( pub async fn add_project_version(
&mut self, &mut self,
version_id: String, version_id: String,
) -> crate::Result<PathBuf> { ) -> crate::Result<(PathBuf, ModrinthVersion)> {
let state = State::get().await?; let state = State::get().await?;
let version = fetch_json::<ModrinthVersion>( let version = fetch_json::<ModrinthVersion>(
@@ -247,11 +306,11 @@ impl Profile {
.add_project_bytes( .add_project_bytes(
&file.filename, &file.filename,
bytes, bytes,
ProjectType::get_from_loaders(version.loaders), ProjectType::get_from_loaders(version.loaders.clone()),
) )
.await?; .await?;
Ok(path) Ok((path, version))
} }
pub async fn add_project_bytes( pub async fn add_project_bytes(
@@ -294,6 +353,25 @@ impl Profile {
let path = self.path.join(project_type.get_folder()).join(file_name); let path = self.path.join(project_type.get_folder()).join(file_name);
write(&path, &bytes, &state.io_semaphore).await?; write(&path, &bytes, &state.io_semaphore).await?;
let hash = get_hash(bytes).await?;
self.projects.insert(
path.clone(),
Project {
sha512: hash,
disabled: false,
metadata: ProjectMetadata::Unknown,
file_name: file_name.to_string(),
},
);
emit_profile(
self.uuid,
self.path.clone(),
&self.metadata.name,
ProfilePayloadType::Synced,
)
.await?;
Ok(path) Ok(path)
} }
@@ -329,10 +407,16 @@ impl Profile {
Ok(()) Ok(())
} }
pub async fn remove_project(&mut self, path: &Path) -> crate::Result<()> { pub async fn remove_project(
&mut self,
path: &Path,
dont_remove_arr: Option<bool>,
) -> crate::Result<()> {
if self.projects.contains_key(path) { if self.projects.contains_key(path) {
fs::remove_file(path).await?; fs::remove_file(path).await?;
self.projects.remove(path); if !dont_remove_arr.unwrap_or(false) {
self.projects.remove(path);
}
} else { } else {
return Err(crate::ErrorKind::InputError(format!( return Err(crate::ErrorKind::InputError(format!(
"Project path does not exist: {:?}", "Project path does not exist: {:?}",

View File

@@ -195,6 +195,7 @@ impl ProfileInit {
None, None,
None, None,
None, None,
None,
) )
.await?; .await?;

View File

@@ -2,15 +2,15 @@ use crate::api::Result;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use theseus::prelude::*; use theseus::prelude::*;
// Creates a pack from a version ID (returns a path to the created profile)
// invoke('pack_install_version_id', version_id)
#[tauri::command] #[tauri::command]
pub async fn pack_install_version_id( pub async fn pack_install_version_id(
version_id: String, version_id: String,
pack_title: Option<String>, pack_title: String,
pack_icon: Option<String>,
) -> Result<PathBuf> { ) -> Result<PathBuf> {
let res = let res =
pack::install_pack_from_version_id(version_id, pack_title).await?; pack::install_pack_from_version_id(version_id, pack_title, pack_icon)
.await?;
Ok(res) Ok(res)
} }

View File

@@ -1,4 +1,6 @@
use crate::api::Result; use crate::api::Result;
use daedalus::modded::LoaderVersion;
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use theseus::prelude::*; use theseus::prelude::*;
use uuid::Uuid; use uuid::Uuid;
@@ -59,7 +61,7 @@ pub async fn profile_update_project(
path: &Path, path: &Path,
project_path: &Path, project_path: &Path,
) -> Result<()> { ) -> Result<()> {
profile::update_project(path, project_path, None).await?; profile::update_project(path, project_path).await?;
Ok(()) Ok(())
} }
@@ -165,3 +167,53 @@ pub async fn profile_run_wait_credentials(
let mut proc = proc_lock.write().await; let mut proc = proc_lock.write().await;
Ok(process::wait_for(&mut proc).await?) Ok(process::wait_for(&mut proc).await?)
} }
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct EditProfile {
pub metadata: Option<EditProfileMetadata>,
pub java: Option<JavaSettings>,
pub memory: Option<MemorySettings>,
pub resolution: Option<WindowSize>,
pub hooks: Option<Hooks>,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct EditProfileMetadata {
pub name: Option<String>,
pub game_version: Option<String>,
pub loader: Option<ModLoader>,
pub loader_version: Option<LoaderVersion>,
}
// Edits a profile
// invoke('profile_edit', {path, editProfile})
#[tauri::command]
pub async fn profile_edit(
path: &Path,
edit_profile: EditProfile,
) -> Result<()> {
profile::edit(&path, |prof| {
if let Some(metadata) = edit_profile.metadata.clone() {
if let Some(name) = metadata.name {
prof.metadata.name = name
}
if let Some(game_version) = metadata.game_version {
prof.metadata.game_version = game_version
}
if let Some(loader) = metadata.loader {
prof.metadata.loader = loader
}
prof.metadata.loader_version = metadata.loader_version
}
prof.java = edit_profile.java.clone();
prof.memory = edit_profile.memory;
prof.resolution = edit_profile.resolution;
prof.hooks = edit_profile.hooks.clone();
async { Ok(()) }
})
.await?;
Ok(())
}

View File

@@ -28,6 +28,7 @@ pub async fn profile_create(
icon, icon,
None, None,
None, None,
None,
) )
.await?; .await?;
Ok(res) Ok(res)

View File

@@ -92,6 +92,7 @@ fn main() {
api::profile::profile_run_wait, api::profile::profile_run_wait,
api::profile::profile_run_credentials, api::profile::profile_run_credentials,
api::profile::profile_run_wait_credentials, api::profile::profile_run_wait_credentials,
api::profile::profile_edit,
api::pack::pack_install_version_id, api::pack::pack_install_version_id,
api::pack::pack_install_file, api::pack::pack_install_file,
api::auth::auth_authenticate_begin_flow, api::auth::auth_authenticate_begin_flow,

View File

@@ -97,19 +97,13 @@ const modsRow = ref(null)
.instances { .instances {
display: grid; display: grid;
grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
width: 100%; width: 100%;
gap: 1rem; gap: 1rem;
margin-right: auto; margin-right: auto;
margin-top: 0.8rem; margin-top: 0.8rem;
scroll-behavior: smooth; scroll-behavior: smooth;
overflow-x: scroll; overflow-y: scroll;
overflow-y: hidden;
&::-webkit-scrollbar {
width: 0px;
background: transparent;
}
} }
} }

View File

@@ -1,7 +1,6 @@
<script setup> <script setup>
import { ChevronLeftIcon, ChevronRightIcon } from 'omorphia' import { ChevronLeftIcon, ChevronRightIcon } from 'omorphia'
import Instance from '@/components/ui/Instance.vue' import Instance from '@/components/ui/Instance.vue'
import News from '@/components/ui/News.vue'
import { onMounted, onUnmounted, ref } from 'vue' import { onMounted, onUnmounted, ref } from 'vue'
const props = defineProps({ const props = defineProps({
@@ -11,12 +10,6 @@ const props = defineProps({
return [] return []
}, },
}, },
news: {
type: Array,
default() {
return []
},
},
label: { label: {
type: String, type: String,
default: '', default: '',
@@ -26,16 +19,9 @@ const props = defineProps({
const allowPagination = ref(false) const allowPagination = ref(false)
const modsRow = ref(null) const modsRow = ref(null)
const newsRow = ref(null)
const shouldRenderNormalInstances = props.instances && props.instances?.length !== 0
const shouldRenderNews = props.news && props.news?.length !== 0
const handlePaginationDisplay = () => { const handlePaginationDisplay = () => {
let parentsRow let parentsRow = modsRow.value
if (shouldRenderNormalInstances) parentsRow = modsRow.value
if (shouldRenderNews) parentsRow = newsRow.value
if (!parentsRow) return
// This is wrapped in a setTimeout because the HtmlCollection seems to struggle // This is wrapped in a setTimeout because the HtmlCollection seems to struggle
// with getting populated sometimes. It's a flaky error, but providing a bit of // with getting populated sometimes. It's a flaky error, but providing a bit of
@@ -53,7 +39,7 @@ const handlePaginationDisplay = () => {
onMounted(() => { onMounted(() => {
if (props.canPaginate) window.addEventListener('resize', handlePaginationDisplay) if (props.canPaginate) window.addEventListener('resize', handlePaginationDisplay)
// Check if pagination should be rendered on mount
handlePaginationDisplay() handlePaginationDisplay()
}) })
onUnmounted(() => { onUnmounted(() => {
@@ -61,12 +47,10 @@ onUnmounted(() => {
}) })
const handleLeftPage = () => { const handleLeftPage = () => {
if (shouldRenderNormalInstances) modsRow.value.scrollLeft -= 170 modsRow.value.scrollLeft -= 170
else if (shouldRenderNews) newsRow.value.scrollLeft -= 170
} }
const handleRightPage = () => { const handleRightPage = () => {
if (shouldRenderNormalInstances) modsRow.value.scrollLeft += 170 modsRow.value.scrollLeft += 170
else if (shouldRenderNews) newsRow.value.scrollLeft += 170
} }
</script> </script>
<template> <template>
@@ -79,7 +63,7 @@ const handleRightPage = () => {
<ChevronRightIcon role="button" @click="handleRightPage" /> <ChevronRightIcon role="button" @click="handleRightPage" />
</div> </div>
</div> </div>
<section v-if="shouldRenderNormalInstances" ref="modsRow" class="instances"> <section ref="modsRow" class="instances">
<Instance <Instance
v-for="instance in props.instances" v-for="instance in props.instances"
:key="instance?.project_id || instance?.id" :key="instance?.project_id || instance?.id"
@@ -88,9 +72,6 @@ const handleRightPage = () => {
class="row-instance" class="row-instance"
/> />
</section> </section>
<section v-else-if="shouldRenderNews" ref="newsRow" class="news">
<News v-for="actualNews in props.news" :key="actualNews.id" :news="actualNews" />
</section>
</div> </div>
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
@@ -153,19 +134,6 @@ const handleRightPage = () => {
gap: 1rem; gap: 1rem;
} }
.news {
margin: auto;
width: 100%;
scroll-behavior: smooth;
overflow-x: scroll;
overflow-y: hidden;
&::-webkit-scrollbar {
width: 0px;
background: transparent;
}
}
.instances { .instances {
display: flex; display: flex;
flex-direction: row; flex-direction: row;

View File

@@ -1,25 +1,25 @@
<script setup> <script setup>
import { Button, Modal, XIcon, DownloadIcon } from 'omorphia' import { Button, Modal, XIcon, DownloadIcon } from 'omorphia'
import { useRouter } from 'vue-router'
import { install as pack_install } from '@/helpers/pack' import { install as pack_install } from '@/helpers/pack'
import { ref } from 'vue' import { ref } from 'vue'
const router = useRouter()
const version = ref('') const version = ref('')
const title = ref('')
const icon = ref('')
const confirmModal = ref(null) const confirmModal = ref(null)
defineExpose({ defineExpose({
show: (id) => { show: (id, projectTitle, projectIcon) => {
version.value = id version.value = id
title.value = projectTitle
icon.value = projectIcon
confirmModal.value.show() confirmModal.value.show()
}, },
}) })
async function install() { async function install() {
let id = await pack_install(version.value)
await router.push({ path: `/instance/${encodeURIComponent(id)}` })
confirmModal.value.hide() confirmModal.value.hide()
await pack_install(version.value, title.value, icon.value ? icon.value : null)
} }
</script> </script>

View File

@@ -74,13 +74,13 @@ const install = async (e) => {
) { ) {
try { try {
modLoading.value = true modLoading.value = true
await pack_install(versions[0].id, props.instance.title) await pack_install(versions[0].id, props.instance.title, props.instance.icon_url)
modLoading.value = false modLoading.value = false
} catch (err) { } catch (err) {
console.error(err) console.error(err)
modLoading.value = false modLoading.value = false
} }
} else confirmModal.value.show(versions[0].id) } else confirmModal.value.show(versions[0].id, props.instance.title, props.instance.icon_url)
} }
modLoading.value = false modLoading.value = false
@@ -119,7 +119,7 @@ const stop = async (e) => {
} }
await process_listener((e) => { await process_listener((e) => {
if (e.event === 'Finished' && e.uuid === uuid.value) playing.value = false if (e.event === 'finished' && e.uuid === uuid.value) playing.value = false
}) })
</script> </script>
@@ -147,10 +147,12 @@ await process_listener((e) => {
@mouseenter="checkProcess" @mouseenter="checkProcess"
> >
<Avatar <Avatar
size="lg" size="none"
:src=" :src="
props.instance.metadata props.instance.metadata
? convertFileSrc(props.instance.metadata?.icon) ? props.instance.metadata.icon && props.instance.metadata.icon.startsWith('http')
? props.instance.metadata.icon
: convertFileSrc(props.instance.metadata?.icon)
: props.instance.icon_url : props.instance.icon_url
" "
alt="Mod card" alt="Mod card"
@@ -315,8 +317,14 @@ await process_listener((e) => {
background: hsl(220, 11%, 11%) !important; background: hsl(220, 11%, 11%) !important;
} }
.mod-image { > .avatar {
border-radius: 1.5rem !important; --size: 100%;
width: 100% !important;
height: auto !important;
max-width: unset !important;
max-height: unset !important;
aspect-ratio: 1 / 1 !important;
} }
.project-info { .project-info {

View File

@@ -55,7 +55,7 @@ async function install(instance) {
await installMod(instance.path, version.id) await installMod(instance.path, version.id)
await installVersionDependencies(instance, version) await installVersionDependencies(instance, version)
instance.installed = true instance.installedMod = true
instance.installing = false instance.installing = false
} }
@@ -75,7 +75,7 @@ const filteredVersions = computed(() => {
filtered.map((profile) => { filtered.map((profile) => {
profile.installing = false profile.installing = false
profile.installed = checkInstalled(profile, project.value) profile.installedMod = checkInstalled(profile, project.value)
}) })
return filtered return filtered
@@ -149,10 +149,12 @@ const check_valid = computed(() => {
<Avatar :src="convertFileSrc(profile.metadata.icon)" class="profile-image" /> <Avatar :src="convertFileSrc(profile.metadata.icon)" class="profile-image" />
{{ profile.metadata.name }} {{ profile.metadata.name }}
</Button> </Button>
<Button :disabled="profile.installed || profile.installing" @click="install(profile)"> <Button :disabled="profile.installedMod || profile.installing" @click="install(profile)">
<DownloadIcon v-if="!profile.installed && !profile.installing" /> <DownloadIcon v-if="!profile.installedMod && !profile.installing" />
<CheckIcon v-else-if="profile.installed" /> <CheckIcon v-else-if="profile.installedMod" />
{{ profile.installing ? 'Installing...' : profile.installed ? 'Installed' : 'Install' }} {{
profile.installing ? 'Installing...' : profile.installedMod ? 'Installed' : 'Install'
}}
</Button> </Button>
</div> </div>
</div> </div>

View File

@@ -1,91 +0,0 @@
<script setup>
import { Card, ChevronRightIcon } from 'omorphia'
const props = defineProps({
news: {
type: Object,
default() {
return {}
},
},
})
</script>
<template>
<Card class="news-cta">
<img :src="props.news.img" alt="News Image" />
<div class="body">
<div class="headline">
<h2>{{ props.news.headline }}</h2>
<p>{{ props.news.blurb }}</p>
</div>
<div class="underline">
<p>{{ props.news.source }}</p>
<a href="#"><ChevronRightIcon /></a>
</div>
</div>
</Card>
</template>
<style lang="scss" scoped>
.news-cta {
display: flex;
justify-content: center;
padding: 0;
background: var(--color-raised-bg);
min-width: 24.125rem; /* from wireframe */
min-height: 8.5rem; /* from wireframe */
box-shadow: var(--shadow-raised-lg);
cursor: pointer;
transition: all ease-in-out 0.1s;
&:hover {
box-shadow: var(--shadow-floating);
filter: brightness(0.85);
}
img {
display: flex;
width: 8.4375rem; /* from wireframe */
height: 8.5rem; /* from wireframe */
border-radius: 0.9rem 0 0 0.9rem;
}
.body {
display: flex;
flex-direction: column;
width: 100%;
height: 8.5rem; /* from wireframe */
padding: 0.45rem;
.headline {
display: inherit;
flex-direction: inherit;
margin: 0.4rem 0;
width: 100%;
h2 {
font-size: 1rem;
text-transform: uppercase;
}
p {
font-size: 0.7rem;
}
}
.underline {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
margin-top: auto;
p {
font-size: 0.7rem;
}
a {
transition: all ease-in-out 0.2s;
width: 1.5rem;
color: var(--color-primary);
font-size: 1.3rem;
&:hover {
transform: translate(1px);
filter: brightness(150%);
}
}
}
}
}
</style>

View File

@@ -6,8 +6,8 @@
import { invoke } from '@tauri-apps/api/tauri' import { invoke } from '@tauri-apps/api/tauri'
// Installs pack from a version ID // Installs pack from a version ID
export async function install(versionId, packTitle) { export async function install(versionId, packTitle, packIcon) {
return await invoke('pack_install_version_id', { versionId, packTitle }) return await invoke('pack_install_version_id', { versionId, packTitle, packIcon })
} }
// Installs pack from a path // Installs pack from a path

View File

@@ -101,3 +101,8 @@ export async function run(path) {
export async function run_wait(path) { export async function run_wait(path) {
return await invoke('profile_run_wait', { path }) return await invoke('profile_run_wait', { path })
} }
// Edits a profile
export async function edit(path, editProfile) {
return await invoke('profile_edit', { path, editProfile })
}

View File

@@ -12,28 +12,28 @@ const breadcrumbs = useBreadcrumbs()
breadcrumbs.setRootContext({ name: 'Library', link: route.path }) breadcrumbs.setRootContext({ name: 'Library', link: route.path })
const profiles = await list() const profiles = await list()
const instances = shallowRef( const instances = shallowRef(Object.values(profiles))
Object.values(profiles).filter((prof) => !prof.metadata.linked_project_id)
)
const modpacks = shallowRef(
Object.values(profiles).filter((prof) => prof.metadata.linked_project_id)
)
loading_listener(async (profile) => { loading_listener(async (profile) => {
console.log(profile)
if (profile.event === 'loaded') { if (profile.event === 'loaded') {
const profiles = await list() const profiles = await list()
instances.value = Object.values(profiles).filter((prof) => !prof.metadata.linked_project_id) instances.value = Object.values(profiles)
modpacks.value = Object.values(profiles).filter((prof) => prof.metadata.linked_project_id)
} }
}) })
</script> </script>
<template> <template>
<div> <GridDisplay
<GridDisplay v-if="instances.length > 0" label="Instances" :instances="instances" /> v-if="instances.length > 0"
<GridDisplay v-if="modpacks.length > 0" label="Modpacks" :instances="modpacks" /> label="Instances"
</div> :instances="instances"
class="display"
/>
</template> </template>
<style lang="scss" scoped></style> <style lang="scss" scoped>
.display {
background-color: rgb(30, 31, 34);
min-height: 100%;
}
</style>

View File

@@ -2,7 +2,14 @@
<div class="instance-container"> <div class="instance-container">
<div class="side-cards"> <div class="side-cards">
<Card class="instance-card"> <Card class="instance-card">
<Avatar size="lg" :src="convertFileSrc(instance.metadata.icon)" /> <Avatar
size="lg"
:src="
instance.metadata.icon && instance.metadata.icon.startsWith('http')
? instance.metadata.icon
: convertFileSrc(instance.metadata?.icon)
"
/>
<div class="instance-info"> <div class="instance-info">
<h2 class="name">{{ instance.metadata.name }}</h2> <h2 class="name">{{ instance.metadata.name }}</h2>
<span class="metadata"> <span class="metadata">
@@ -136,7 +143,7 @@ const stopInstance = async () => {
} }
const unlisten = await process_listener((e) => { const unlisten = await process_listener((e) => {
if (e.event === 'Finished' && uuid.value === e.uuid) playing.value = false if (e.event === 'finished' && uuid.value === e.uuid) playing.value = false
}) })
onUnmounted(() => unlisten()) onUnmounted(() => unlisten())

View File

@@ -291,10 +291,9 @@ async function install(version) {
.map((value) => value.metadata) .map((value) => value.metadata)
.find((pack) => pack.linked_data?.project_id === data.value.id) .find((pack) => pack.linked_data?.project_id === data.value.id)
) { ) {
let id = await packInstall(queuedVersionData.id, data.value.title) await packInstall(queuedVersionData.id, data.value.title, data.value.icon_url)
await router.push({ path: `/instance/${encodeURIComponent(id)}` })
} else { } else {
confirmModal.value.show(queuedVersionData.id) confirmModal.value.show(queuedVersionData.id, data.value.title, data.value.icon_url)
} }
} else { } else {
if (instance.value) { if (instance.value) {

View File

@@ -6,6 +6,8 @@
use dunce::canonicalize; use dunce::canonicalize;
use theseus::jre::autodetect_java_globals; use theseus::jre::autodetect_java_globals;
use theseus::prelude::*; use theseus::prelude::*;
use theseus::profile::install;
use theseus::profile_create::profile_create;
use tokio::time::{sleep, Duration}; use tokio::time::{sleep, Duration};
use tracing_error::ErrorLayer; use tracing_error::ErrorLayer;
@@ -67,48 +69,51 @@ async fn main() -> theseus::Result<()> {
println!("Creating/adding profile."); println!("Creating/adding profile.");
// let name = "Example".to_string(); let name = "Example".to_string();
// let game_version = "1.19.2".to_string(); let game_version = "1.19.2".to_string();
// let modloader = ModLoader::Vanilla; let modloader = ModLoader::Vanilla;
// let loader_version = "stable".to_string(); let loader_version = "stable".to_string();
//
// let profile_path = profile_create( let profile_path = profile_create(
// name.clone(), name.clone(),
// game_version, game_version,
// modloader, modloader,
// Some(loader_version), Some(loader_version),
// None, None,
// None, None,
// None, None,
// ) None,
// .await?; )
.await?;
install(&profile_path).await.unwrap();
// let mut value = list().await?; // let mut value = list().await?;
// let profile_path = value.iter().next().map(|x| x.0).unwrap(); // let profile_path = value.iter().next().map(|x| x.0).unwrap();
// println!("Adding sodium"); println!("Adding sodium");
// let sodium_path = profile::add_project_from_version( let sodium_path = profile::add_project_from_version(
// &profile_path, &profile_path,
// "rAfhHfow".to_string(), "rAfhHfow".to_string(),
// )
// .await?;
//
// let mod_menu_path = profile::add_project_from_version(
// &profile_path,
// "gSoPJyVn".to_string(),
// )
// .await?;
//
// println!("Disabling sodium");
// profile::toggle_disable_project(&profile_path, &sodium_path).await?;
//
// profile::remove_project(&profile_path, &mod_menu_path).await?;
let profile_path = pack::install_pack_from_version_id(
"zroFQG1k".to_string(),
Some("Technical Electrical".to_string()),
) )
.await .await?;
.unwrap();
let mod_menu_path = profile::add_project_from_version(
&profile_path,
"gSoPJyVn".to_string(),
)
.await?;
println!("Disabling sodium");
profile::toggle_disable_project(&profile_path, &sodium_path).await?;
// profile::remove_project(&profile_path, &mod_menu_path).await?;
// let profile_path = pack::install_pack_from_version_id(
// "zroFQG1k".to_string(),
// Some("Technical Electrical".to_string()),
// )
// .await
// .unwrap();
// async closure for testing any desired edits // async closure for testing any desired edits
// (ie: changing the java runtime of an added profile) // (ie: changing the java runtime of an added profile)