Clean up debug logging spam

- Remove ~101 useless debug print statements from production code
- Remove verbose resource debugging and repetitive status messages
- Significantly reduce console noise while maintaining error visibility
This commit is contained in:
2025-05-30 22:59:25 -05:00
parent a9976cbbe5
commit 4f71789710
5 changed files with 11 additions and 183 deletions
@@ -11,7 +11,6 @@ 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 }
}
@@ -19,14 +18,12 @@ impl Steam {
pub fn drop_item(&self) {
// Placeholder for item drop functionality
// The actual implementation would use the Steam API to trigger an item drop
println!("Steam item drop triggered (placeholder)");
// 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
}
@@ -34,7 +31,6 @@ impl Steam {
impl Drop for Steam {
fn drop(&mut self) {
println!("Steam client being dropped, performing cleanup");
self.shutdown();
}
}
+6 -117
View File
@@ -55,33 +55,24 @@ fn apply_cursor_by_index(
}
let cursor = &app_state.cursors[index];
println!("Applying cursor: {} ({})", cursor.name, cursor.path);
// Verify the file exists
if !Path::new(&cursor.path).exists() {
println!("File doesn't exist: {}", cursor.path);
return Err(format!("Cursor file does not exist: {}", cursor.path));
}
println!("File exists, applying cursor...");
// Apply the cursor
if let Err(e) = platform::set_system_cursor(&cursor.path) {
println!("Error applying cursor: {}", e);
return Err(format!("Failed to apply cursor '{}': {}", cursor.name, e));
}
// Emit an event to notify the frontend
let _ = app_handle.emit_all("cursor_changed", index); // Ignore error
println!("Successfully applied cursor using actual file path");
Ok(())
}
// Helper function to perform application cleanup (Steam shutdown and cursor restoration)
fn perform_app_cleanup() {
println!("Performing application cleanup...");
// Clean up Steam integration
{
let steam = STEAM.lock();
@@ -90,11 +81,9 @@ fn perform_app_cleanup() {
// Clean up and restore default cursor before exit
match platform::restore_system_cursor() {
Ok(_) => println!("Default cursor restored"),
Ok(_) => {},
Err(e) => eprintln!("Failed to restore default cursor: {}", e),
}
println!("Cleanup complete");
}
// Command to select a cursor
@@ -104,51 +93,17 @@ fn select_cursor(
state: tauri::State<AppStateWrapper>,
app_handle: AppHandle,
) -> Result<(), String> {
println!("=== RESOURCE DEBUG [select_cursor] ===");
let mut app_state = state.0.lock();
if index < app_state.cursors.len() {
app_state.current_index = index;
let cursor = &app_state.cursors[index];
println!("Cursor selected: {}", cursor.name);
println!("Original path: {}", cursor.path);
// Get the resource directory
let resource_dir = app_handle.path_resolver().resource_dir();
println!("Resource dir: {:?}", resource_dir);
// List contents of resource dir
if let Some(res_dir) = &resource_dir {
println!("Listing contents of resource dir: {}", res_dir.display());
if let Ok(entries) = std::fs::read_dir(res_dir) {
for (i, entry) in entries.filter_map(Result::ok).enumerate() {
println!(" {}: {}", i, entry.path().display());
// List subdirectories
if entry.path().is_dir() {
if let Ok(subentries) = std::fs::read_dir(entry.path()) {
for (j, subentry) in subentries.filter_map(Result::ok).enumerate() {
println!(" {}.{}: {}", i, j, subentry.path().display());
}
}
}
}
} else {
println!("Failed to read resource directory");
}
}
let filename = Path::new(&cursor.path)
.file_name()
.and_then(|name| name.to_str())
.ok_or_else(|| format!("Invalid cursor path: {}", cursor.path))?;
println!("Extracted filename: {}", filename);
// Try using the actual file path directly
println!("Using direct file path: {}", cursor.path);
// Use the helper function to apply the cursor
apply_cursor_by_index(index, &app_state, &app_handle)
} else {
@@ -162,26 +117,17 @@ fn next_cursor(
state: tauri::State<AppStateWrapper>,
app_handle: AppHandle,
) -> Result<usize, String> {
println!("=== RESOURCE DEBUG [next_cursor] ===");
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();
let cursor = &app_state.cursors[app_state.current_index];
println!("Next cursor: {} ({})", cursor.name, cursor.path);
let filename = Path::new(&cursor.path)
.file_name()
.and_then(|name| name.to_str())
.ok_or_else(|| format!("Invalid cursor path: {}", cursor.path))?;
// Try both resource paths like in select_cursor
println!("Extracted filename: {}", filename);
// Try using the actual file path directly
println!("Using direct file path: {}", cursor.path);
// Use the helper function to apply the cursor
apply_cursor_by_index(app_state.current_index, &app_state, &app_handle)?;
Ok(app_state.current_index)
@@ -193,13 +139,9 @@ fn next_cursor(
// Command to quit the application
#[tauri::command]
fn quit_app(app_handle: AppHandle) {
println!("Quit app command received");
// Use the helper function to perform cleanup
perform_app_cleanup();
println!("Exiting application");
// Exit the application
std::thread::spawn(move || {
app_handle.exit(0);
@@ -209,8 +151,6 @@ fn quit_app(app_handle: AppHandle) {
// Command to minimize the window to tray
#[tauri::command]
fn minimize_to_tray(app_handle: AppHandle) -> Result<(), String> {
println!("Minimizing to tray");
// Get the main window
let window = app_handle
.get_window("main")
@@ -221,9 +161,6 @@ fn minimize_to_tray(app_handle: AppHandle) -> Result<(), String> {
.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");
Ok(())
}
@@ -231,10 +168,7 @@ fn minimize_to_tray(app_handle: AppHandle) -> Result<(), String> {
#[tauri::command]
fn temporarily_restore_cursor() -> Result<(), String> {
match platform::restore_system_cursor_temporarily() {
Ok(_) => {
println!("System cursor temporarily restored for drag operation");
Ok(())
}
Ok(_) => Ok(()),
Err(e) => Err(format!("Failed to restore system cursor: {}", e)),
}
}
@@ -246,10 +180,7 @@ fn reapply_custom_cursor(state: tauri::State<AppStateWrapper>) -> Result<(), Str
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(&current_cursor.path) {
Ok(_) => {
println!("Custom cursor re-applied after drag operation");
Ok(())
}
Ok(_) => Ok(()),
Err(e) => Err(format!("Failed to re-apply custom cursor: {}", e)),
}
} else {
@@ -260,12 +191,8 @@ fn reapply_custom_cursor(state: tauri::State<AppStateWrapper>) -> Result<(), Str
// 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(())
}
Ok(_) => Ok(()),
Err(e) => {
eprintln!("Failed to restore default cursors: {}", e);
Err(format!("Failed to restore default cursors: {}", e))
@@ -275,12 +202,10 @@ fn restore_default_cursors() -> Result<(), String> {
// Function to load cursor files from src/cursors directory
fn load_cursor_files() -> Vec<Cursor> {
println!("=== RESOURCE DEBUG [load_cursor_files] ===");
let mut cursors = Vec::new();
// Determine the path to src/cursors relative to src-tauri (CARGO_MANIFEST_DIR)
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
println!("CARGO_MANIFEST_DIR: {}", manifest_dir.display());
// Check multiple possible locations
let possible_cursor_dirs = vec![
@@ -290,18 +215,11 @@ fn load_cursor_files() -> Vec<Cursor> {
manifest_dir.clone(), // Check manifest dir itself
];
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!(" Directory exists: {}", cursors_dir.exists());
for cursors_dir in possible_cursor_dirs.iter() {
if cursors_dir.exists() {
println!(" Looking for cursor files in this directory...");
if let Ok(entries) = std::fs::read_dir(cursors_dir) {
for entry in entries.filter_map(Result::ok) {
let path = entry.path();
println!(" Found: {}", path.display());
if path.is_file()
&& path
@@ -314,7 +232,6 @@ fn load_cursor_files() -> Vec<Cursor> {
.unwrap_or("Unknown")
.to_string();
println!(" ADDING CURSOR: {} at path {}", name, path.display());
cursors.push(Cursor {
name,
path: path.to_string_lossy().to_string(),
@@ -324,7 +241,6 @@ fn load_cursor_files() -> Vec<Cursor> {
}
if !cursors.is_empty() {
println!(" Found {} cursor files in this directory.", cursors.len());
break;
}
}
@@ -332,12 +248,7 @@ fn load_cursor_files() -> Vec<Cursor> {
// If we found no cursors, use mock data with paths relative to what resolve_resource expects
if cursors.is_empty() {
println!("No cursors found in any directory. Using mock data instead.");
println!("IMPORTANT: This is probably the source of your problem!");
println!("The app could not find your cursor PNG files. Check that they exist in one of these directories:");
for dir in &possible_cursor_dirs {
println!(" {}", dir.display());
}
eprintln!("No cursor files found, using fallback cursors");
// Mock data paths should reflect their eventual resource path structure
cursors.push(Cursor {
@@ -354,12 +265,8 @@ fn load_cursor_files() -> Vec<Cursor> {
name: "Red".to_string(),
path: "src/cursors/red.png".to_string(), // Filename will be 'red.png'
});
println!("Created {} mock cursor entries", cursors.len());
}
println!("Loaded {} cursor files", cursors.len());
// Sort cursors by name for consistent ordering
cursors.sort_by(|a, b| a.name.cmp(&b.name));
cursors
@@ -367,8 +274,6 @@ fn load_cursor_files() -> Vec<Cursor> {
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
println!("Starting Cursor Rush application");
// Get LazyLock to create steam
let _ = STEAM.lock();
@@ -405,15 +310,12 @@ pub fn run() {
.system_tray(system_tray)
.on_system_tray_event(|app, event| match event {
SystemTrayEvent::LeftClick { .. } => {
println!("System tray received a left click");
if let Some(window) = app.get_window("main") {
match window.is_visible() {
Ok(visible) => {
if visible {
println!("Window is already visible, focusing it");
let _ = window.set_focus();
} else {
println!("Window is hidden, showing it");
if let Err(e) = window.show() {
eprintln!("Failed to show window: {}", e);
}
@@ -435,10 +337,8 @@ pub fn run() {
}
}
SystemTrayEvent::MenuItemClick { id, .. } => {
println!("Menu item clicked: {}", id);
match id.as_str() {
"next_cursor" => {
println!("Next cursor requested from tray");
let state = app.state::<AppStateWrapper>();
let mut app_state = state.0.lock();
@@ -453,7 +353,6 @@ pub fn run() {
}
}
"show_window" => {
println!("Show window requested from tray");
if let Some(window) = app.get_window("main") {
if let Err(e) = window.show() {
eprintln!("Failed to show window: {}", e);
@@ -466,12 +365,9 @@ pub fn run() {
}
}
"quit" => {
println!("Quit requested from tray");
// Use the helper function to perform cleanup
perform_app_cleanup();
println!("Exiting from tray");
app.exit(0);
}
_ => {}
@@ -487,13 +383,10 @@ pub fn run() {
// Get the window and hide it
let window = event.window();
println!("Window close requested in backend handler, hiding window");
// Hide the window instead of closing it
if let Err(e) = window.hide() {
eprintln!("Failed to hide window: {}", e);
} else {
println!("Window hidden successfully, app is now in system tray");
}
}
_ => {}
@@ -511,12 +404,8 @@ pub fn run() {
restore_default_cursors
])
.setup(|_app| {
// Register for events or perform additional setup
println!("Tauri application setup complete");
// We're not setting up a window close handler here anymore
// The frontend will handle this based on the minimize-to-tray setting
Ok(())
})
// This matches exactly how it was before our changes
@@ -23,7 +23,6 @@ use super::state::*;
// Control handler function for console events (Ctrl+C, close, etc.)
extern "system" fn ctrl_handler(_ctrl_type: u32) -> i32 {
println!("Control event received, attempting cleanup...");
cleanup(); // Call cleanup logic
FALSE // Allow other handlers (like default exit) to run
}
@@ -200,19 +199,15 @@ unsafe fn create_cursor_from_image(image: &RgbaImage) -> Option<SyncHCURSOR> {
// Cleanup function to restore cursors and clean up resources
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) {
println!("Restoring system cursors...");
unsafe {
// Try multiple approaches to ensure cursors are restored
@@ -224,18 +219,12 @@ pub fn cleanup() {
};
if let Some(original_cursors) = original_cursors_opt {
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 {
restored_count += 1;
println!("Successfully restored cursor for ID: {}", cursor_id);
} else {
if SetSystemCursor(cursor_copy, cursor_id) == 0 {
eprintln!("Failed to restore original cursor for ID: {}", cursor_id);
DestroyIcon(cursor_copy);
}
@@ -247,9 +236,7 @@ pub fn cleanup() {
DestroyIcon(cursor.0);
}
}
println!("Restored {} out of {} original cursors", restored_count, total_cursors);
} else {
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() {
@@ -257,9 +244,7 @@ pub fn cleanup() {
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 {
if SetSystemCursor(cursor_copy, cursor_id) == 0 {
eprintln!("Failed to restore default cursor for ID: {}", cursor_id);
DestroyIcon(cursor_copy);
}
@@ -268,22 +253,18 @@ pub fn cleanup() {
}
}
// 2. Force Windows to reload default cursor settings
println!("Forcing Windows to reload default cursor settings");
// Force Windows to reload default cursor settings
SystemParametersInfoW(SPI_SETCURSORS, 0, null_mut(), 0);
// 3. Also try the A version for maximum compatibility
// Also try the A version for maximum compatibility
super::state::reset_system_cursors();
// 4. Reset to default arrow cursor
// 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.");
}
}
println!("System cursors restoration complete.");
}
// Destroy the custom cursor if it exists
@@ -292,7 +273,6 @@ pub fn cleanup() {
unsafe {
if !cursor_wrapper.0.is_null() {
DestroyIcon(cursor_wrapper.0);
println!("Custom cursor destroyed during cleanup.");
}
}
}
@@ -308,14 +288,11 @@ pub fn cleanup() {
unsafe {
if SetConsoleCtrlHandler(Some(ctrl_handler), FALSE) != 0 {
CTRL_HANDLER_REGISTERED.store(false, Ordering::SeqCst);
println!("Control handler unregistered.");
} else {
eprintln!("Failed to unregister control handler.");
}
}
}
println!("Cursor cleanup complete.");
}
// --- Public API Functions ---
@@ -328,7 +305,6 @@ pub fn hide_system_cursor() -> bool {
unsafe {
if SetConsoleCtrlHandler(Some(ctrl_handler), TRUE) != 0 {
CTRL_HANDLER_REGISTERED.store(true, Ordering::SeqCst);
println!("Control handler registered for clean exit.");
} else {
eprintln!("Failed to register control handler: {}", std::io::Error::last_os_error());
}
@@ -343,14 +319,12 @@ 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);
}
@@ -359,7 +333,6 @@ pub fn hide_system_cursor() -> bool {
// 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!");
@@ -373,15 +346,11 @@ pub fn hide_system_cursor() -> bool {
// Update the cursor image using CursorInfo (with caching)
pub fn update_cursor_info(cursor_info: &mut crate::platform::types::CursorInfo) -> bool {
println!("Updating cursor to: {}", cursor_info.name);
// Use cached image if available, otherwise load from disk
let image: image::RgbaImage = if let Some(ref cached_image) = cursor_info.image {
println!("Using cached image for cursor: {}", cursor_info.name);
let img_clone: image::RgbaImage = cached_image.clone();
img_clone
} else {
println!("Loading image from disk for cursor: {}", cursor_info.name);
match image_open(&cursor_info.path) {
Ok(img) => {
let rgba = img.to_rgba8();
@@ -448,7 +417,6 @@ pub fn update_cursor_info(cursor_info: &mut crate::platform::types::CursorInfo)
#[cfg(windows)]
if let Some(cached_cursor) = &cursor_info.win_cursor {
if !cached_cursor.handle.is_null() {
println!("Falling back to cached cursor as a last resort");
let mut cursor_guard = CUSTOM_CURSOR.lock().unwrap();
// Convert WinCursorWrapper to SyncHCURSOR
let sync_cursor = super::types::SyncHCURSOR(cached_cursor.handle);
@@ -539,11 +507,8 @@ unsafe fn apply_cursor_to_all_system_cursors(cursor: winapi::shared::windef::HCU
// 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
@@ -553,11 +518,8 @@ pub fn restore_cursor_temporarily() {
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)
@@ -9,7 +9,6 @@ use crate::platform::Result;
// Functions expected by the platform-agnostic interface
pub fn set_cursor(path: &str) -> Result<()> {
println!("Windows platform: setting cursor to {}", path);
// Create a cursor info struct to pass to update_cursor_info
let mut cursor_info = crate::platform::types::CursorInfo {
-18
View File
@@ -26,21 +26,16 @@ function App() {
// Function to minimize app to tray
const minimizeToTray = useCallback(async () => {
try {
console.log('Minimizing app to tray');
// First hide the window to ensure it disappears immediately
await appWindow.hide();
console.log('Window hidden, now ensuring tray is visible');
// Then call the backend to ensure the tray is visible
await invoke("minimize_to_tray");
console.log('minimize_to_tray command completed successfully');
} catch (error) {
console.error("Failed to minimize to tray:", error);
// Fallback to window API if the invoke fails
try {
console.log('Trying fallback hide');
await appWindow.hide();
console.log('Fallback hide succeeded');
} catch (fallbackError) {
console.error("Fallback hide also failed:", fallbackError);
}
@@ -52,7 +47,6 @@ function App() {
const setupFocusHandler = async () => {
const unlistenFocus = await appWindow.onFocusChanged(async ({ payload: focused }) => {
if (focused) {
console.log('Window gained focus, re-applying custom cursor');
try {
await invoke("reapply_custom_cursor");
} catch (error) {
@@ -82,7 +76,6 @@ function App() {
try {
// Get cursors from the Tauri backend
const loadedCursors = await invoke("get_cursors");
console.log("Loaded cursors:", loadedCursors);
setCursors(loadedCursors || []);
// Get current cursor index
@@ -109,16 +102,12 @@ function App() {
useEffect(() => {
const setupCloseHandler = async () => {
const unlisten = await appWindow.onCloseRequested(async (event) => {
console.log('Window close requested');
if (settings.minimizeToTrayOnClose) {
console.log('Minimize to tray setting is enabled, preventing close and hiding instead');
// Prevent the window from closing
event.preventDefault();
// Temporarily restore cursor before hiding to tray
try {
console.log('Temporarily restoring cursor before hiding to tray');
await invoke("temporarily_restore_cursor");
} catch (error) {
console.error('Failed to restore cursor before hiding:', error);
@@ -126,14 +115,11 @@ function App() {
// Hide the window instead
try {
console.log('Calling minimizeToTray function');
await minimizeToTray();
console.log('Window should now be hidden and app should be in system tray');
} catch (error) {
console.error('Failed to minimize to tray on close:', error);
}
} else {
console.log('Minimize to tray setting is disabled, allowing window to close');
// Let the window close normally, but we need to call quit_app to ensure proper cleanup
try {
await invoke("quit_app");
@@ -149,7 +135,6 @@ function App() {
let unlistenFn;
setupCloseHandler().then(unlisten => {
unlistenFn = unlisten;
console.log('Close handler set up successfully');
}).catch(err => console.error('Failed to set up close handler:', err));
// Clean up event listener on unmount
@@ -163,7 +148,6 @@ function App() {
// Functions to handle cursor operations using Tauri backend
const selectCursor = async (index) => {
try {
console.log(`Selecting cursor at index ${index}`);
await invoke("select_cursor", { index });
setCurrentCursorIndex(index);
} catch (error) {
@@ -175,7 +159,6 @@ function App() {
if (cursors.length === 0) return;
try {
console.log('Switching to next cursor');
const newIndex = await invoke("next_cursor");
setCurrentCursorIndex(newIndex);
} catch (error) {
@@ -189,7 +172,6 @@ function App() {
// Function to exit app
const quitApp = async () => {
try {
console.log('Quitting app');
await invoke("quit_app");
} catch (error) {
console.error("Failed to quit app:", error);