diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..04fbbec --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,4 @@ + +[workspace] +members = ["frontend/src-tauri"] +resolver = "3" \ No newline at end of file diff --git a/frontend/src-tauri/Cargo.toml b/frontend/src-tauri/Cargo.toml index 39137b9..8435292 100644 --- a/frontend/src-tauri/Cargo.toml +++ b/frontend/src-tauri/Cargo.toml @@ -21,7 +21,9 @@ image = "0.24" # Ensure "consoleapi" is in this features list winapi = { version = "0.3.9", features = ["winuser", "libloaderapi", "wingdi", "errhandlingapi", "consoleapi"] } once_cell = "1.19.0" -steamworks = "0.10.0" +steamworks = "0.11.0" +parking_lot = "0.12.3" + [features] # this feature is used for production builds or when `devPath` points to the filesystem # DO NOT REMOVE!! diff --git a/frontend/src-tauri/build.rs b/frontend/src-tauri/build.rs index 795b9b7..d9806c7 100644 --- a/frontend/src-tauri/build.rs +++ b/frontend/src-tauri/build.rs @@ -1,3 +1,42 @@ -fn main() { - tauri_build::build() +use std::{env, fs::{self, read_dir}, path::{Path, PathBuf}}; + +fn main() -> Result<(), Box> { + tauri_build::build(); + + let out_dir = PathBuf::from(env::var("OUT_DIR")?); + + let profile_target_dir = out_dir + .ancestors() + .nth(3) + .ok_or("Failed to determine profile target directory from OUT_DIR")?; + + println!( + "cargo:info=Build script running for target OS: {}", + env::var("CARGO_CFG_TARGET_OS").unwrap_or_default() + ); + println!( + "cargo:info=Final libraries will be copied to: {}", + profile_target_dir.display() + ); + + // --- Define libraries and their source locations based on OS --- + let target_os = env::var("CARGO_CFG_TARGET_OS")?; + + let source_subdir = if target_os == "windows" { + "lib/win64" + } else if target_os == "linux" { + "lib/linux64" + } else if target_os == "macos" { + "lib/osx" + } else { + return Err("Unsupported target".into()); + }; + + for f in read_dir(source_subdir)? { + let f = f?; + println!("cargo:rerun-if-changed={}", f.path().display()); + fs::copy(f.path(), profile_target_dir.join(f.file_name()))?; + } + + Ok(()) } diff --git a/frontend/src-tauri/lib/linux32/libsteam_api.so b/frontend/src-tauri/lib/linux32/libsteam_api.so new file mode 100644 index 0000000..2d9e8a7 Binary files /dev/null and b/frontend/src-tauri/lib/linux32/libsteam_api.so differ diff --git a/frontend/src-tauri/lib/linux64/libsteam_api.so b/frontend/src-tauri/lib/linux64/libsteam_api.so new file mode 100644 index 0000000..8783570 Binary files /dev/null and b/frontend/src-tauri/lib/linux64/libsteam_api.so differ diff --git a/frontend/src-tauri/lib/osx/libsteam_api.dylib b/frontend/src-tauri/lib/osx/libsteam_api.dylib new file mode 100644 index 0000000..c493b2b Binary files /dev/null and b/frontend/src-tauri/lib/osx/libsteam_api.dylib differ diff --git a/frontend/src-tauri/lib/steam_api.dll b/frontend/src-tauri/lib/steam_api.dll new file mode 100644 index 0000000..2372ab1 Binary files /dev/null and b/frontend/src-tauri/lib/steam_api.dll differ diff --git a/frontend/src-tauri/lib/steam_api.lib b/frontend/src-tauri/lib/steam_api.lib new file mode 100644 index 0000000..4efd430 Binary files /dev/null and b/frontend/src-tauri/lib/steam_api.lib differ diff --git a/frontend/src-tauri/lib/win64/steam_api64.dll b/frontend/src-tauri/lib/win64/steam_api64.dll new file mode 100644 index 0000000..6d11825 Binary files /dev/null and b/frontend/src-tauri/lib/win64/steam_api64.dll differ diff --git a/frontend/src-tauri/lib/win64/steam_api64.lib b/frontend/src-tauri/lib/win64/steam_api64.lib new file mode 100644 index 0000000..1f1c623 Binary files /dev/null and b/frontend/src-tauri/lib/win64/steam_api64.lib differ diff --git a/frontend/src-tauri/src/lib.rs b/frontend/src-tauri/src/lib.rs index 8ee9422..39538ed 100644 --- a/frontend/src-tauri/src/lib.rs +++ b/frontend/src-tauri/src/lib.rs @@ -1,11 +1,18 @@ -use std::sync::Mutex; -use serde::{Serialize, Deserialize}; -use tauri::{Manager, AppHandle, CustomMenuItem, SystemTray, SystemTrayMenu, SystemTrayMenuItem, SystemTrayEvent, WindowEvent}; -use std::path::{Path, PathBuf}; +use integrations::steam::Steam; +use parking_lot::Mutex; +use serde::{Deserialize, Serialize}; use std::env; +use std::path::{Path, PathBuf}; +use std::sync::LazyLock; +use tauri::{ + AppHandle, CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, + SystemTrayMenuItem, WindowEvent, +}; -mod platform; mod integrations; +mod platform; + +static STEAM: LazyLock> = LazyLock::new(|| Mutex::new(Steam::new())); // Define cursor structure #[derive(Debug, Clone, Serialize, Deserialize)] @@ -26,23 +33,27 @@ pub struct AppStateWrapper(Mutex); // Command to get all cursors #[tauri::command] fn get_cursors(state: tauri::State) -> Vec { - let app_state = state.0.lock().unwrap(); + let app_state = state.0.lock(); app_state.cursors.clone() } // Command to get current cursor index #[tauri::command] fn get_current_cursor_index(state: tauri::State) -> usize { - let app_state = state.0.lock().unwrap(); + let app_state = state.0.lock(); app_state.current_index } // Command to select a cursor #[tauri::command] -fn select_cursor(index: usize, state: tauri::State, app_handle: AppHandle) -> Result<(), String> { +fn select_cursor( + index: usize, + state: tauri::State, + app_handle: AppHandle, +) -> Result<(), String> { println!("=== RESOURCE DEBUG [select_cursor] ==="); - let mut app_state = state.0.lock().unwrap(); + let mut app_state = state.0.lock(); if index < app_state.cursors.len() { app_state.current_index = index; @@ -110,10 +121,13 @@ fn select_cursor(index: usize, state: tauri::State, app_handle: // Command to go to the next cursor #[tauri::command] -fn next_cursor(state: tauri::State, app_handle: AppHandle) -> Result { +fn next_cursor( + state: tauri::State, + app_handle: AppHandle, +) -> Result { println!("=== RESOURCE DEBUG [next_cursor] ==="); - let mut app_state = state.0.lock().unwrap(); + let mut app_state = state.0.lock(); if !app_state.cursors.is_empty() { app_state.current_index = (app_state.current_index + 1) % app_state.cursors.len(); @@ -175,11 +189,14 @@ fn minimize_to_tray(app_handle: AppHandle) -> Result<(), String> { println!("Minimizing to tray"); // Get the main window - let window = app_handle.get_window("main") + let window = app_handle + .get_window("main") .ok_or_else(|| "Failed to get main window".to_string())?; // Hide the window - window.hide().map_err(|e| format!("Failed to hide window: {}", e))?; + window + .hide() + .map_err(|e| format!("Failed to hide window: {}", e))?; // The tray should already be visible as configured in tauri.conf.json println!("Window hidden, application should now be accessible from the system tray"); @@ -206,7 +223,7 @@ fn load_cursor_files() -> Vec { println!("CHECKING FOR PNG/CUR FILES IN MULTIPLE DIRECTORIES:"); for (i, cursors_dir) in possible_cursor_dirs.iter().enumerate() { - println!("Checking dir {}: {}", i+1, cursors_dir.display()); + println!("Checking dir {}: {}", i + 1, cursors_dir.display()); println!(" Directory exists: {}", cursors_dir.exists()); if cursors_dir.exists() { @@ -217,8 +234,13 @@ fn load_cursor_files() -> Vec { let path = entry.path(); println!(" Found: {}", path.display()); - if path.is_file() && path.extension().map_or(false, |ext| ext == "png" || ext == "cur") { - let name = path.file_stem() + if path.is_file() + && path + .extension() + .map_or(false, |ext| ext == "png" || ext == "cur") + { + let name = path + .file_stem() .and_then(|s| s.to_str()) .unwrap_or("Unknown") .to_string(); @@ -278,6 +300,9 @@ fn load_cursor_files() -> Vec { pub fn run() { println!("Starting Cursor Rush application"); + // Get LazyLock to create steam + let _ = STEAM.lock(); + // Initialize platform-specific cursor handling if let Err(e) = platform::initialize() { eprintln!("Failed to initialize platform: {}", e); @@ -327,7 +352,7 @@ pub fn run() { eprintln!("Failed to focus window: {}", e); } } - }, + } Err(e) => { eprintln!("Failed to check window visibility: {}", e); // Try to show it anyway @@ -346,10 +371,11 @@ pub fn run() { "next_cursor" => { println!("Next cursor requested from tray"); let state = app.state::(); - let mut app_state = state.0.lock().unwrap(); + let mut app_state = state.0.lock(); if !app_state.cursors.is_empty() { - app_state.current_index = (app_state.current_index + 1) % app_state.cursors.len(); + app_state.current_index = + (app_state.current_index + 1) % app_state.cursors.len(); let cursor = &app_state.cursors[app_state.current_index]; if Path::new(&cursor.path).exists() {