diff --git a/Cargo.toml b/Cargo.toml index ac94097..46846b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "envision" version = "3.2.0" -edition = "2021" +edition = "2024" authors = [ "Gabriele Musco ", ] diff --git a/src/depcheck/mod.rs b/src/depcheck/mod.rs index c7d9f79..962615d 100644 --- a/src/depcheck/mod.rs +++ b/src/depcheck/mod.rs @@ -72,15 +72,14 @@ impl Dependency { } pub fn package_name_for_distro(&self, distro: Option<&LinuxDistro>) -> String { - if let Some(distro) = distro { - if let Some(pname) = self + if let Some(distro) = distro + && let Some(pname) = self .packages .iter() .find(|(k, _)| *k == distro) .map(|(_, v)| v) - { - return pname.clone(); - } + { + return pname.clone(); } self.name.clone() } diff --git a/src/file_builders/openvrpaths_vrpath.rs b/src/file_builders/openvrpaths_vrpath.rs index 1b888c2..3b8c692 100644 --- a/src/file_builders/openvrpaths_vrpath.rs +++ b/src/file_builders/openvrpaths_vrpath.rs @@ -42,13 +42,13 @@ fn get_backed_up_steam_openvrpaths() -> Option { } fn backup_steam_openvrpaths() { - if let Some(openvrpaths) = get_current_openvrpaths() { - if is_steam(&openvrpaths) { - copy_file( - &get_openvrpaths_vrpath_path(), - &get_backup_steam_openvrpaths_path(), - ); - } + if let Some(openvrpaths) = get_current_openvrpaths() + && is_steam(&openvrpaths) + { + copy_file( + &get_openvrpaths_vrpath_path(), + &get_backup_steam_openvrpaths_path(), + ); } } diff --git a/src/gpu_profile.rs b/src/gpu_profile.rs index 98eea11..d8ea8a3 100644 --- a/src/gpu_profile.rs +++ b/src/gpu_profile.rs @@ -141,14 +141,14 @@ pub fn get_first_amd_gpu() -> Option { pub fn get_amd_gpu_power_profile() -> Option { let amd_gpu = get_first_amd_gpu(); - if let Some(GpuSysDrm::Amd(card_dir)) = amd_gpu { - if let Some(mut reader) = get_reader(&power_profile_mode_file(&card_dir)) { - let mut txt = String::new(); - reader.read_to_string(&mut txt).ok()?; - for line in txt.split('\n') { - if let Ok(pp) = GpuPowerProfile::from_str(line) { - return Some(pp); - } + if let Some(GpuSysDrm::Amd(card_dir)) = amd_gpu + && let Some(mut reader) = get_reader(&power_profile_mode_file(&card_dir)) + { + let mut txt = String::new(); + reader.read_to_string(&mut txt).ok()?; + for line in txt.split('\n') { + if let Ok(pp) = GpuPowerProfile::from_str(line) { + return Some(pp); } } } diff --git a/src/main.rs b/src/main.rs index 64a6e59..b9d3e66 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,12 +63,11 @@ fn restore_steam_xr_files() { if let Err(e) = restore_active_runtime_backup() { warn!("failed to restore active runtime to steam: {e}"); } - if let Some(ovrp) = openvrpaths { - if !file_builders::openvrpaths_vrpath::is_steam(&ovrp) { - if let Err(e) = set_current_openvrpaths_to_steam() { - warn!("failed to restore openvrpaths to steam: {e}"); - } - } + if let Some(ovrp) = openvrpaths + && !file_builders::openvrpaths_vrpath::is_steam(&ovrp) + && let Err(e) = set_current_openvrpaths_to_steam() + { + warn!("failed to restore openvrpaths to steam: {e}"); } restore_sniper_runtime_entrypoint(); restore_soldier_runtime_entrypoint(); diff --git a/src/ui/app.rs b/src/ui/app.rs index c905ba2..8396370 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -995,14 +995,14 @@ impl AsyncComponent for App { self.wivrn_conf_editor = Some(editor); } Msg::HandleCommandLine(opts) => { - if let Some(prof_uuid) = opts.profile_uuid { - if let Some(index) = self.profiles.iter().position(|p| p.uuid == prof_uuid) { - let target = self.profiles.get(index).unwrap(); - sender.input(Msg::ProfileSelected(target.clone())); - self.main_view - .sender() - .emit(MainViewMsg::SetSelectedProfile(index as u32)); - } + if let Some(prof_uuid) = opts.profile_uuid + && let Some(index) = self.profiles.iter().position(|p| p.uuid == prof_uuid) + { + let target = self.profiles.get(index).unwrap(); + sender.input(Msg::ProfileSelected(target.clone())); + self.main_view + .sender() + .emit(MainViewMsg::SetSelectedProfile(index as u32)); } if opts.start { sender.input(Msg::DoStartStopXRService) diff --git a/src/ui/install_wivrn_box.rs b/src/ui/install_wivrn_box.rs index 769e012..d4f827c 100644 --- a/src/ui/install_wivrn_box.rs +++ b/src/ui/install_wivrn_box.rs @@ -183,10 +183,10 @@ impl AsyncComponent for InstallWivrnBox { Err(GetWivrnApkRefErr::RepoManipulationFailed(giterr)) => { error!("failed to manipulate WiVRn repo: {giterr}, falling back to latest release APK"); let existing = cache_file_path(WIVRN_LATEST_RELEASE_APK_URL, Some("apk")); - if existing.is_file() { - if let Err(e) = remove_file(&existing) { - error!("failed to remove file {}: {e}", existing.to_string_lossy()); - } + if existing.is_file() + && let Err(e) = remove_file(&existing) + { + error!("failed to remove file {}: {e}", existing.to_string_lossy()); } sender.input(Self::Input::DoInstall(WIVRN_LATEST_RELEASE_APK_URL.into())); } diff --git a/src/ui/job_worker/mod.rs b/src/ui/job_worker/mod.rs index c50ab21..96f0c82 100644 --- a/src/ui/job_worker/mod.rs +++ b/src/ui/job_worker/mod.rs @@ -103,14 +103,16 @@ impl JobWorker { let state = self.state.clone(); thread::spawn(move || { sleep(Duration::from_secs(2)); - if let Ok(s) = state.lock() { - if !s.exited { - // process is still alive - warn!("process is still alive 2 seconds after SIGTERM, proceeding to send SIGKILL..."); - if let Err(e) = kill(pid, SIGKILL) { - error!("failed to send SIGKILL: {e}"); - }; - } + if let Ok(s) = state.lock() + && !s.exited + { + // process is still alive + warn!( + "process is still alive 2 seconds after SIGTERM, proceeding to send SIGKILL..." + ); + if let Err(e) = kill(pid, SIGKILL) { + error!("failed to send SIGKILL: {e}"); + }; } }); } diff --git a/src/ui/libsurvive_setup_window.rs b/src/ui/libsurvive_setup_window.rs index aaf0547..bde1503 100644 --- a/src/ui/libsurvive_setup_window.rs +++ b/src/ui/libsurvive_setup_window.rs @@ -420,12 +420,12 @@ impl SimpleComponent for LibsurviveSetupWindow { Some(&self.win.as_ref().unwrap().clone()), gtk::gio::Cancellable::NONE, move |res| { - if let Ok(file) = res { - if let Some(path) = file.path() { - fd_sender.input(LibsurviveSetupMsg::SetSteamLighthousePath(Some( - path.to_str().unwrap().to_string(), - ))) - } + if let Ok(file) = res + && let Some(path) = file.path() + { + fd_sender.input(LibsurviveSetupMsg::SetSteamLighthousePath(Some( + path.to_str().unwrap().to_string(), + ))) } }, ); diff --git a/src/ui/main_view.rs b/src/ui/main_view.rs index a7bbe32..bb032e6 100644 --- a/src/ui/main_view.rs +++ b/src/ui/main_view.rs @@ -786,24 +786,17 @@ impl AsyncComponent for MainView { gtk::gio::Cancellable::NONE, move |res| { if let Ok(file) = res { - if let Some(path) = file.path() { - if let Ok(mut writer) = get_writer(&path) { - if let Ok(s) = serde_json::to_string_pretty(&prof) { - let prof_id = prof.uuid; - let s = s - .replace( - get_data_dir().to_string_lossy().as_ref(), - "@DATADIR@", - ) - .replace( - get_home_dir().to_string_lossy().as_ref(), - "@HOMEDIR@", - ) - .replace(&prof_id, "@UUID@"); - if writer.write_all(s.as_bytes()).is_ok() { - return; - } - } + if let Some(path) = file.path() + && let Ok(mut writer) = get_writer(&path) + && let Ok(s) = serde_json::to_string_pretty(&prof) + { + let prof_id = prof.uuid; + let s = s + .replace(get_data_dir().to_string_lossy().as_ref(), "@DATADIR@") + .replace(get_home_dir().to_string_lossy().as_ref(), "@HOMEDIR@") + .replace(&prof_id, "@UUID@"); + if writer.write_all(s.as_bytes()).is_ok() { + return; } } alert("Failed to export profile", None, Some(&root_win)); @@ -850,22 +843,22 @@ impl AsyncComponent for MainView { gtk::gio::Cancellable::NONE, move |res| { if let Ok(file) = res { - if let Some(path) = file.path() { - if let Ok(s) = read_to_string(path) { - let s = s - .replace( - "@DATADIR@", - get_data_dir().to_string_lossy().as_ref(), - ) - .replace( - "@HOMEDIR@", - get_home_dir().to_string_lossy().as_ref(), - ) - .replace("@UUID@", &Profile::new_uuid()); - if let Ok(nprof) = serde_json::from_str::(&s) { - fd_sender.input(Self::Input::OpenProfileEditor(nprof)); - return; - } + if let Some(path) = file.path() + && let Ok(s) = read_to_string(path) + { + let s = s + .replace( + "@DATADIR@", + get_data_dir().to_string_lossy().as_ref(), + ) + .replace( + "@HOMEDIR@", + get_home_dir().to_string_lossy().as_ref(), + ) + .replace("@UUID@", &Profile::new_uuid()); + if let Ok(nprof) = serde_json::from_str::(&s) { + fd_sender.input(Self::Input::OpenProfileEditor(nprof)); + return; } } alert("Failed to import profile", None, Some(&root_win)); diff --git a/src/ui/plugins/store.rs b/src/ui/plugins/store.rs index 0faf99a..168000a 100644 --- a/src/ui/plugins/store.rs +++ b/src/ui/plugins/store.rs @@ -385,17 +385,18 @@ impl AsyncComponent for PluginStore { } if let Some(exec) = plugin.executable() { // delete executable only if it's not a custom plugin - if exec.is_file() && plugin.exec_url.is_some() { - if let Err(e) = remove_file(&exec) { - alert( - "Failed removing plugin", - Some(&format!( - "Could not remove plugin executable {}:\n\n{e}", - exec.to_string_lossy() - )), - Some(&self.win.as_ref().unwrap().clone().upcast::()), - ); - } + if exec.is_file() + && plugin.exec_url.is_some() + && let Err(e) = remove_file(&exec) + { + alert( + "Failed removing plugin", + Some(&format!( + "Could not remove plugin executable {}:\n\n{e}", + exec.to_string_lossy() + )), + Some(&self.win.as_ref().unwrap().clone().upcast::()), + ); } } self.config_plugins.remove(&plugin.appid); diff --git a/src/ui/plugins/store_detail.rs b/src/ui/plugins/store_detail.rs index 4bd9d9f..b0906a2 100644 --- a/src/ui/plugins/store_detail.rs +++ b/src/ui/plugins/store_detail.rs @@ -246,15 +246,14 @@ impl AsyncComponent for StoreDetail { match message { Self::Input::OpenHomepage => { - if let Some(plugin) = self.plugin.as_ref() { - if let Some(homepage) = plugin.homepage_url.as_ref() { - if let Err(e) = gtk::gio::AppInfo::launch_default_for_uri( - homepage, - gtk::gio::AppLaunchContext::NONE, - ) { - error!("opening uri {homepage}: {e}"); - }; - } + if let Some(plugin) = self.plugin.as_ref() + && let Some(homepage) = plugin.homepage_url.as_ref() + && let Err(e) = gtk::gio::AppInfo::launch_default_for_uri( + homepage, + gtk::gio::AppLaunchContext::NONE, + ) + { + error!("opening uri {homepage}: {e}"); } } Self::Input::SetPlugin(p, enabled, needs_update) => { diff --git a/src/ui/preference_rows.rs b/src/ui/preference_rows.rs index bace44c..b4ab4b4 100644 --- a/src/ui/preference_rows.rs +++ b/src/ui/preference_rows.rs @@ -229,12 +229,12 @@ pub fn file_row) + 'static + Clone>( #[strong] cb, move |res| { - if let Ok(file) = res { - if let Some(path) = file.path() { - let path_s = path.to_string_lossy().to_string(); - path_label.set_text(&path_s); - cb(Some(path_s)) - } + if let Ok(file) = res + && let Some(path) = file.path() + { + let path_s = path.to_string_lossy().to_string(); + path_label.set_text(&path_s); + cb(Some(path_s)) } } ), @@ -271,12 +271,12 @@ pub fn path_row) + 'static + Clone>( #[strong] cb, move |res| { - if let Ok(file) = res { - if let Some(path) = file.path() { - let path_s = path.to_string_lossy().to_string(); - path_label.set_text(&path_s); - cb(Some(path_s)) - } + if let Ok(file) = res + && let Some(path) = file.path() + { + let path_s = path.to_string_lossy().to_string(); + path_label.set_text(&path_s); + cb(Some(path_s)) } } ), diff --git a/src/util/file_utils.rs b/src/util/file_utils.rs index 04efb13..951493b 100644 --- a/src/util/file_utils.rs +++ b/src/util/file_utils.rs @@ -13,10 +13,10 @@ use std::{ use tracing::{debug, error}; pub fn get_writer(path: &Path) -> anyhow::Result> { - if let Some(parent) = path.parent() { - if !parent.is_dir() { - create_dir_all(parent)?; - } + if let Some(parent) = path.parent() + && !parent.is_dir() + { + create_dir_all(parent)?; }; if path.is_symlink() { bail!( @@ -151,11 +151,11 @@ pub fn rm_rf(path: &Path) { } pub fn copy_file(source: &Path, dest: &Path) { - if let Some(parent) = dest.parent() { - if !parent.is_dir() { - create_dir_all(parent) - .unwrap_or_else(|_| panic!("Failed to create dir {}", parent.to_str().unwrap())); - } + if let Some(parent) = dest.parent() + && !parent.is_dir() + { + create_dir_all(parent) + .unwrap_or_else(|_| panic!("Failed to create dir {}", parent.to_str().unwrap())); } if !dest.is_symlink() { set_file_readonly(dest, false)