Event handling (#75)

* working on amcros

* fleshed out draft

* added feature support

* finished loading

* Fixed issue with multiple data types in macro

* Working, and added more loading uses

* added window scopes

* clippy, fmt

* working other variants

* fmt; clippy

* prettier

* refactored emissions to use increment

* fixed deadlock

* doc changes

* clippy, prettier

* uuid change

* restructured events to util

* loading restructure

* merge fixes

* comments mistake

* better cfg tauri feature structuring

* added extra fields to some loading enum variants

* removed Option<>

* added pack + version labels

* doc change
This commit is contained in:
Wyatt Verchere
2023-04-16 10:12:37 -07:00
committed by GitHub
parent f8173d3b78
commit b120b5cfa8
22 changed files with 3519 additions and 102 deletions

View File

@@ -1,6 +1,7 @@
//! Theseus profile management interface
use crate::{
auth::{self, refresh},
event::{emit::emit_profile, ProfilePayloadType},
launcher::download,
state::MinecraftChild,
};
@@ -20,6 +21,17 @@ use tokio::{fs, process::Command, sync::RwLock};
pub async fn remove(path: &Path) -> crate::Result<()> {
let state = State::get().await?;
let mut profiles = state.profiles.write().await;
if let Some(profile) = profiles.0.get(path) {
emit_profile(
profile.uuid,
profile.path.clone(),
&profile.metadata.name,
ProfilePayloadType::Removed,
)
.await?;
}
profiles.remove(path).await?;
Ok(())
@@ -46,7 +58,17 @@ where
let mut profiles = state.profiles.write().await;
match profiles.0.get_mut(path) {
Some(ref mut profile) => action(profile).await,
Some(ref mut profile) => {
emit_profile(
profile.uuid,
profile.path.clone(),
&profile.metadata.name,
ProfilePayloadType::Edited,
)
.await?;
action(profile).await
}
None => Err(crate::ErrorKind::UnmanagedProfileError(
path.display().to_string(),
)
@@ -219,7 +241,7 @@ pub async fn run_credentials(
.minecraft
.versions
.iter()
.find(|it| it.id == profile.metadata.game_version.as_ref())
.find(|it| it.id == profile.metadata.game_version)
.ok_or_else(|| {
crate::ErrorKind::LauncherError(format!(
"Invalid or unknown Minecraft version: {}",
@@ -325,6 +347,7 @@ pub async fn run_credentials(
&memory,
&resolution,
credentials,
&profile,
)
.await?;
@@ -335,8 +358,9 @@ pub async fn run_credentials(
"Process failed to stay open.".to_string(),
)
})?;
let mchild_arc =
state_children.insert_process(pid, path.to_path_buf(), mc_process);
let mchild_arc = state_children
.insert_process(pid, path.to_path_buf(), mc_process)
.await?;
Ok(mchild_arc)
}