You've already forked AstralRinth
forked from xxxOFFxxx/AstralRinth
* Initial bug fixes * fix compile error on non-mac * Fix even more bugs * Fix more * fix more * fix build * fix build * Search fixes * Fix small instance ui * working basic * fix javaw issue * removed zip * working functions * merge fixes * fixed loadintg bar bug * menu fix * wait for settings to sync * safety expanded and for loading bars * swtiching to windows * minimize * default landing page * test link registry * url redirection * fix formatting * .mrpack windows * working mrpack reader * changed to one layer deep * working .mrpack + command handling for both opening and existing process * forge version numbers * working mac opening mrpack * reverted changes * prettier/fmt * missed debug statement * improvements + refactoring * renamed things to fit plugin * fixed bugs * removed println * overrides dont include mrpack * merge * fixes * fixes * fixed deletion * merge errors * force sync before export * removed testing * missed line * removed console log * mac error reverted * incoreclty named helper * additional fixes * added removed merges * fixed mislabled invokes * mac * added to new register method * comments, cleanup * mac clippy change * review changes * minor changes * moved create pack * removed playground compilation bug * fixed linux bug; other add ons * fixed review commets * cicd fix * mistaken import for prod * cicd fix --------- Co-authored-by: Jai A <jaiagr+gpg@pm.me>
70 lines
1.9 KiB
Rust
70 lines
1.9 KiB
Rust
use uuid::Uuid;
|
|
|
|
use crate::State;
|
|
|
|
// We implement a store for safe loading bars such that we can wait for them to complete
|
|
// We create this store separately from the loading bars themselves, because this may be extended as needed
|
|
pub struct SafeProcesses {
|
|
pub loading_bars: Vec<Uuid>,
|
|
}
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
pub enum ProcessType {
|
|
LoadingBar,
|
|
// Potentially other types of processes (ie: IO operations?)
|
|
}
|
|
|
|
impl SafeProcesses {
|
|
// init
|
|
pub fn new() -> Self {
|
|
Self {
|
|
loading_bars: Vec::new(),
|
|
}
|
|
}
|
|
|
|
// Adds a new running safe process to the list by uuid
|
|
pub async fn add_uuid(
|
|
r#type: ProcessType,
|
|
uuid: Uuid,
|
|
) -> crate::Result<Uuid> {
|
|
let state = State::get().await?;
|
|
let mut safe_processes = state.safety_processes.write().await;
|
|
match r#type {
|
|
ProcessType::LoadingBar => {
|
|
safe_processes.loading_bars.push(uuid);
|
|
}
|
|
}
|
|
Ok(uuid)
|
|
}
|
|
|
|
// Mark a safe process as finishing
|
|
pub async fn complete(
|
|
r#type: ProcessType,
|
|
uuid: Uuid,
|
|
) -> crate::Result<()> {
|
|
let state = State::get().await?;
|
|
let mut safe_processes = state.safety_processes.write().await;
|
|
|
|
match r#type {
|
|
ProcessType::LoadingBar => {
|
|
safe_processes.loading_bars.retain(|x| *x != uuid);
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
// Check if there are any pending safe processes of a given type
|
|
pub async fn is_complete(r#type: ProcessType) -> crate::Result<bool> {
|
|
let state = State::get().await?;
|
|
let safe_processes = state.safety_processes.read().await;
|
|
match r#type {
|
|
ProcessType::LoadingBar => {
|
|
if safe_processes.loading_bars.is_empty() {
|
|
return Ok(true);
|
|
}
|
|
}
|
|
}
|
|
Ok(false)
|
|
}
|
|
}
|