feat: init macos linux support

This commit is contained in:
2024-06-16 10:36:32 +08:00
parent 5cf8d5a0a0
commit cd812cac66
46 changed files with 2103 additions and 14 deletions

View File

@ -19,8 +19,11 @@ once_cell = "1.19"
reqwest = { version = "0.12", features = ["rustls-tls-webpki-roots", "cookies", "gzip", "json", "stream"] }
hickory-resolver = { version = "0.24" }
anyhow = "1.0"
win32job = "2"
scopeguard = "1.2"
notify-rust = "4"
windows = { version = "0.57.0", features = ["Win32_UI_WindowsAndMessaging"] }
asar = "0.3.0"
[target.'cfg(windows)'.dependencies]
windows = { version = "0.57.0", features = ["Win32_UI_WindowsAndMessaging"] }
win32job = "2"

View File

@ -48,17 +48,23 @@ pub async fn start(
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.kill_on_drop(true);
#[cfg(target_os = "windows")]
command.creation_flags(0x08000000);
#[cfg(target_os = "windows")]
let job = win32job::Job::create().unwrap();
#[cfg(target_os = "windows")]
let mut info = job.query_extended_limit_info().unwrap();
#[cfg(target_os = "windows")]
info.limit_kill_on_job_close();
#[cfg(target_os = "windows")]
job.set_extended_limit_info(&mut info).unwrap();
#[cfg(target_os = "windows")]
let job_arc = Arc::from(job);
if let Ok(mut child) = command.spawn() {
#[cfg(target_os = "windows")]
{
let raw_handle = child.raw_handle();
if raw_handle.is_some() {
@ -67,7 +73,6 @@ pub async fn start(
.unwrap();
}
}
let stdin = child
.stdin
.take()
@ -142,6 +147,7 @@ pub async fn start(
}
}
pub async fn write(rs_pid: &u32, data: String) {
let mut map = RS_PROCESS_MAP.lock().await;
let process = map.get_mut(rs_pid).unwrap();

View File

@ -1,7 +1,4 @@
use notify_rust::Notification;
use windows::core::{HSTRING, PCWSTR};
use windows::Win32::Foundation::HWND;
use windows::Win32::UI::WindowsAndMessaging;
pub fn send_notify(
summary: Option<String>,
@ -19,14 +16,22 @@ pub fn send_notify(
if let Some(app_name) = app_name {
n.appname(&app_name);
}
#[cfg(target_os = "windows")]
if let Some(app_id) = app_id {
n.app_id(&app_id);
}
#[cfg(not(target_os = "windows"))]
println!("send_notify (unix) appid: {:?}", app_id);
n.show()?;
Ok(())
}
#[cfg(target_os = "windows")]
pub fn set_foreground_window(window_name: &str) -> anyhow::Result<bool> {
use windows::core::{HSTRING, PCWSTR};
use windows::Win32::Foundation::HWND;
use windows::Win32::UI::WindowsAndMessaging;
let window_name_p: PCWSTR = PCWSTR(HSTRING::from(window_name).as_ptr());
let h = unsafe { WindowsAndMessaging::FindWindowW(PCWSTR::null(), window_name_p) };
if h == HWND::default() {
@ -39,3 +44,9 @@ pub fn set_foreground_window(window_name: &str) -> anyhow::Result<bool> {
let r = unsafe { WindowsAndMessaging::SetForegroundWindow(h) };
Ok(r.as_bool())
}
#[cfg(not(target_os = "windows"))]
pub fn set_foreground_window(window_name: &str) -> anyhow::Result<bool> {
println!("set_foreground_window (unix): {}", window_name);
return Ok(false);
}