2023-04-05 10:07:59 -07:00
|
|
|
//! Theseus process management interface
|
|
|
|
|
|
2024-07-24 11:03:19 -07:00
|
|
|
use crate::state::Process;
|
2023-04-05 10:07:59 -07:00
|
|
|
pub use crate::{
|
2024-07-24 11:03:19 -07:00
|
|
|
state::{Hooks, MemorySettings, Profile, Settings, WindowSize},
|
2023-04-05 10:07:59 -07:00
|
|
|
State,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Gets the Profile paths of each *running* stored process in the state
|
|
|
|
|
#[tracing::instrument]
|
2024-07-24 11:03:19 -07:00
|
|
|
pub async fn get_all() -> crate::Result<Vec<Process>> {
|
2023-04-05 10:07:59 -07:00
|
|
|
let state = State::get().await?;
|
2024-07-24 11:03:19 -07:00
|
|
|
let processes = Process::get_all(&state.pool).await?;
|
|
|
|
|
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,
|
|
|
|
|
) -> crate::Result<Vec<Process>> {
|
2023-04-05 10:07:59 -07:00
|
|
|
let state = State::get().await?;
|
2024-07-24 11:03:19 -07:00
|
|
|
let processes =
|
|
|
|
|
Process::get_from_profile(profile_path, &state.pool).await?;
|
|
|
|
|
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-07-24 11:03:19 -07:00
|
|
|
pub async fn kill(pid: i32) -> crate::Result<()> {
|
2023-04-05 10:07:59 -07:00
|
|
|
let state = State::get().await?;
|
2024-07-24 11:03:19 -07:00
|
|
|
let process = Process::get(pid, &state.pool).await?;
|
|
|
|
|
|
|
|
|
|
if let Some(process) = process {
|
|
|
|
|
process.kill().await?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
2023-04-05 10:07:59 -07:00
|
|
|
} else {
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-07-24 11:03:19 -07:00
|
|
|
pub async fn wait_for(pid: i32) -> crate::Result<()> {
|
2023-04-05 10:07:59 -07:00
|
|
|
let state = State::get().await?;
|
2024-07-24 11:03:19 -07:00
|
|
|
let process = Process::get(pid, &state.pool).await?;
|
|
|
|
|
|
|
|
|
|
if let Some(process) = process {
|
|
|
|
|
process.wait_for().await?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
2023-04-05 10:07:59 -07:00
|
|
|
} else {
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|