From a75e7234160eadf0b6fb253a2253efc8d80480be Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Sun, 1 Nov 2026 12:14:23 +0100 Subject: [PATCH] chore(rust): resolve all clippy warnings across codebase --- src-tauri/src/commands.rs | 45 ++++++++++--------------- src-tauri/src/lib.rs | 5 ++- src-tauri/src/logging.rs | 2 +- src-tauri/src/macos.rs | 70 +++++++++++++++------------------------ src-tauri/src/presence.rs | 31 +++++++++-------- src-tauri/src/utils.rs | 27 +++++++-------- 6 files changed, 75 insertions(+), 105 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 21d3ef9..af80713 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -90,7 +90,6 @@ pub fn file_size(path: String) -> Option { pub fn get_hwid() -> String { get_id() .unwrap_or("recorderinsandybridge".to_string()) - .into() } /// Show the native macOS picker, which can select `osu!.app` bundles as files. @@ -374,8 +373,8 @@ pub async fn get_skins_count(folder: String) -> Option { let mut count = 0; if let Ok(mut entries) = fs::read_dir(skins_folder).await { while let Ok(Some(entry)) = entries.next_entry().await { - if let Ok(ft) = entry.file_type().await { - if ft.is_dir() { + if let Ok(ft) = entry.file_type().await + && ft.is_dir() { let dir_path = entry.path(); let has_ini = tokio::fs::try_exists(dir_path.join("skin.ini")) .await @@ -387,7 +386,6 @@ pub async fn get_skins_count(folder: String) -> Option { count += 1; } } - } } } Some(count) @@ -1596,8 +1594,8 @@ pub(crate) fn theme_root() -> Result { #[cfg(any(target_os = "linux", target_os = "macos"))] fn loopback_theme_asset_base() -> String { - if crate::theme_server::base_url().is_none() { - if let Ok(root) = theme_root() { + if crate::theme_server::base_url().is_none() + && let Ok(root) = theme_root() { match crate::theme_server::media_root() { Ok(media) => { if let Err(error) = crate::theme_server::start(root, media) { @@ -1609,7 +1607,6 @@ fn loopback_theme_asset_base() -> String { } } } - } crate::theme_server::base_url().unwrap_or_default() } @@ -1617,7 +1614,7 @@ fn loopback_theme_asset_base() -> String { pub fn theme_asset_base() -> String { #[cfg(any(target_os = "linux", target_os = "macos"))] { - return loopback_theme_asset_base(); + loopback_theme_asset_base() } #[cfg(not(any(target_os = "linux", target_os = "macos")))] @@ -1631,7 +1628,7 @@ pub fn theme_preview_url(path: String) -> Result { #[cfg(any(target_os = "linux", target_os = "macos"))] { let _ = loopback_theme_asset_base(); - return crate::theme_server::preview_url(Path::new(&path)); + crate::theme_server::preview_url(Path::new(&path)) } #[cfg(not(any(target_os = "linux", target_os = "macos")))] @@ -1915,9 +1912,8 @@ async fn download_ffmpeg(app: &AppHandle) -> Result { .await .map_err(|error| format!("Could not write the FFmpeg archive: {error}"))?; - if total > 0 { - let percent = ((received.min(total) * 100) / total) as u8; - if percent != last_percent { + if let Some(percent) = (received.min(total) * 100).checked_div(total).map(|v| v as u8) + && percent != last_percent { last_percent = percent; let _ = app.emit( "theme-media-progress", @@ -1927,7 +1923,6 @@ async fn download_ffmpeg(app: &AppHandle) -> Result { }, ); } - } } file.flush() @@ -2035,7 +2030,7 @@ fn optimize_theme_media_blocking( let codec = probe_text.lines().find_map(|line| { let index = line.find("Video: ")?; line[index + 7..] - .split(|character: char| character == ',' || character == ' ') + .split([',', ' ']) .next() .map(str::to_ascii_lowercase) }); @@ -2518,7 +2513,7 @@ pub async fn list_theme_backups(theme_folder: String) -> Result Result>(); - backups.sort_by(|a, b| b.created_at.cmp(&a.created_at)); + backups.sort_by_key(|b| std::cmp::Reverse(b.created_at)); Ok(backups) }) .await @@ -2699,13 +2694,11 @@ fn collect_theme_asset_refs(value: &Value, assets: &mut HashSet) { match value { Value::Object(object) => { for (key, value) in object { - if key == "src" || key == "preview" { - if let Some(src) = value.as_str() { - if let Some(path) = theme_asset_reference(src) { + if (key == "src" || key == "preview") + && let Some(src) = value.as_str() + && let Some(path) = theme_asset_reference(src) { assets.insert(path); } - } - } collect_theme_asset_refs(value, assets); } } @@ -2816,14 +2809,13 @@ fn add_theme_folder_to_zip( continue; } - if let Some(filter) = asset_filter { - if let Ok(asset_path) = entry_path.strip_prefix(&assets_root) { + if let Some(filter) = asset_filter + && let Ok(asset_path) = entry_path.strip_prefix(&assets_root) { let key = asset_path.to_string_lossy().replace('\\', "/"); if !filter.contains(&key) { continue; } } - } let relative = entry_path .strip_prefix(root) @@ -2938,7 +2930,6 @@ pub async fn reveal_window(window: tauri::WebviewWindow) -> Result<(), String> { { let res = crate::macos::activate_and_focus_window(&win); let _ = tx.send(res); - return; } #[cfg(not(target_os = "macos"))] diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index cf6cce4..67da2ed 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -227,8 +227,8 @@ pub fn run() { // The content view can be replaced again while the webview is being // built, so re-apply the corner mask once the app is ready. #[cfg(target_os = "macos")] - if let tauri::RunEvent::Ready = &event { - if let Some(window) = app.get_webview_window("main") { + if let tauri::RunEvent::Ready = &event + && let Some(window) = app.get_webview_window("main") { if let Err(error) = macos::round_window(&window, 12.0) { log::warn!(target: "launcher", "Could not round the launcher window: {error}"); } @@ -236,7 +236,6 @@ pub fn run() { log::warn!(target: "launcher", "{error}"); } } - } presence::handle_run_event(app, &event); }); diff --git a/src-tauri/src/logging.rs b/src-tauri/src/logging.rs index f147daf..ee56200 100644 --- a/src-tauri/src/logging.rs +++ b/src-tauri/src/logging.rs @@ -426,7 +426,7 @@ pub fn list_log_bundles() -> Result, String> { }) .collect::>(); - bundles.sort_by(|a, b| b.modified.cmp(&a.modified)); + bundles.sort_by_key(|b| std::cmp::Reverse(b.modified)); Ok(bundles) } diff --git a/src-tauri/src/macos.rs b/src-tauri/src/macos.rs index ff0d77c..afa1442 100644 --- a/src-tauri/src/macos.rs +++ b/src-tauri/src/macos.rs @@ -291,17 +291,15 @@ impl WineRuntime { if let Ok(rel) = canon_path.strip_prefix(&canon_drive_c) { return format!("C:\\{}", rel.display()).replace('/', "\\"); } - if let Ok(rel) = path.strip_prefix(&self.prefix.join("drive_c")) { + if let Ok(rel) = path.strip_prefix(self.prefix.join("drive_c")) { return format!("C:\\{}", rel.display()).replace('/', "\\"); } if let Some(drive_c_ancestor) = canon_path .ancestors() .find(|a| a.file_name() == Some(OsStr::new("drive_c"))) - { - if let Ok(rel) = canon_path.strip_prefix(drive_c_ancestor) { + && let Ok(rel) = canon_path.strip_prefix(drive_c_ancestor) { return format!("C:\\{}", rel.display()).replace('/', "\\"); } - } // If outside drive_c, Wine maps the Unix root filesystem to Z:\ let path_display = canon_path.display().to_string(); @@ -521,9 +519,9 @@ pub async fn prepare_osu_environment(folder: &Path, runtime: &WineRuntime) { // 3. Reset update fail count in osu!.cfg let cfg_path = folder.join("osu!.cfg"); - if cfg_path.is_file() { - if let Ok(content) = fs::read_to_string(&cfg_path) { - if content.contains("_UpdateFailCount") { + if cfg_path.is_file() + && let Ok(content) = fs::read_to_string(&cfg_path) + && content.contains("_UpdateFailCount") { let updated = content .lines() .map(|line| { @@ -537,42 +535,36 @@ pub async fn prepare_osu_environment(folder: &Path, runtime: &WineRuntime) { .join("\n"); let _ = fs::write(&cfg_path, updated); } - } - } // 4. Update execute.bat if present to use ez-pp.farm let bat_path = folder.join("execute.bat"); - if bat_path.is_file() { - if let Ok(content) = fs::read_to_string(&bat_path) { - if content.contains("lucoa.best") { + if bat_path.is_file() + && let Ok(content) = fs::read_to_string(&bat_path) + && content.contains("lucoa.best") { let updated = content.replace("lucoa.best", "ez-pp.farm"); let _ = fs::write(&bat_path, updated); } - } - } } async fn clean_wine_font_registry(runtime: &WineRuntime) { let mut needs_clean = false; for reg_name in &["user.reg", "system.reg"] { let reg_path = runtime.prefix.join(reg_name); - if reg_path.is_file() { - if let Ok(content) = fs::read_to_string(®_path) { - if content.contains("Apple Braille") { + if reg_path.is_file() + && let Ok(content) = fs::read_to_string(®_path) + && content.contains("Apple Braille") { needs_clean = true; break; } - } - } } if needs_clean { runtime.kill_prefix().await; for reg_name in &["user.reg", "system.reg"] { let reg_path = runtime.prefix.join(reg_name); - if reg_path.is_file() { - if let Ok(content) = fs::read_to_string(®_path) { - if content.contains("Apple Braille") { + if reg_path.is_file() + && let Ok(content) = fs::read_to_string(®_path) + && content.contains("Apple Braille") { let cleaned: String = content .lines() .filter(|line| !line.contains("Apple Braille")) @@ -585,8 +577,6 @@ async fn clean_wine_font_registry(runtime: &WineRuntime) { reg_path.display() ); } - } - } } } } @@ -660,8 +650,8 @@ pub async fn run_osu(osu_folder: &str, patch: bool) -> Result<(), String> { let start_time = Instant::now(); let mut wait_result = game.wait().await; - if let Ok(status) = &wait_result { - if status.code() == Some(5) && start_time.elapsed() < StdDuration::from_secs(6) { + if let Ok(status) = &wait_result + && status.code() == Some(5) && start_time.elapsed() < StdDuration::from_secs(6) { log::warn!( target: "osu", "osu! exited early with status 5 during Wine cold start; retrying now that Wine runtime is initialized..." @@ -683,7 +673,6 @@ pub async fn run_osu(osu_folder: &str, patch: bool) -> Result<(), String> { wait_result = retry_game.wait().await; } - } match &wait_result { Ok(status) => log::info!(target: "osu", "osu! loader exited with {status}"), @@ -836,7 +825,7 @@ async fn wait_for_osu_game() -> bool { sys.refresh_processes(sysinfo::ProcessesToUpdate::All, true); - for (_pid, process) in sys.processes() { + for process in sys.processes().values() { if crate::utils::is_osu_process(process) || process.name() == "osu!.exe" { let pid = process.pid(); let title = crate::utils::get_window_title_by_pid(pid); @@ -932,17 +921,15 @@ pub fn resolve_osu_folder(folder: &Path) -> Option { let mut prefixes = Vec::new(); - if folder.file_name() == Some(OsStr::new("drive_c")) { - if let Some(parent) = canonical_prefix(folder) { + if folder.file_name() == Some(OsStr::new("drive_c")) + && let Some(parent) = canonical_prefix(folder) { prefixes.push(parent); } - } - if folder.join("drive_c").is_dir() { - if let Some(parent) = canonical_prefix(&folder.join("drive_c")) { + if folder.join("drive_c").is_dir() + && let Some(parent) = canonical_prefix(&folder.join("drive_c")) { prefixes.push(parent); } - } if folder.extension() == Some(OsStr::new("app")) || folder.join("Contents").is_dir() { for drive_c in [ @@ -950,11 +937,10 @@ pub fn resolve_osu_folder(folder: &Path) -> Option { folder.join("Contents/SharedSupport/drive_c"), folder.join("Contents/SharedSupport/prefix/drive_c"), ] { - if drive_c.is_dir() { - if let Some(parent) = canonical_prefix(&drive_c) { + if drive_c.is_dir() + && let Some(parent) = canonical_prefix(&drive_c) { prefixes.push(parent); } - } } let mut drive_dirs = Vec::new(); @@ -1093,11 +1079,10 @@ fn find_drive_c_dirs(dir: &Path, depth: usize, out: &mut Vec) { // Wineskin wrappers often add a convenience drive_c symlink at // the app root. Resolve it to the real prefix so WINEPREFIX points // at Contents/Resources instead of the bundle itself. - if path.file_name() == Some(OsStr::new("drive_c")) { - if let Ok(canonical) = fs::canonicalize(&path) { + if path.file_name() == Some(OsStr::new("drive_c")) + && let Ok(canonical) = fs::canonicalize(&path) { out.push(canonical); } - } continue; } @@ -1246,12 +1231,11 @@ fn find_wine_bin(prefix: &Path, app: Option<&Path>) -> Option<(PathBuf, Option

), Disconnect(oneshot::Sender<()>), - UpdateData(PresenceData), + UpdateData(Box), IsConnected(oneshot::Sender), } enum ReconnectResult { - Connected(AsyncDiscordIpcClient), + Connected(Box), Failed, } @@ -103,7 +103,7 @@ impl PresenceActor { PresenceCommand::Connect(resp) => self.cmd_connect(resp).await, PresenceCommand::Disconnect(resp) => self.cmd_disconnect(resp).await, PresenceCommand::UpdateData(data) => { - self.data = data; + self.data = *data; self.push_presence().await; } PresenceCommand::IsConnected(resp) => { @@ -117,7 +117,7 @@ impl PresenceActor { match result { ReconnectResult::Connected(client) => { log::info!(target: "launcher", "Presence: reconnect succeeded"); - self.client = Some(client); + self.client = Some(*client); self.push_presence().await; } ReconnectResult::Failed => { @@ -188,16 +188,14 @@ impl PresenceActor { builder = builder.small_text(text); } - if let Some(btn) = &self.data.dynamic_button { - if !btn.label.trim().is_empty() && !btn.url.trim().is_empty() { + if let Some(btn) = &self.data.dynamic_button + && !btn.label.trim().is_empty() && !btn.url.trim().is_empty() { builder = builder.button(&btn.label, &btn.url); } - } - if let Some(btn2) = &self.data.secondary_button { - if !btn2.label.trim().is_empty() && !btn2.url.trim().is_empty() { + if let Some(btn2) = &self.data.secondary_button + && !btn2.label.trim().is_empty() && !btn2.url.trim().is_empty() { builder = builder.button(&btn2.label, &btn2.url); } - } let activity = builder.build(); @@ -233,7 +231,7 @@ impl PresenceActor { tokio::time::sleep(delay).await; if let Some(client) = try_connect_once().await { - let _ = tx.send(ReconnectResult::Connected(client)).await; + let _ = tx.send(ReconnectResult::Connected(Box::new(client))).await; return; } } @@ -302,6 +300,7 @@ pub async fn has_presence() -> bool { false } +#[allow(clippy::too_many_arguments)] pub fn update_activity( state: Option<&str>, details: Option<&str>, @@ -347,7 +346,7 @@ pub fn update_activity( let tx = PRESENCE_TX.clone(); tokio::spawn(async move { - let _ = tx.send(PresenceCommand::UpdateData(data)).await; + let _ = tx.send(PresenceCommand::UpdateData(Box::new(data))).await; }); } @@ -368,7 +367,7 @@ pub fn update_status(state: Option<&str>, details: Option<&str>, large_image_key let tx = PRESENCE_TX.clone(); tokio::spawn(async move { - let _ = tx.send(PresenceCommand::UpdateData(data)).await; + let _ = tx.send(PresenceCommand::UpdateData(Box::new(data))).await; }); } @@ -382,7 +381,7 @@ pub fn update_user(username: Option<&str>, id: Option<&str>) { let tx = PRESENCE_TX.clone(); tokio::spawn(async move { - let _ = tx.send(PresenceCommand::UpdateData(data)).await; + let _ = tx.send(PresenceCommand::UpdateData(Box::new(data))).await; }); } @@ -398,7 +397,7 @@ pub fn set_button(label: &str, url: &str) { let tx = PRESENCE_TX.clone(); tokio::spawn(async move { - let _ = tx.send(PresenceCommand::UpdateData(data)).await; + let _ = tx.send(PresenceCommand::UpdateData(Box::new(data))).await; }); } @@ -411,7 +410,7 @@ pub fn clear_button() { let tx = PRESENCE_TX.clone(); tokio::spawn(async move { - let _ = tx.send(PresenceCommand::UpdateData(data)).await; + let _ = tx.send(PresenceCommand::UpdateData(Box::new(data))).await; }); } diff --git a/src-tauri/src/utils.rs b/src-tauri/src/utils.rs index c5be048..8ac1d9d 100644 --- a/src-tauri/src/utils.rs +++ b/src-tauri/src/utils.rs @@ -40,15 +40,14 @@ pub fn is_osu_process(process: &sysinfo::Process) -> bool { return true; } - if let Some(exe) = process.exe() { - if exe + if let Some(exe) = process.exe() + && exe .file_name() .map(|file_name| file_name.to_string_lossy().to_ascii_lowercase() == "osu!.exe") .unwrap_or(false) { return true; } - } process.cmd().iter().any(|arg| { arg.to_string_lossy() @@ -103,7 +102,7 @@ fn find_osu_user_config_path>(folder_path: P) -> Option }) .collect::>(); - candidates.sort_by(|a, b| b.0.cmp(&a.0)); + candidates.sort_by_key(|b| std::cmp::Reverse(b.0)); candidates.into_iter().next().map(|(_, path)| path) } @@ -261,7 +260,7 @@ pub fn get_osu_config>( } } - return Some(config_map); + Some(config_map) } #[cfg(target_os = "linux")] @@ -469,7 +468,7 @@ pub fn get_window_title_by_pid(target_pid: Pid) -> String { } else { 0 }; - if layer < 0 || layer > 50 { + if !(0..=50).contains(&layer) { continue; } @@ -477,8 +476,8 @@ pub fn get_window_title_by_pid(target_pid: Pid) -> String { let name_str: *mut AnyObject = msg_send![dict, objectForKey: name_key]; if !name_str.is_null() { let utf8: *const std::ffi::c_char = msg_send![name_str, UTF8String]; - if !utf8.is_null() { - if let Ok(s) = CStr::from_ptr(utf8).to_str() { + if !utf8.is_null() + && let Ok(s) = CStr::from_ptr(utf8).to_str() { let trimmed = s.trim(); if !trimmed.is_empty() { if trimmed.to_lowercase().contains("updater") { @@ -489,7 +488,6 @@ pub fn get_window_title_by_pid(target_pid: Pid) -> String { } } } - } } // 2. Check window bounds @@ -723,6 +721,7 @@ pub fn is_compatible_patcher(data: &[u8]) -> bool { /// 2. `GetOsuPid()` checks for `" -devserver "` via PEB reading, which fails or is unreliable under Wine. /// 3. Costura embeds `ManagedInjector.Lib` which also calls generic `Marshal.SizeOf()` /// and parses remote PE export tables through generic marshal APIs. +/// /// This function patches the binary in-place so it runs reliably under Wine. pub fn ensure_patcher_compatibility(patcher_exe: &Path) -> Result { if !patcher_exe.is_file() { @@ -828,9 +827,9 @@ pub fn ensure_patcher_compatibility(patcher_exe: &Path) -> Result if inner_modified { let mut encoder = DeflateEncoder::new(Vec::new(), Compression::best()); - if encoder.write_all(&decomp).is_ok() { - if let Ok(mut compressed) = encoder.finish() { - if compressed.len() <= 10020 - 5 { + if encoder.write_all(&decomp).is_ok() + && let Ok(mut compressed) = encoder.finish() + && compressed.len() <= 10020 - 5 { let remaining = 10020 - compressed.len(); let length = (remaining - 5) as u16; let nlen = !length; @@ -839,14 +838,12 @@ pub fn ensure_patcher_compatibility(patcher_exe: &Path) -> Result compressed.push((length >> 8) as u8); compressed.push((nlen & 0xff) as u8); compressed.push((nlen >> 8) as u8); - compressed.extend(std::iter::repeat(0x00).take(length as usize)); + compressed.extend(std::iter::repeat_n(0x00, length as usize)); if compressed.len() == 10020 { data[0x1f00..0x1f00 + 10020].copy_from_slice(&compressed); modified = true; } } - } - } } } }