Clean up unused code: Remove unused imports, static variables, functions, and fields

This commit is contained in:
2025-05-05 20:08:08 -05:00
parent 852ee64932
commit 83288b8791
2 changed files with 3 additions and 98 deletions
-34
View File
@@ -59,7 +59,6 @@ struct CursorRush {
shared_state: Option<Arc<Mutex<SharedState>>>,
main_window: Option<iced::window::Id>, // Store the main window ID
tray_icon: Option<TrayIcon>, // Store the TrayIcon object to keep it alive
tray_tx: Option<mpsc::UnboundedSender<Message>>, // Sender for tray events
}
// Make sure the default impl initializes tray_icon to None
@@ -71,7 +70,6 @@ impl Default for CursorRush {
shared_state: None,
main_window: None,
tray_icon: None, // Initialize as None
tray_tx: None, // Initialize as None
}
}
}
@@ -163,28 +161,11 @@ fn apply_cursor(path: &Path) -> bool {
}
// Global channel for tray events
use std::sync::Once;
use std::sync::atomic::{AtomicBool, Ordering};
use once_cell::sync::Lazy;
static INIT: Once = Once::new();
static INITIALIZED: AtomicBool = AtomicBool::new(false);
static TRAY_SENDER: Lazy<std::sync::Mutex<Option<mpsc::UnboundedSender<Message>>>> =
Lazy::new(|| std::sync::Mutex::new(None));
// Function to get or create the global tray sender
fn get_tray_sender() -> mpsc::UnboundedSender<Message> {
if !INITIALIZED.load(Ordering::SeqCst) {
INIT.call_once(|| {
let (tx, _) = mpsc::unbounded();
*TRAY_SENDER.lock().unwrap() = Some(tx);
INITIALIZED.store(true, Ordering::SeqCst);
});
}
TRAY_SENDER.lock().unwrap().clone().unwrap()
}
// Top-level subscription function to listen for events
fn subscription(_state: &CursorRush) -> Subscription<Message> {
// Create a vector to hold all subscriptions
@@ -596,21 +577,6 @@ fn hide_window_to_tray(window_id: iced::window::Id) -> Task<Message> {
})
}
// Helper function to show a window from the tray
fn show_window_from_tray(window_id: iced::window::Id) -> Task<Message> {
println!("Attempting to show window with ID: {:?}", window_id);
// Use ONLY the iced methods for showing and focusing.
let show_task: Task<()> = iced::window::change_mode(window_id, iced::window::Mode::Windowed);
let focus_task: Task<()> = iced::window::gain_focus(window_id);
Task::batch(vec![show_task, focus_task]).map(|_: ()| {
println!("Window show/focus tasks completed (via iced)");
// Return a specific message to confirm the window was shown
Message::WindowShown
})
}
// Update function to handle messages
fn update(state: &mut CursorRush, message: Message) -> Task<Message> {
match message {
+3 -64
View File
@@ -668,19 +668,6 @@ mod windows {
}
}
// Main set_cursor function - now uses the separate functions
pub fn set_cursor(path: &Path) -> bool {
// First, ensure system cursor is hidden (only happens once)
if !unsafe { CURSOR_HIDDEN } {
if !hide_system_cursor() {
return false;
}
}
// Then update the cursor image
update_cursor_image(path)
}
// Function to restore the cursor when the program exits
pub fn restore_cursor() {
println!("Explicit restore_cursor called");
@@ -836,14 +823,6 @@ mod macos {
false
}
pub fn set_cursor(_path: &Path) -> bool {
// macOS cursor implementation would go here
// This is a placeholder - actual implementation would require
// Objective-C/Cocoa bindings to NSCursor
println!("macOS cursor swapping not yet implemented");
false
}
pub fn restore_cursor() {
// Placeholder for restoring cursor on macOS
println!("macOS cursor restoration not yet implemented");
@@ -874,14 +853,6 @@ mod linux {
false
}
pub fn set_cursor(_path: &Path) -> bool {
// Linux cursor implementation would go here
// This is a placeholder - actual implementation would require
// X11 or Wayland bindings
println!("Linux cursor swapping not yet implemented");
false
}
pub fn restore_cursor() {
// Placeholder for restoring cursor on Linux
println!("Linux cursor restoration not yet implemented");
@@ -893,41 +864,15 @@ mod linux {
}
}
// Windows-specific function to hide a window - DEPRECATED
// We now use iced's window::change_mode instead for cross-platform compatibility
#[cfg(windows)]
pub fn hide_window() {
println!("WARNING: platform::hide_window is deprecated. Use iced::window::change_mode instead.");
}
// Windows-specific function to show a window - DEPRECATED
// We now use iced's window::change_mode instead for cross-platform compatibility
#[cfg(windows)]
pub fn show_window() {
println!("WARNING: platform::show_window is deprecated. Use iced::window::change_mode instead.");
}
// Placeholder for non-Windows platforms - DEPRECATED
#[cfg(not(windows))]
pub fn hide_window() {
println!("WARNING: platform::hide_window is deprecated. Use iced::window::change_mode instead.");
}
// Placeholder for non-Windows platforms - DEPRECATED
#[cfg(not(windows))]
pub fn show_window() {
println!("WARNING: platform::show_window is deprecated. Use iced::window::change_mode instead.");
}
// Export the appropriate implementation based on platform
#[cfg(windows)]
pub use windows::{set_cursor, restore_cursor, render_cursor, hide_system_cursor, update_cursor_image};
pub use windows::{restore_cursor, render_cursor, hide_system_cursor, update_cursor_image};
#[cfg(target_os = "macos")]
pub use macos::{set_cursor, restore_cursor, render_cursor, hide_system_cursor, update_cursor_image};
pub use macos::{restore_cursor, render_cursor, hide_system_cursor, update_cursor_image};
#[cfg(target_os = "linux")]
pub use linux::{set_cursor, restore_cursor, render_cursor, hide_system_cursor, update_cursor_image};
pub use linux::{restore_cursor, render_cursor, hide_system_cursor, update_cursor_image};
// Default implementation for other platforms
#[cfg(not(any(windows, target_os = "macos", target_os = "linux")))]
@@ -942,12 +887,6 @@ pub fn update_cursor_image(_path: &Path) -> bool {
false
}
#[cfg(not(any(windows, target_os = "macos", target_os = "linux")))]
pub fn set_cursor(_path: &Path) -> bool {
println!("Cursor swapping not supported on this platform");
false
}
#[cfg(not(any(windows, target_os = "macos", target_os = "linux")))]
pub fn restore_cursor() {
println!("Cursor restoration not supported on this platform");