#![cfg_attr(windows, windows_subsystem = "windows")]
#[cfg(windows)]
use std::ffi::OsStr;
#[cfg(windows)]
use std::os::windows::ffi::OsStrExt;
#[cfg(windows)]
use std::ptr::null_mut;
#[cfg(windows)]
fn main() {
let exe_path = std::env::current_exe().unwrap_or_default();
let exe_dir = exe_path.parent().unwrap_or(std::path::Path::new("."));
let tray_path = exe_dir.join("ruvector-memopt-tray.exe");
let wide_path: Vec<u16> = OsStr::new(&tray_path)
.encode_wide()
.chain(std::iter::once(0))
.collect();
unsafe {
use windows::Win32::System::Threading::*;
use windows::Win32::Foundation::*;
use windows::core::{PCWSTR, PWSTR};
let mut startup_info: STARTUPINFOW = std::mem::zeroed();
startup_info.cb = std::mem::size_of::<STARTUPINFOW>() as u32;
startup_info.dwFlags = STARTF_USESHOWWINDOW;
startup_info.wShowWindow = 0;
let mut process_info: PROCESS_INFORMATION = std::mem::zeroed();
let result = CreateProcessW(
PCWSTR(wide_path.as_ptr()),
PWSTR(null_mut()),
None,
None,
false,
CREATE_NO_WINDOW,
None,
None,
&startup_info,
&mut process_info,
);
if result.is_ok() {
let _ = CloseHandle(process_info.hProcess);
let _ = CloseHandle(process_info.hThread);
}
}
}
#[cfg(not(windows))]
fn main() {
eprintln!("Windows launcher only runs on Windows");
}