Skip to content

Commit

Permalink
UUID implements copy so borrows are unnecessary. (#1154)
Browse files Browse the repository at this point in the history
  • Loading branch information
CoreyShupe authored May 9, 2024
1 parent e1a7480 commit 5300746
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions theseus/src/api/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ pub use crate::{

// Gets whether a child process stored in the state by UUID has finished
#[tracing::instrument]
pub async fn has_finished_by_uuid(uuid: &Uuid) -> crate::Result<bool> {
pub async fn has_finished_by_uuid(uuid: Uuid) -> crate::Result<bool> {
Ok(get_exit_status_by_uuid(uuid).await?.is_some())
}

// Gets the exit status of a child process stored in the state by UUID
#[tracing::instrument]
pub async fn get_exit_status_by_uuid(
uuid: &Uuid,
uuid: Uuid,
) -> crate::Result<Option<i32>> {
let state = State::get().await?;
let children = state.children.read().await;
Expand Down Expand Up @@ -71,7 +71,7 @@ pub async fn get_uuids_by_profile_path(

// Kill a child process stored in the state by UUID, as a string
#[tracing::instrument]
pub async fn kill_by_uuid(uuid: &Uuid) -> crate::Result<()> {
pub async fn kill_by_uuid(uuid: Uuid) -> crate::Result<()> {
let state = State::get().await?;
let children = state.children.read().await;
if let Some(mchild) = children.get(uuid) {
Expand All @@ -85,7 +85,7 @@ pub async fn kill_by_uuid(uuid: &Uuid) -> crate::Result<()> {

// Wait for a child process stored in the state by UUID
#[tracing::instrument]
pub async fn wait_for_by_uuid(uuid: &Uuid) -> crate::Result<()> {
pub async fn wait_for_by_uuid(uuid: Uuid) -> crate::Result<()> {
let state = State::get().await?;
let children = state.children.read().await;
// No error returned for already killed process
Expand Down
6 changes: 3 additions & 3 deletions theseus/src/launcher/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub fn get_minecraft_arguments(
arg,
&credentials.access_token,
&credentials.username,
&credentials.id,
credentials.id,
version,
asset_index_name,
game_directory,
Expand All @@ -237,7 +237,7 @@ pub fn get_minecraft_arguments(
&x.replace(' ', TEMPORARY_REPLACE_CHAR),
&credentials.access_token,
&credentials.username,
&credentials.id,
credentials.id,
version,
asset_index_name,
game_directory,
Expand All @@ -257,7 +257,7 @@ fn parse_minecraft_argument(
argument: &str,
access_token: &str,
username: &str,
uuid: &Uuid,
uuid: Uuid,
version: &str,
asset_index_name: &str,
game_directory: &Path,
Expand Down
14 changes: 7 additions & 7 deletions theseus/src/state/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,8 @@ impl Children {
}

// Returns a ref to the child
pub fn get(&self, uuid: &Uuid) -> Option<Arc<RwLock<MinecraftChild>>> {
self.0.get(uuid).cloned()
pub fn get(&self, uuid: Uuid) -> Option<Arc<RwLock<MinecraftChild>>> {
self.0.get(&uuid).cloned()
}

// Gets all PID keys
Expand All @@ -615,7 +615,7 @@ impl Children {

// Get exit status of a child by PID
// Returns None if the child is still running
pub async fn exit_status(&self, uuid: &Uuid) -> crate::Result<Option<i32>> {
pub async fn exit_status(&self, uuid: Uuid) -> crate::Result<Option<i32>> {
if let Some(child) = self.get(uuid) {
let child = child.write().await;
let status = child.current_child.write().await.try_wait().await?;
Expand All @@ -629,7 +629,7 @@ impl Children {
pub async fn running_keys(&self) -> crate::Result<Vec<Uuid>> {
let mut keys = Vec::new();
for key in self.keys() {
if let Some(child) = self.get(&key) {
if let Some(child) = self.get(key) {
let child = child.clone();
let child = child.write().await;
if child
Expand All @@ -655,7 +655,7 @@ impl Children {
let running_keys = self.running_keys().await?;
let mut keys = Vec::new();
for key in running_keys {
if let Some(child) = self.get(&key) {
if let Some(child) = self.get(key) {
let child = child.clone();
let child = child.read().await;
if child.profile_relative_path == profile_path {
Expand All @@ -672,7 +672,7 @@ impl Children {
) -> crate::Result<Vec<ProfilePathId>> {
let mut profiles = Vec::new();
for key in self.keys() {
if let Some(child) = self.get(&key) {
if let Some(child) = self.get(key) {
let child = child.clone();
let child = child.write().await;
if child
Expand All @@ -695,7 +695,7 @@ impl Children {
pub async fn running_profiles(&self) -> crate::Result<Vec<Profile>> {
let mut profiles = Vec::new();
for key in self.keys() {
if let Some(child) = self.get(&key) {
if let Some(child) = self.get(key) {
let child = child.clone();
let child = child.write().await;
if child
Expand Down
8 changes: 4 additions & 4 deletions theseus_gui/src-tauri/src/api/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
// Checks if a process has finished by process UUID
#[tauri::command]
pub async fn process_has_finished_by_uuid(uuid: Uuid) -> Result<bool> {
Ok(process::has_finished_by_uuid(&uuid).await?)
Ok(process::has_finished_by_uuid(uuid).await?)
}

// Gets process exit status by process UUID
#[tauri::command]
pub async fn process_get_exit_status_by_uuid(
uuid: Uuid,
) -> Result<Option<i32>> {
Ok(process::get_exit_status_by_uuid(&uuid).await?)
Ok(process::get_exit_status_by_uuid(uuid).await?)
}

// Gets all process UUIDs
Expand Down Expand Up @@ -68,11 +68,11 @@ pub async fn process_get_all_running_profiles() -> Result<Vec<Profile>> {
// Kill a process by process UUID
#[tauri::command]
pub async fn process_kill_by_uuid(uuid: Uuid) -> Result<()> {
Ok(process::kill_by_uuid(&uuid).await?)
Ok(process::kill_by_uuid(uuid).await?)
}

// Wait for a process to finish by process UUID
#[tauri::command]
pub async fn process_wait_for_by_uuid(uuid: Uuid) -> Result<()> {
Ok(process::wait_for_by_uuid(&uuid).await?)
Ok(process::wait_for_by_uuid(uuid).await?)
}

0 comments on commit 5300746

Please sign in to comment.