Fixed window dragging for main menu
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::{env, fs::{self, read_dir}, path::{Path, PathBuf}};
|
||||
use std::{env, fs::{self, read_dir}, path::PathBuf};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
tauri_build::build();
|
||||
|
||||
@@ -11,6 +11,7 @@ pub struct Steam {
|
||||
impl Steam {
|
||||
pub fn new() -> Self {
|
||||
let (client, single) = Client::init_app(AppId(1430270)).unwrap();
|
||||
println!("Steam client initialized successfully");
|
||||
Self { client, single }
|
||||
}
|
||||
|
||||
@@ -23,4 +24,17 @@ impl Steam {
|
||||
// In a real implementation with the correct API version, we would use:
|
||||
// self.client.get_inventory().trigger_item_drop(item_def_id);
|
||||
}
|
||||
|
||||
pub fn shutdown(&self) {
|
||||
println!("Steam client shutting down");
|
||||
// The steamworks crate handles cleanup automatically when the client is dropped
|
||||
// But we can add any additional cleanup logic here if needed
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Steam {
|
||||
fn drop(&mut self) {
|
||||
println!("Steam client being dropped, performing cleanup");
|
||||
self.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,12 +171,22 @@ fn next_cursor(
|
||||
// Command to quit the application
|
||||
#[tauri::command]
|
||||
fn quit_app(app_handle: AppHandle) {
|
||||
println!("Quit app command received, performing cleanup");
|
||||
|
||||
// Clean up Steam integration
|
||||
{
|
||||
let steam = STEAM.lock();
|
||||
steam.shutdown();
|
||||
}
|
||||
|
||||
// Clean up and restore default cursor before exit
|
||||
match platform::restore_system_cursor() {
|
||||
Ok(_) => println!("Default cursor restored"),
|
||||
Err(e) => eprintln!("Failed to restore default cursor: {}", e),
|
||||
}
|
||||
|
||||
println!("Cleanup complete, exiting application");
|
||||
|
||||
// Exit the application
|
||||
std::thread::spawn(move || {
|
||||
app_handle.exit(0);
|
||||
@@ -204,6 +214,52 @@ fn minimize_to_tray(app_handle: AppHandle) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Command to temporarily restore system cursor (for drag operations)
|
||||
#[tauri::command]
|
||||
fn temporarily_restore_cursor() -> Result<(), String> {
|
||||
match platform::restore_system_cursor_temporarily() {
|
||||
Ok(_) => {
|
||||
println!("System cursor temporarily restored for drag operation");
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => Err(format!("Failed to restore system cursor: {}", e)),
|
||||
}
|
||||
}
|
||||
|
||||
// Command to re-apply custom cursor (after drag operations)
|
||||
#[tauri::command]
|
||||
fn reapply_custom_cursor(state: tauri::State<AppStateWrapper>) -> Result<(), String> {
|
||||
let app_state = state.0.lock();
|
||||
if !app_state.cursors.is_empty() && app_state.current_index < app_state.cursors.len() {
|
||||
let current_cursor = &app_state.cursors[app_state.current_index];
|
||||
match platform::set_system_cursor(¤t_cursor.path) {
|
||||
Ok(_) => {
|
||||
println!("Custom cursor re-applied after drag operation");
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => Err(format!("Failed to re-apply custom cursor: {}", e)),
|
||||
}
|
||||
} else {
|
||||
Err("No cursor to re-apply".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
// Command to manually restore default cursors
|
||||
#[tauri::command]
|
||||
fn restore_default_cursors() -> Result<(), String> {
|
||||
println!("Manual restore default cursors command received");
|
||||
match platform::restore_system_cursor() {
|
||||
Ok(_) => {
|
||||
println!("Default cursors restored successfully");
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to restore default cursors: {}", e);
|
||||
Err(format!("Failed to restore default cursors: {}", e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Function to load cursor files from src/cursors directory
|
||||
fn load_cursor_files() -> Vec<Cursor> {
|
||||
println!("=== RESOURCE DEBUG [load_cursor_files] ===");
|
||||
@@ -403,11 +459,20 @@ pub fn run() {
|
||||
}
|
||||
"quit" => {
|
||||
println!("Quit requested from tray");
|
||||
|
||||
// Clean up Steam integration
|
||||
{
|
||||
let steam = STEAM.lock();
|
||||
steam.shutdown();
|
||||
}
|
||||
|
||||
// Clean up and restore default cursor before exit
|
||||
match platform::restore_system_cursor() {
|
||||
Ok(_) => println!("Default cursor restored"),
|
||||
Err(e) => eprintln!("Failed to restore default cursor: {}", e),
|
||||
}
|
||||
|
||||
println!("Cleanup complete, exiting from tray");
|
||||
app.exit(0);
|
||||
}
|
||||
_ => {}
|
||||
@@ -441,7 +506,10 @@ pub fn run() {
|
||||
select_cursor,
|
||||
next_cursor,
|
||||
quit_app,
|
||||
minimize_to_tray
|
||||
minimize_to_tray,
|
||||
temporarily_restore_cursor,
|
||||
reapply_custom_cursor,
|
||||
restore_default_cursors
|
||||
])
|
||||
.setup(|_app| {
|
||||
// Register for events or perform additional setup
|
||||
|
||||
@@ -20,7 +20,7 @@ pub type Result<T> = std::result::Result<T, String>;
|
||||
|
||||
// Platform-agnostic interface for cursor handling
|
||||
#[cfg(target_os = "windows")]
|
||||
pub use self::windows::{set_cursor, restore_default_cursor, init};
|
||||
pub use self::windows::{set_cursor, restore_default_cursor, restore_default_cursor_temporarily, init};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub use self::macos::{set_cursor, restore_default_cursor, init};
|
||||
@@ -52,6 +52,20 @@ pub fn restore_system_cursor() -> Result<()> {
|
||||
restore_default_cursor()
|
||||
}
|
||||
|
||||
// Cross-platform implementation for temporarily restoring default cursor
|
||||
pub fn restore_system_cursor_temporarily() -> Result<()> {
|
||||
println!("Temporarily restoring system cursor");
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
restore_default_cursor_temporarily()
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
// For non-Windows platforms, just use the regular restore for now
|
||||
restore_default_cursor()
|
||||
}
|
||||
}
|
||||
|
||||
// Default implementations for non-supported platforms
|
||||
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
|
||||
pub fn set_cursor(_path: &str) -> Result<()> {
|
||||
|
||||
@@ -202,6 +202,13 @@ unsafe fn create_cursor_from_image(image: &RgbaImage) -> Option<SyncHCURSOR> {
|
||||
pub fn cleanup() {
|
||||
println!("Running cursor cleanup...");
|
||||
|
||||
// Check if we have original cursors saved before attempting restoration
|
||||
let has_original_cursors = {
|
||||
let guard = ORIGINAL_CURSORS.lock().unwrap();
|
||||
guard.is_some()
|
||||
};
|
||||
println!("Has original cursors saved: {}", has_original_cursors);
|
||||
|
||||
// Restore system cursors if they were hidden
|
||||
// Use swap to ensure it runs only once
|
||||
if CURSOR_HIDDEN.swap(false, Ordering::SeqCst) {
|
||||
@@ -211,15 +218,24 @@ pub fn cleanup() {
|
||||
// Try multiple approaches to ensure cursors are restored
|
||||
|
||||
// 1. First try to restore original cursors if we saved them
|
||||
let original_cursors_opt = ORIGINAL_CURSORS.lock().unwrap().take();
|
||||
let original_cursors_opt = {
|
||||
let mut guard = ORIGINAL_CURSORS.lock().unwrap();
|
||||
guard.take()
|
||||
};
|
||||
|
||||
if let Some(original_cursors) = original_cursors_opt {
|
||||
println!("Restoring {} saved original cursors", original_cursors.len());
|
||||
let total_cursors = original_cursors.len();
|
||||
println!("Restoring {} saved original cursors", total_cursors);
|
||||
let mut restored_count = 0;
|
||||
for (cursor_id, cursor) in original_cursors {
|
||||
if !cursor.0.is_null() {
|
||||
// Make a copy of the original cursor
|
||||
let cursor_copy = CopyIcon(cursor.0);
|
||||
if !cursor_copy.is_null() {
|
||||
if SetSystemCursor(cursor_copy, cursor_id) == 0 {
|
||||
if SetSystemCursor(cursor_copy, cursor_id) != 0 {
|
||||
restored_count += 1;
|
||||
println!("Successfully restored cursor for ID: {}", cursor_id);
|
||||
} else {
|
||||
eprintln!("Failed to restore original cursor for ID: {}", cursor_id);
|
||||
DestroyIcon(cursor_copy);
|
||||
}
|
||||
@@ -231,8 +247,25 @@ pub fn cleanup() {
|
||||
DestroyIcon(cursor.0);
|
||||
}
|
||||
}
|
||||
println!("Restored {} out of {} original cursors", restored_count, total_cursors);
|
||||
} else {
|
||||
println!("No saved original cursors found");
|
||||
println!("No saved original cursors found, using fallback restoration methods");
|
||||
|
||||
// Try to restore each system cursor to its default
|
||||
for &cursor_id in SYSTEM_CURSORS.iter() {
|
||||
let default_cursor = LoadCursorW(null_mut(), MAKEINTRESOURCEW(cursor_id as u16));
|
||||
if !default_cursor.is_null() {
|
||||
let cursor_copy = CopyIcon(default_cursor);
|
||||
if !cursor_copy.is_null() {
|
||||
if SetSystemCursor(cursor_copy, cursor_id) != 0 {
|
||||
println!("Restored default cursor for ID: {}", cursor_id);
|
||||
} else {
|
||||
eprintln!("Failed to restore default cursor for ID: {}", cursor_id);
|
||||
DestroyIcon(cursor_copy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Force Windows to reload default cursor settings
|
||||
@@ -310,19 +343,26 @@ pub fn hide_system_cursor() -> bool {
|
||||
// Save original cursors for restoration
|
||||
let mut original_cursors = Vec::new();
|
||||
unsafe {
|
||||
println!("Saving original cursors for restoration...");
|
||||
for &cursor_id in SYSTEM_CURSORS.iter() {
|
||||
// Get the original cursor
|
||||
let original_cursor = CopyIcon(LoadCursorW(null_mut(), MAKEINTRESOURCEW(cursor_id as u16)));
|
||||
if !original_cursor.is_null() {
|
||||
// Save the original cursor for restoration
|
||||
original_cursors.push((cursor_id, SyncHCURSOR(original_cursor)));
|
||||
println!("Saved original cursor for ID: {}", cursor_id);
|
||||
} else {
|
||||
eprintln!("Failed to save original cursor for ID: {}", cursor_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store original cursors for restoration
|
||||
if !original_cursors.is_empty() {
|
||||
println!("Storing {} original cursors for later restoration", original_cursors.len());
|
||||
*ORIGINAL_CURSORS.lock().unwrap() = Some(original_cursors);
|
||||
} else {
|
||||
eprintln!("No original cursors were saved!");
|
||||
}
|
||||
|
||||
// Mark as hidden - this is now just a flag to indicate we've saved the original cursors
|
||||
@@ -497,7 +537,30 @@ unsafe fn apply_cursor_to_all_system_cursors(cursor: winapi::shared::windef::HCU
|
||||
success
|
||||
}
|
||||
|
||||
// Restore the system cursor
|
||||
// Restore the system cursor temporarily (without affecting cleanup state)
|
||||
pub fn restore_cursor_temporarily() {
|
||||
println!("Temporarily restoring system cursors...");
|
||||
|
||||
unsafe {
|
||||
// Force Windows to reload default cursor settings
|
||||
println!("Forcing Windows to reload default cursor settings");
|
||||
SystemParametersInfoW(SPI_SETCURSORS, 0, null_mut(), 0);
|
||||
|
||||
// Also try the A version for maximum compatibility
|
||||
super::state::reset_system_cursors();
|
||||
|
||||
// Reset to default arrow cursor
|
||||
let arrow_cursor = LoadCursorW(null_mut(), MAKEINTRESOURCEW(IDC_ARROW as u16));
|
||||
if !arrow_cursor.is_null() {
|
||||
SetCursor(arrow_cursor);
|
||||
println!("Reset to default arrow cursor temporarily.");
|
||||
}
|
||||
}
|
||||
|
||||
println!("Temporary cursor restoration complete.");
|
||||
}
|
||||
|
||||
// Restore the system cursor permanently (full cleanup)
|
||||
pub fn restore_cursor() {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
@@ -36,6 +36,12 @@ pub fn restore_default_cursor() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn restore_default_cursor_temporarily() -> Result<()> {
|
||||
println!("Windows platform: temporarily restoring default cursor");
|
||||
cursor::restore_cursor_temporarily();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn init() -> Result<()> {
|
||||
println!("Windows platform: initializing cursor system");
|
||||
if !cursor::hide_system_cursor() {
|
||||
|
||||
Reference in New Issue
Block a user