From d53319bab36532b38ec901458197712c4df4528b Mon Sep 17 00:00:00 2001 From: SquitchYT Date: Tue, 9 Jan 2024 23:28:20 +0100 Subject: [PATCH] :bug: Fix compilation on Linux --- src-tauri/src/pty/pty.rs | 10 ++++++-- src-tauri/src/pty/utils.rs | 52 +++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src-tauri/src/pty/pty.rs b/src-tauri/src/pty/pty.rs index 366fd21..95fb0cb 100644 --- a/src-tauri/src/pty/pty.rs +++ b/src-tauri/src/pty/pty.rs @@ -4,16 +4,19 @@ use std::sync::{mpsc, Arc}; use std::time::Duration; use portable_pty::{native_pty_system, Child, CommandBuilder, MasterPty, PtySize}; -use regex::Captures; use tokio::sync::Mutex; use std::sync::atomic::{AtomicBool, Ordering}; use crate::common::error::PtyError; -use crate::pty::utils; + #[cfg(target_os = "windows")] use regex::Regex; +#[cfg(target_os = "windows")] +use crate::pty::utils; +#[cfg(target_os = "windows")] +use regex::Captures; pub struct Pty { writer: Box, @@ -95,6 +98,9 @@ impl Pty { let paused = Arc::from(AtomicBool::new(false)); let paused_cloned = paused.clone(); + #[cfg(target_family = "unix")] + let cloned_master = master.clone(); + #[cfg(target_os = "windows")] let shell_pid = child.lock().await.process_id().ok_or(PtyError::Creation("PID not found".to_owned()))?; std::thread::spawn(move || { diff --git a/src-tauri/src/pty/utils.rs b/src-tauri/src/pty/utils.rs index c89378d..4135ffb 100644 --- a/src-tauri/src/pty/utils.rs +++ b/src-tauri/src/pty/utils.rs @@ -1,5 +1,3 @@ -use std::{ffi::OsString, os::windows::ffi::OsStringExt}; - #[cfg(target_os = "windows")] pub fn get_leader_pid(shell_pid: u32) -> u32 { use std::mem::size_of; @@ -30,35 +28,37 @@ pub fn get_leader_pid(shell_pid: u32) -> u32 { leader_pid } +#[cfg(target_os = "windows")] pub fn get_process_title(pid: u32) -> Option { - #[cfg(target_os = "windows")] - { - use windows::Win32::{ - Foundation::CloseHandle, - System::Threading::{PROCESS_QUERY_INFORMATION, PROCESS_VM_READ}, - }; + use std::{ffi::OsString, os::windows::ffi::OsStringExt}; + use windows::Win32::{ + Foundation::CloseHandle, + System::Threading::{PROCESS_QUERY_INFORMATION, PROCESS_VM_READ}, + }; - unsafe { - windows::Win32::System::Threading::OpenProcess( - PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, - false, - pid, - ) - } - .map_or(None, |handle| { - let mut path = [0; 4096]; - let path_len = unsafe { - windows::Win32::System::ProcessStatus::GetModuleFileNameExW(handle, None, &mut path) - }; + unsafe { + windows::Win32::System::Threading::OpenProcess( + PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, + false, + pid, + ) + } + .map_or(None, |handle| { + let mut path = [0; 4096]; + let path_len = unsafe { + windows::Win32::System::ProcessStatus::GetModuleFileNameExW(handle, None, &mut path) + }; - unsafe { CloseHandle(handle).ok() }; + unsafe { CloseHandle(handle).ok() }; - std::path::PathBuf::from(OsString::from_wide(&path[..path_len as usize])) - .file_name() - .and_then(|filename| filename.to_os_string().into_string().ok()) - }) - } + std::path::PathBuf::from(OsString::from_wide(&path[..path_len as usize])) + .file_name() + .and_then(|filename| filename.to_os_string().into_string().ok()) + }) +} +#[cfg(target_family = "unix")] +pub fn get_process_title(pid: i32) -> Option { #[cfg(target_family = "unix")] { std::fs::read_to_string(format!("/proc/{pid}/comm")).map_or(