diff --git a/src/platform.rs b/src/platform.rs index 822b18a..c2bc522 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -8,9 +8,6 @@ mod windows { use std::thread; use std::time::Duration; use std::sync::Once; - use std::fs::File; - use std::io::Write; - use std::process::Command; use winapi::{ um::winuser::{ GetDC, ReleaseDC, GetCursorPos, LoadCursorW, @@ -346,23 +343,8 @@ mod windows { // Method 3: Reset all system cursors to their defaults using Windows API if !restoration_success { println!("Using system reset method"); - // Call our reset function which uses both W and A versions of SystemParametersInfo + // Call our reset function which uses SystemParametersInfo reset_system_cursors(); - - // We'll assume this worked unless we have evidence it didn't - restoration_success = true; - - // Try to verify by checking if we can load a cursor - let test_cursor = LoadCursorW(null_mut(), 32512 as _); // IDC_ARROW - if test_cursor.is_null() { - restoration_success = false; - } - } - - // Method 4: Only create and run a batch file as a last resort if all other methods failed - if !restoration_success { - println!("All direct restoration methods failed, using batch file fallback"); - create_cursor_reset_file(); } CURSOR_HIDDEN = false; @@ -436,85 +418,36 @@ mod windows { #[ctor::dtor] fn module_cleanup() { println!("Module unloading, restoring cursors..."); - // Just call cleanup which now handles all restoration methods + // Call cleanup which handles all cursor restoration cleanup(); - // No need to create a reset file here as cleanup() will do it if needed } // Function to reset all system cursors to their defaults fn reset_system_cursors() { unsafe { - // Try multiple approaches to reset cursors + // Use the Windows API to reset system cursors + let result = SystemParametersInfoW(SPI_SETCURSORS, 0, null_mut(), 0); - // First try with the W version - let result1 = SystemParametersInfoW(SPI_SETCURSORS, 0, null_mut(), 0); + if result == 0 { + // If the W version failed, try with the A version with flags to update the system settings + let result = SystemParametersInfoA( + SPI_SETCURSORS_A, + 0, + null_mut(), + SPIF_UPDATEINIFILE | SPIF_SENDCHANGE + ); - // Then try with the A version with flags to update the system settings - let result2 = SystemParametersInfoA( - SPI_SETCURSORS_A, - 0, - null_mut(), - SPIF_UPDATEINIFILE | SPIF_SENDCHANGE - ); - - // Try direct call to rundll32 as a more forceful approach - if result1 == 0 && result2 == 0 { - // Both API calls failed, try using Command - match Command::new("rundll32.exe") - .args(&["user32.dll,SystemParametersInfo", "0x0057", "0", "0", "0x01"]) - .status() - { - Ok(status) => { - if status.success() { - println!("Reset system cursors using rundll32"); - } else { - eprintln!("rundll32 cursor reset failed with status: {}", status); - } - }, - Err(e) => eprintln!("Failed to execute rundll32: {}", e), + if result == 0 { + eprintln!("Failed to reset system cursors via API"); + } else { + println!("Reset system cursors to defaults via API (A version)"); } } else { - println!("Reset system cursors to defaults via API"); + println!("Reset system cursors to defaults via API (W version)"); } } } - // Create a batch file that will reset the cursors and run it - fn create_cursor_reset_file() { - // Create a temporary batch file to reset cursors - let batch_content = r#"@echo off -echo Resetting system cursors... -rundll32.exe user32.dll,SystemParametersInfo 0x0057 0 0 0x01 | 0x02 -echo Cursors reset. -timeout /t 2 -del "%~f0" -"#; - - let file_path = "reset_cursors.bat"; - - // Write the batch file - match File::create(file_path) { - Ok(mut file) => { - if let Err(e) = file.write_all(batch_content.as_bytes()) { - eprintln!("Failed to write to batch file: {}", e); - return; - } - - println!("Created cursor reset batch file"); - - // Run the batch file in a separate process - match Command::new("cmd") - .args(&["/C", "start", "/min", file_path]) - .spawn() - { - Ok(_) => println!("Launched cursor reset batch file"), - Err(e) => eprintln!("Failed to launch batch file: {}", e), - } - }, - Err(e) => eprintln!("Failed to create batch file: {}", e), - } - } - // Function to save the original system cursors fn save_original_cursors() { unsafe {