diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index ba38dbbf..250ba78d 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -22,6 +22,8 @@ pub async fn inject( omp_file }; + crate::ipc::ensure_listening(); + match injector::run_samp( name, ip, diff --git a/src-tauri/src/ipc.rs b/src-tauri/src/ipc.rs index 7507abf0..6938e87d 100644 --- a/src-tauri/src/ipc.rs +++ b/src-tauri/src/ipc.rs @@ -2,7 +2,8 @@ use once_cell::sync::Lazy; use std::collections::HashMap; use std::io::BufRead; use std::net::{TcpListener, TcpStream}; -use std::sync::{Arc, Mutex}; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::{Arc, Mutex, OnceLock}; use std::thread; use tauri::{AppHandle, Manager, WindowBuilder, WindowUrl}; @@ -12,6 +13,25 @@ type SharedStreams = Arc>>; pub static GAME_STREAMS: Lazy = Lazy::new(|| Arc::new(Mutex::new(HashMap::new()))); +static IPC_HANDLE: OnceLock = OnceLock::new(); +static IPC_STARTED: AtomicBool = AtomicBool::new(false); + +pub fn init_ipc(app_handle: AppHandle) { + let _ = IPC_HANDLE.set(app_handle); +} + +pub fn ensure_listening() { + if IPC_STARTED + .compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst) + .is_err() + { + return; + } + if let Some(handle) = IPC_HANDLE.get() { + listen_for_ipc(handle.clone()); + } +} + fn create_overlay_window( app: &tauri::AppHandle, label: &str, diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index def58481..59ffd831 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -222,7 +222,7 @@ fn setup_tauri_app(app: &mut tauri::App) -> std::result::Result<(), Box