Skip to content

Commit

Permalink
fix(fig_desktop): exit code not propagated by main (#409)
Browse files Browse the repository at this point in the history
This fixes an issues that was accidently introduced in 524eec6. To prevent this again I have marked the functions in the file as `#[must_use]`.
  • Loading branch information
grant0417 authored Jan 10, 2025
1 parent 524eec6 commit 921c861
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions crates/fig_desktop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ async fn main() -> ExitCode {
if !cli.allow_multiple {
match get_current_pid() {
Ok(current_pid) => {
allow_multiple_running_check(current_pid, cli.kill_old, page.clone()).await;
if let Some(exit_code) = allow_multiple_running_check(current_pid, cli.kill_old, page.clone()).await {
return exit_code;
}
},
Err(err) => warn!(%err, "Failed to get pid"),
}
Expand Down Expand Up @@ -226,6 +228,7 @@ fn parse_url_page(url: Option<&str>) -> Result<Option<String>, ExitCode> {
}

#[cfg(target_os = "linux")]
#[must_use]
async fn allow_multiple_running_check(
current_pid: sysinfo::Pid,
kill_old: bool,
Expand Down Expand Up @@ -287,6 +290,7 @@ async fn allow_multiple_running_check(
}

#[cfg(target_os = "macos")]
#[must_use]
async fn allow_multiple_running_check(
current_pid: sysinfo::Pid,
kill_old: bool,
Expand All @@ -297,14 +301,7 @@ async fn allow_multiple_running_check(
let app_process_name = OsString::from(APP_PROCESS_NAME);
let system = System::new_with_specifics(RefreshKind::new().with_processes(ProcessRefreshKind::new()));
let processes = system.processes_by_name(&app_process_name);

cfg_if::cfg_if! {
if #[cfg(unix)] {
let current_user_id = Some(nix::unistd::getuid().as_raw());
} else {
let current_user_id = None;
}
};
let current_uid = nix::unistd::getuid().as_raw();

for process in processes {
let pid = process.pid();
Expand Down Expand Up @@ -347,12 +344,8 @@ async fn allow_multiple_running_check(
}
};

match (process.user_id().map(|uid| uid as &u32), current_user_id.as_ref()) {
(Some(uid), Some(current_uid)) if uid == current_uid => {
on_match.await;
return Some(ExitCode::SUCCESS);
},
(_, None) => {
match process.user_id().map(|uid| uid as &u32) {
Some(&uid) if uid == current_uid => {
on_match.await;
return Some(ExitCode::SUCCESS);
},
Expand Down

0 comments on commit 921c861

Please sign in to comment.