2023-04-05 10:07:59 -07:00
|
|
|
//! Theseus process management interface
|
|
|
|
|
|
2024-08-16 23:20:11 -07:00
|
|
|
use crate::state::ProcessMetadata;
|
2023-04-05 10:07:59 -07:00
|
|
|
pub use crate::{
|
|
|
|
|
State,
|
2025-05-02 04:51:17 -05:00
|
|
|
state::{Hooks, MemorySettings, Profile, Settings, WindowSize},
|
2023-04-05 10:07:59 -07:00
|
|
|
};
|
2024-08-16 23:20:11 -07:00
|
|
|
use uuid::Uuid;
|
2023-04-05 10:07:59 -07:00
|
|
|
|
|
|
|
|
// Gets the Profile paths of each *running* stored process in the state
|
|
|
|
|
#[tracing::instrument]
|
2024-08-16 23:20:11 -07:00
|
|
|
pub async fn get_all() -> crate::Result<Vec<ProcessMetadata>> {
|
2023-04-05 10:07:59 -07:00
|
|
|
let state = State::get().await?;
|
2024-08-16 23:20:11 -07:00
|
|
|
let processes = state.process_manager.get_all();
|
2024-07-24 11:03:19 -07:00
|
|
|
Ok(processes)
|
2023-04-05 10:07:59 -07:00
|
|
|
}
|
|
|
|
|
|
2023-04-17 12:40:27 -07:00
|
|
|
// Gets the UUID of each stored process in the state by profile path
|
2023-04-05 10:07:59 -07:00
|
|
|
#[tracing::instrument]
|
2024-07-24 11:03:19 -07:00
|
|
|
pub async fn get_by_profile_path(
|
|
|
|
|
profile_path: &str,
|
2024-08-16 23:20:11 -07:00
|
|
|
) -> crate::Result<Vec<ProcessMetadata>> {
|
2023-04-05 10:07:59 -07:00
|
|
|
let state = State::get().await?;
|
2024-08-16 23:20:11 -07:00
|
|
|
let processes = state
|
|
|
|
|
.process_manager
|
|
|
|
|
.get_all()
|
|
|
|
|
.into_iter()
|
|
|
|
|
.filter(|x| x.profile_path == profile_path)
|
|
|
|
|
.collect();
|
2024-07-24 11:03:19 -07:00
|
|
|
Ok(processes)
|
2023-04-05 10:07:59 -07:00
|
|
|
}
|
|
|
|
|
|
2023-04-17 12:40:27 -07:00
|
|
|
// Kill a child process stored in the state by UUID, as a string
|
2023-04-05 10:07:59 -07:00
|
|
|
#[tracing::instrument]
|
2024-08-16 23:20:11 -07:00
|
|
|
pub async fn kill(uuid: Uuid) -> crate::Result<()> {
|
2023-04-05 10:07:59 -07:00
|
|
|
let state = State::get().await?;
|
2024-08-16 23:20:11 -07:00
|
|
|
state.process_manager.kill(uuid).await?;
|
2024-07-24 11:03:19 -07:00
|
|
|
|
2024-08-16 23:20:11 -07:00
|
|
|
Ok(())
|
2023-04-05 10:07:59 -07:00
|
|
|
}
|
|
|
|
|
|
2023-04-17 12:40:27 -07:00
|
|
|
// Wait for a child process stored in the state by UUID
|
2023-04-05 10:07:59 -07:00
|
|
|
#[tracing::instrument]
|
2024-08-16 23:20:11 -07:00
|
|
|
pub async fn wait_for(uuid: Uuid) -> crate::Result<()> {
|
2023-04-05 10:07:59 -07:00
|
|
|
let state = State::get().await?;
|
2024-08-16 23:20:11 -07:00
|
|
|
state.process_manager.wait_for(uuid).await?;
|
2024-07-24 11:03:19 -07:00
|
|
|
|
2024-08-16 23:20:11 -07:00
|
|
|
Ok(())
|
2023-04-05 10:07:59 -07:00
|
|
|
}
|