From 4659eca89c157c679f8ac2b8922f0cf640d760ce Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Tue, 15 Aug 2023 17:16:41 +0000 Subject: [PATCH] fix: lots of clippy errors --- src/adb.rs | 5 +- src/build_tools/cmake.rs | 4 +- src/build_tools/git.rs | 14 ++--- src/builders/build_basalt.rs | 16 ++--- src/builders/build_libsurvive.rs | 16 ++--- src/builders/build_mercury.rs | 5 +- src/builders/build_monado.rs | 18 +++--- src/builders/build_opencomposite.rs | 16 ++--- src/builders/build_wivrn.rs | 18 +++--- src/config.rs | 10 +-- src/depcheck.rs | 2 +- src/downloader.rs | 2 +- src/file_builders/active_runtime_json.rs | 15 ++--- src/file_builders/openvrpaths_vrpath.rs | 22 +++---- src/file_utils.rs | 32 ++++------ src/log_level.rs | 25 +++++--- src/log_parser.rs | 2 +- src/main.rs | 8 +-- src/profile.rs | 2 +- src/runner.rs | 16 ++--- src/runner_pipeline.rs | 9 +-- src/ui/alert.rs | 4 +- src/ui/app.rs | 39 +++++------- src/ui/build_window.rs | 2 +- src/ui/debug_view.rs | 13 ++-- src/ui/install_wivrn_box.rs | 20 ++---- src/ui/libsurvive_setup_window.rs | 77 +++++++++++------------- src/ui/main_view.rs | 2 +- src/ui/preference_rows.rs | 41 +++++-------- src/ui/profile_editor.rs | 4 +- src/ui/util.rs | 9 +-- src/ui/wivrn_conf_editor.rs | 13 ++-- src/xr_devices.rs | 18 +----- 33 files changed, 197 insertions(+), 302 deletions(-) diff --git a/src/adb.rs b/src/adb.rs index f1fe7ed..ba6c2fb 100644 --- a/src/adb.rs +++ b/src/adb.rs @@ -4,10 +4,9 @@ use std::path::Path; pub fn get_adb_install_runner(apk_path: &String) -> Runner { let path = Path::new(apk_path); path.try_exists().expect("APK file provided does not exist"); - let runner = Runner::new( + Runner::new( None, "adb".into(), vec!["install".into(), path.to_str().unwrap().to_string()], - ); - runner + ) } diff --git a/src/build_tools/cmake.rs b/src/build_tools/cmake.rs index 83cf9a9..6d69cd3 100644 --- a/src/build_tools/cmake.rs +++ b/src/build_tools/cmake.rs @@ -19,10 +19,10 @@ impl Cmake { ]; if self.vars.is_some() { for (k, v) in self.vars.as_ref().unwrap() { - if k.contains(" ") { + if k.contains(' ') { panic!("Cmake vars cannot contain spaces!"); } - if v.contains(" ") { + if v.contains(' ') { args.push(format!("-D{k}=\"{v}\"", k = k, v = v)); } else { args.push(format!("-D{k}={v}", k = k, v = v)); diff --git a/src/build_tools/git.rs b/src/build_tools/git.rs index 6fc8a66..cbc0844 100644 --- a/src/build_tools/git.rs +++ b/src/build_tools/git.rs @@ -20,10 +20,7 @@ impl Git { fn get_ref(&self) -> Option { let mut split = self.repo.split('#'); split.next().expect("Could not get repo url"); - match split.next() { - None => None, - Some(s) => Some(s.into()), - } + split.next().map(|s| s.into()) } pub fn get_reset_runner(&self) -> Runner { @@ -61,14 +58,13 @@ impl Git { } pub fn get_checkout_ref_runner(&self) -> Option { - match self.get_ref() { - Some(r) => Some(Runner::new( + self.get_ref().map(|r| { + Runner::new( None, "git".into(), vec!["-C".into(), self.dir.clone(), "checkout".into(), r], - )), - None => None, - } + ) + }) } pub fn get_clone_or_not_runner(&self) -> Option { diff --git a/src/builders/build_basalt.rs b/src/builders/build_basalt.rs index 2a555f6..470947b 100644 --- a/src/builders/build_basalt.rs +++ b/src/builders/build_basalt.rs @@ -15,18 +15,14 @@ pub fn get_build_basalt_runners(profile: &Profile, clean_build: bool) -> Vec runners.push(r), - None => {} + if let Some(r) = git.clone_or_pull(profile) { + runners.push(r); }; - match git.get_checkout_ref_runner() { - Some(r) => { - runners.push(r); - if profile.pull_on_build { - runners.push(git.get_pull_runner()); - } + if let Some(r) = git.get_checkout_ref_runner() { + runners.push(r); + if profile.pull_on_build { + runners.push(git.get_pull_runner()); } - None => {} } let build_dir = format!("{}/build", profile.features.basalt.path.as_ref().unwrap()); diff --git a/src/builders/build_libsurvive.rs b/src/builders/build_libsurvive.rs index 9f598cb..887ba11 100644 --- a/src/builders/build_libsurvive.rs +++ b/src/builders/build_libsurvive.rs @@ -15,18 +15,14 @@ pub fn get_build_libsurvive_runners(profile: &Profile, clean_build: bool) -> Vec }, dir: profile.features.libsurvive.path.as_ref().unwrap().clone(), }; - match git.clone_or_pull(profile) { - Some(r) => runners.push(r), - None => {} + if let Some(r) = git.clone_or_pull(profile) { + runners.push(r); }; - match git.get_checkout_ref_runner() { - Some(r) => { - runners.push(r); - if profile.pull_on_build { - runners.push(git.get_pull_runner()); - } + if let Some(r) = git.get_checkout_ref_runner() { + runners.push(r); + if profile.pull_on_build { + runners.push(git.get_pull_runner()); } - None => {} } let build_dir = format!( diff --git a/src/builders/build_mercury.rs b/src/builders/build_mercury.rs index 65ba0c8..acb1320 100644 --- a/src/builders/build_mercury.rs +++ b/src/builders/build_mercury.rs @@ -2,13 +2,12 @@ use crate::{constants::pkg_data_dir, paths::get_cache_dir, profile::Profile, run pub fn get_build_mercury_runner(profile: &Profile) -> Runner { let args = vec![profile.prefix.clone(), get_cache_dir()]; - let runner = Runner::new( + Runner::new( None, format!( "{sysdata}/scripts/build_mercury.sh", sysdata = pkg_data_dir() ), args, - ); - runner + ) } diff --git a/src/builders/build_monado.rs b/src/builders/build_monado.rs index 9bedd4e..cd9b60a 100644 --- a/src/builders/build_monado.rs +++ b/src/builders/build_monado.rs @@ -15,18 +15,14 @@ pub fn get_build_monado_runners(profile: &Profile, clean_build: bool) -> Vec runners.push(r), - None => {} - }; - match git.get_checkout_ref_runner() { - Some(r) => { - runners.push(r); - if profile.pull_on_build { - runners.push(git.get_pull_runner()); - } + if let Some(r) = git.clone_or_pull(profile) { + runners.push(r); + } + if let Some(r) = git.get_checkout_ref_runner() { + runners.push(r); + if profile.pull_on_build { + runners.push(git.get_pull_runner()); } - None => {} } let build_dir = format!("{}/build", profile.xrservice_path); diff --git a/src/builders/build_opencomposite.rs b/src/builders/build_opencomposite.rs index 62fe678..ecc8d8f 100644 --- a/src/builders/build_opencomposite.rs +++ b/src/builders/build_opencomposite.rs @@ -15,18 +15,14 @@ pub fn get_build_opencomposite_runners(profile: &Profile, clean_build: bool) -> }, dir: profile.opencomposite_path.clone(), }; - match git.clone_or_pull(profile) { - Some(r) => runners.push(r), - None => {} + if let Some(r) = git.clone_or_pull(profile) { + runners.push(r); }; - match git.get_checkout_ref_runner() { - Some(r) => { - runners.push(r); - if profile.pull_on_build { - runners.push(git.get_pull_runner()); - } + if let Some(r) = git.get_checkout_ref_runner() { + runners.push(r); + if profile.pull_on_build { + runners.push(git.get_pull_runner()); } - None => {} } let build_dir = format!("{}/build", profile.opencomposite_path); diff --git a/src/builders/build_wivrn.rs b/src/builders/build_wivrn.rs index f1cb3a1..5d25aa2 100644 --- a/src/builders/build_wivrn.rs +++ b/src/builders/build_wivrn.rs @@ -15,18 +15,14 @@ pub fn get_build_wivrn_runners(profile: &Profile, clean_build: bool) -> Vec runners.push(r), - None => {} - }; - match git.get_checkout_ref_runner() { - Some(r) => { - runners.push(r); - if profile.pull_on_build { - runners.push(git.get_pull_runner()); - } + if let Some(r) = git.clone_or_pull(profile) { + runners.push(r); + } + if let Some(r) = git.get_checkout_ref_runner() { + runners.push(r); + if profile.pull_on_build { + runners.push(git.get_pull_runner()); } - None => {} } let build_dir = format!("{}/build", profile.xrservice_path); diff --git a/src/config.rs b/src/config.rs index 79058d3..0a4d237 100644 --- a/src/config.rs +++ b/src/config.rs @@ -31,7 +31,7 @@ impl Default for Config { } impl Config { - pub fn get_selected_profile(&self, profiles: &Vec) -> Profile { + pub fn get_selected_profile(&self, profiles: &[Profile]) -> Profile { let def = || profiles.get(0).expect("No profiles found").clone(); match profiles @@ -84,12 +84,8 @@ impl Config { Self::from_path(Self::config_file_path()) } - pub fn set_profiles(&mut self, profiles: &Vec) { - self.user_profiles = profiles - .iter() - .filter(|p| p.editable) - .map(Profile::clone) - .collect(); + pub fn set_profiles(&mut self, profiles: &[Profile]) { + self.user_profiles = profiles.iter().filter(|p| p.editable).cloned().collect(); } } diff --git a/src/depcheck.rs b/src/depcheck.rs index a08c1a0..d98c24e 100644 --- a/src/depcheck.rs +++ b/src/depcheck.rs @@ -80,7 +80,7 @@ pub fn check_dependency(dep: Dependency) -> bool { return true; } } - return false; + false } pub fn check_dependencies(deps: Vec) -> Vec { diff --git a/src/downloader.rs b/src/downloader.rs index aeb3dd3..c087913 100644 --- a/src/downloader.rs +++ b/src/downloader.rs @@ -38,7 +38,7 @@ pub fn download_file(url: String, path: String) -> JoinHandle String { } pub fn is_steam(active_runtime: &ActiveRuntime) -> bool { - match active_runtime.runtime.valve_runtime_is_steamvr { - Some(true) => true, - _ => false, - } + matches!(active_runtime.runtime.valve_runtime_is_steamvr, Some(true)) } fn get_backup_steam_active_runtime_path() -> String { @@ -51,9 +48,8 @@ fn get_backed_up_steam_active_runtime() -> Option { } fn backup_steam_active_runtime() { - let ar = get_current_active_runtime(); - if ar.is_some() { - if is_steam(&ar.unwrap()) { + if let Some(ar) = get_current_active_runtime() { + if is_steam(&ar) { copy_file( &get_active_runtime_json_path(), &get_backup_steam_active_runtime_path(), @@ -85,9 +81,8 @@ pub fn dump_current_active_runtime( } fn build_steam_active_runtime() -> ActiveRuntime { - let backup = get_backed_up_steam_active_runtime(); - if backup.is_some() { - return backup.unwrap(); + if let Some(backup) = get_backed_up_steam_active_runtime() { + return backup; } ActiveRuntime { file_format_version: "1.0.0".into(), diff --git a/src/file_builders/openvrpaths_vrpath.rs b/src/file_builders/openvrpaths_vrpath.rs index 0ce3983..33da8c4 100644 --- a/src/file_builders/openvrpaths_vrpath.rs +++ b/src/file_builders/openvrpaths_vrpath.rs @@ -28,14 +28,10 @@ fn get_openvrpaths_vrpath_path() -> String { } pub fn is_steam(ovr_paths: &OpenVrPaths) -> bool { - ovr_paths - .runtime - .iter() - .find(|rt| { - rt.to_lowercase() - .ends_with("/steam/steamapps/common/steamvr") - }) - .is_some() + ovr_paths.runtime.iter().any(|rt| { + rt.to_lowercase() + .ends_with("/steam/steamapps/common/steamvr") + }) } fn get_backup_steam_openvrpaths_path() -> String { @@ -50,9 +46,8 @@ fn get_backed_up_steam_openvrpaths() -> Option { } fn backup_steam_openvrpaths() { - let openvrpaths = get_current_openvrpaths(); - if openvrpaths.is_some() { - if is_steam(&openvrpaths.unwrap()) { + if let Some(openvrpaths) = get_current_openvrpaths() { + if is_steam(&openvrpaths) { copy_file( &get_openvrpaths_vrpath_path(), &get_backup_steam_openvrpaths_path(), @@ -82,9 +77,8 @@ pub fn dump_current_openvrpaths(ovr_paths: &OpenVrPaths) -> Result<(), serde_jso } fn build_steam_openvrpaths() -> OpenVrPaths { - let backup = get_backed_up_steam_openvrpaths(); - if backup.is_some() { - return backup.unwrap(); + if let Some(backup) = get_backed_up_steam_openvrpaths() { + return backup; } let datadir = get_xdg_data_dir(); OpenVrPaths { diff --git a/src/file_utils.rs b/src/file_utils.rs index 4be5a43..adb5260 100644 --- a/src/file_utils.rs +++ b/src/file_utils.rs @@ -11,13 +11,10 @@ use std::{ pub fn get_writer(path_s: &String) -> BufWriter { let path = Path::new(path_s); - match path.parent() { - Some(parent) => { - if !parent.is_dir() { - create_dir_all(parent).expect("Could not create dir") - } + if let Some(parent) = path.parent() { + if !parent.is_dir() { + create_dir_all(parent).expect("Could not create dir") } - None => {} }; let file = OpenOptions::new() .write(true) @@ -36,14 +33,14 @@ pub fn get_reader(path_s: &String) -> Option> { match File::open(path) { Err(e) => { println!("Error opening {}: {}", path_s, e); - return None; + None } Ok(fd) => Some(BufReader::new(fd)), } } pub fn deserialize_file(path_s: &String) -> Option { - match get_reader(&path_s) { + match get_reader(path_s) { None => None, Some(reader) => match serde_json::from_reader(reader) { Err(e) => { @@ -79,26 +76,23 @@ pub fn setcap_cap_sys_nice_eip(file: String) { } pub fn rm_rf(path_s: &String) { - match remove_dir_all(path_s) { - Err(_) => println!("Failed to remove path {}", path_s), - Ok(_) => {} + if remove_dir_all(path_s).is_err() { + println!("Failed to remove path {}", path_s); } } pub fn copy_file(source_s: &String, dest_s: &String) { let source = Path::new(source_s); let dest = Path::new(dest_s); - let parent = dest.parent(); - if parent.is_some() { - if !parent.unwrap().is_dir() { - create_dir_all(parent.unwrap()).expect( - format!("Failed to create dir {}", parent.unwrap().to_str().unwrap()).as_str(), - ); + 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())); } } set_file_readonly(dest_s, false) - .expect(format!("Failed to set file {} as rw", dest_s).as_str()); - copy(source, dest).expect(format!("Failed to copy {} to {}", source_s, dest_s).as_str()); + .unwrap_or_else(|_| panic!("Failed to set file {} as rw", dest_s)); + copy(source, dest).unwrap_or_else(|_| panic!("Failed to copy {} to {}", source_s, dest_s)); } pub fn mount_has_nosuid(path_s: &str) -> Result { diff --git a/src/log_level.rs b/src/log_level.rs index 375b28e..a6ea930 100644 --- a/src/log_level.rs +++ b/src/log_level.rs @@ -1,5 +1,5 @@ use serde::{de::Visitor, Deserialize, Serialize}; -use std::{fmt::Display, slice::Iter}; +use std::{fmt::Display, slice::Iter, str::FromStr}; #[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize)] pub enum LogLevel { @@ -24,14 +24,21 @@ impl<'de> Visitor<'de> for LogLevelStringVisitor { where E: serde::de::Error, { - Ok(LogLevel::from_string(v.to_string())) + Ok(LogLevel::from_str(v).unwrap()) } fn visit_string(self, v: String) -> Result where E: serde::de::Error, { - Ok(LogLevel::from_string(v)) + Ok(LogLevel::from_str(&v).unwrap()) + } + + fn visit_str(self, v: &str) -> Result + where + E: serde::de::Error, + { + Ok(LogLevel::from_str(v).unwrap()) } } @@ -44,9 +51,9 @@ impl<'de> Deserialize<'de> for LogLevel { } } -impl LogLevel { - pub fn from_string(s: String) -> Self { - match s.to_lowercase().as_str() { +impl FromStr for LogLevel { + fn from_str(s: &str) -> Result { + Ok(match s.to_lowercase().as_str() { "trace" => Self::Trace, "debug" => Self::Debug, "info" => Self::Info, @@ -55,9 +62,13 @@ impl LogLevel { "error" => Self::Error, "err" => Self::Error, _ => Self::Debug, - } + }) } + type Err = (); +} + +impl LogLevel { pub fn iter() -> Iter<'static, LogLevel> { [ Self::Trace, diff --git a/src/log_parser.rs b/src/log_parser.rs index ca1ce32..3e77b24 100644 --- a/src/log_parser.rs +++ b/src/log_parser.rs @@ -10,7 +10,7 @@ pub struct MonadoLog { } impl MonadoLog { - pub fn from_str(s: &str) -> Option { + pub fn new_from_str(s: &str) -> Option { serde_json::from_str::(s).ok() } } diff --git a/src/main.rs b/src/main.rs index b7dbb69..840e970 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,16 +39,16 @@ pub mod xr_devices; fn restore_steam_xr_files() { let active_runtime = get_current_active_runtime(); let openvrpaths = get_current_openvrpaths(); - if active_runtime.is_some() { - if !file_builders::active_runtime_json::is_steam(&active_runtime.unwrap()) { + if let Some(ar) = active_runtime { + if !file_builders::active_runtime_json::is_steam(&ar) { match set_current_active_runtime_to_steam() { Ok(_) => {} Err(_) => println!("Warning: failed to restore active runtime to steam!"), }; } } - if openvrpaths.is_some() { - if !file_builders::openvrpaths_vrpath::is_steam(&openvrpaths.unwrap()) { + if let Some(ovrp) = openvrpaths { + if !file_builders::openvrpaths_vrpath::is_steam(&ovrp) { match set_current_openvrpaths_to_steam() { Ok(_) => {} Err(_) => println!("Warning: failed to restore openvrpaths to steam!"), diff --git a/src/profile.rs b/src/profile.rs index b8e5cec..7095d8e 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -285,7 +285,7 @@ impl Profile { serde_json::from_reader(reader).expect("Faiuled to deserialize profile") } - pub fn dump_profile(&self, path_s: &String) -> () { + pub fn dump_profile(&self, path_s: &String) { let writer = get_writer(path_s); serde_json::to_writer_pretty(writer, self).expect("Could not write profile") } diff --git a/src/runner.rs b/src/runner.rs index 0d61c41..09bfb80 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -114,11 +114,8 @@ impl Runner { .envs(self.environment.clone()) .stderr(Stdio::piped()) .stdout(Stdio::piped()) - .spawn(); - if cmd.is_err() { - return Err(cmd.unwrap_err()); - } - self.process = Some(cmd.unwrap()); + .spawn()?; + self.process = Some(cmd); let stdout = self.process.as_mut().unwrap().stdout.take().unwrap(); let stderr = self.process.as_mut().unwrap().stderr.take().unwrap(); let stdout_sender = self.sender.clone(); @@ -178,11 +175,8 @@ impl Runner { } fn receive_output(&mut self) { - loop { - match self.receiver.try_recv() { - Ok(data) => self.output.push(data), - Err(_) => break, - }; + while let Ok(data) = self.receiver.try_recv() { + self.output.push(data); } } @@ -200,7 +194,7 @@ impl Runner { res } - fn save_log(path_s: String, log: &Vec) -> Result<(), std::io::Error> { + fn save_log(path_s: String, log: &[String]) -> Result<(), std::io::Error> { let mut writer = get_writer(&path_s); let log_s = log.concat(); writer.write_all(log_s.as_ref()) diff --git a/src/runner_pipeline.rs b/src/runner_pipeline.rs index 6e1c66c..c2a0a44 100644 --- a/src/runner_pipeline.rs +++ b/src/runner_pipeline.rs @@ -34,13 +34,8 @@ impl RunnerPipeline { return; } self.has_started = true; - match self.get_current_runner() { - None => { - return; - } - Some(runner) => { - runner.borrow_mut().start(); - } + if let Some(runner) = self.get_current_runner() { + runner.borrow_mut().start(); } } diff --git a/src/ui/alert.rs b/src/ui/alert.rs index 76dd49c..d160997 100644 --- a/src/ui/alert.rs +++ b/src/ui/alert.rs @@ -6,8 +6,8 @@ pub fn alert(title: &str, msg: Option<&str>, parent: Option<>k::Window>) { .modal(true) .heading(title) .build(); - if msg.is_some() { - d.set_body(msg.unwrap()); + if let Some(m) = msg { + d.set_body(m); } if parent.is_some() { d.set_transient_for(parent); diff --git a/src/ui/app.rs b/src/ui/app.rs index e175122..007b917 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -193,10 +193,10 @@ impl App { pub fn shutdown_xrservice(&mut self) { self.set_inhibit_session(false); - if self.xrservice_runner.is_some() { - if self.xrservice_runner.as_mut().unwrap().status() == RunnerStatus::Running { - self.xrservice_runner.as_mut().unwrap().terminate(); - } + if self.xrservice_runner.is_some() + && self.xrservice_runner.as_mut().unwrap().status() == RunnerStatus::Running + { + self.xrservice_runner.as_mut().unwrap().terminate(); } self.restore_openxr_openvr_files(); self.main_view @@ -258,10 +258,10 @@ impl SimpleComponent for App { } fn shutdown(&mut self, _widgets: &mut Self::Widgets, _output: relm4::Sender) { - if self.xrservice_runner.is_some() { - if self.xrservice_runner.as_mut().unwrap().status() == RunnerStatus::Running { - self.xrservice_runner.as_mut().unwrap().terminate(); - } + if self.xrservice_runner.is_some() + && self.xrservice_runner.as_mut().unwrap().status() == RunnerStatus::Running + { + self.xrservice_runner.as_mut().unwrap().terminate(); } self.restore_openxr_openvr_files(); } @@ -337,7 +337,7 @@ impl SimpleComponent for App { } Msg::ProcessDevicesLog(rows) => { for row in rows { - match MonadoLog::from_str(row.as_str()) { + match MonadoLog::new_from_str(row.as_str()) { None => {} Some(parsed) => { if parsed.func == "p_create_system" { @@ -386,12 +386,11 @@ impl SimpleComponent for App { Some(runner) => match runner.status() { RunnerStatus::Stopped(_) => {} RunnerStatus::Running => { - if self.xrservice_runner.is_some() { - if self.xrservice_runner.as_mut().unwrap().status() + if self.xrservice_runner.is_some() + && self.xrservice_runner.as_mut().unwrap().status() == RunnerStatus::Running - { - self.xrservice_runner.as_mut().unwrap().terminate(); - } + { + self.xrservice_runner.as_mut().unwrap().terminate(); } } }, @@ -464,13 +463,7 @@ impl SimpleComponent for App { Msg::DeleteProfile => { let todel = self.get_selected_profile(); if todel.editable { - self.config.user_profiles = self - .config - .user_profiles - .iter() - .filter(|p| p.uuid != todel.uuid) - .map(|p| p.clone()) - .collect(); + self.config.user_profiles.retain(|p| p.uuid != todel.uuid); self.config.save(); self.profiles = Self::profiles_list(&self.config); self.main_view @@ -550,7 +543,7 @@ impl SimpleComponent for App { sender: ComponentSender, ) -> ComponentParts { let config = Config::get_config(); - let win_size = config.win_size.clone(); + let win_size = config.win_size; let profiles = Self::profiles_list(&config); let setcap_confirm_dialog = adw::MessageDialog::builder() .modal(true) @@ -682,7 +675,7 @@ impl SimpleComponent for App { withclones![sender]; glib::timeout_add_local(Duration::from_millis(1000), move || { sender.input(Msg::ClockTicking); - return glib::Continue(true); + glib::Continue(true) }); } diff --git a/src/ui/build_window.rs b/src/ui/build_window.rs index 32f194a..a70357d 100644 --- a/src/ui/build_window.rs +++ b/src/ui/build_window.rs @@ -139,7 +139,7 @@ impl SimpleComponent for BuildWindow { self.set_title(t); } Self::Input::UpdateContent(c) => { - if c.len() > 0 { + if !c.is_empty() { let is_at_bottom = { let adj = self.scrolledwin.as_ref().unwrap().vadjustment(); (adj.upper() - adj.page_size() - adj.value()) <= 15.0 diff --git a/src/ui/debug_view.rs b/src/ui/debug_view.rs index b27c8db..ea44b2c 100644 --- a/src/ui/debug_view.rs +++ b/src/ui/debug_view.rs @@ -200,12 +200,12 @@ impl SimpleComponent for DebugView { }; self.log.extend(n_log.clone()); for row in n_log { - let txt = match MonadoLog::from_str(row.as_str()) { + let txt = match MonadoLog::new_from_str(row.as_str()) { Some(o) => match o.level >= self.log_level { false => None, true => Some(format!( "{lvl}\t[{file}:{func}]\n\t{msg}\n", - lvl = o.level.to_string(), + lvl = o.level, file = o.file, func = o.func, msg = o.message @@ -213,9 +213,9 @@ impl SimpleComponent for DebugView { }, None => Some(row), }; - if txt.is_some() { + if let Some(t) = txt { self.textbuf - .insert(&mut self.textbuf.end_iter(), txt.unwrap().as_str()); + .insert(&mut self.textbuf.end_iter(), t.as_str()); } } let textbuf = self.textbuf.clone(); @@ -284,11 +284,10 @@ impl SimpleComponent for DebugView { .log_level_dropdown .connect_selected_notify(move |dd| { sender.input(Self::Input::LogLevelChanged( - LogLevel::iter() + *LogLevel::iter() .as_slice() .get(dd.selected() as usize) - .unwrap() - .clone(), + .unwrap(), )); }); } diff --git a/src/ui/install_wivrn_box.rs b/src/ui/install_wivrn_box.rs index 761b736..3053513 100644 --- a/src/ui/install_wivrn_box.rs +++ b/src/ui/install_wivrn_box.rs @@ -72,10 +72,7 @@ impl SimpleComponent for InstallWivrnBox { set_margin_top: 12, set_margin_bottom: 12, #[track = "model.changed(Self::selected_profile())"] - set_visible: match model.selected_profile.xrservice_type { - XRServiceType::Wivrn => true, - _ => false, - }, + set_visible: model.selected_profile.xrservice_type == XRServiceType::Wivrn, gtk::Separator { set_orientation: gtk::Orientation::Horizontal, set_hexpand: true, @@ -111,10 +108,7 @@ impl SimpleComponent for InstallWivrnBox { set_margin_end: 12, set_halign: gtk::Align::Start, #[track = "model.changed(Self::install_wivrn_status())"] - set_sensitive: match model.install_wivrn_status { - InstallWivrnStatus::InProgress => false, - _ => true, - }, + set_sensitive: model.install_wivrn_status != InstallWivrnStatus::InProgress, set_menu_model: Some(&install_wivrn_menu), }, gtk::Label { @@ -123,10 +117,7 @@ impl SimpleComponent for InstallWivrnBox { set_margin_end: 12, set_xalign: 0.0, #[track = "model.changed(Self::install_wivrn_status())"] - set_visible: match &model.install_wivrn_status { - InstallWivrnStatus::Done(Some(_)) => true, - _ => false, - }, + set_visible: matches!(&model.install_wivrn_status, InstallWivrnStatus::Done(Some(_))), #[track = "model.changed(Self::install_wivrn_status())"] set_label: match &model.install_wivrn_status { InstallWivrnStatus::Done(Some(err)) => err.as_str(), @@ -139,10 +130,7 @@ impl SimpleComponent for InstallWivrnBox { set_margin_end: 12, set_xalign: 0.0, #[track = "model.changed(Self::install_wivrn_status())"] - set_visible: match &model.install_wivrn_status { - InstallWivrnStatus::Success => true, - _ => false, - }, + set_visible: model.install_wivrn_status == InstallWivrnStatus::Success, set_label: "WiVRn Installed Successfully", }, } diff --git a/src/ui/libsurvive_setup_window.rs b/src/ui/libsurvive_setup_window.rs index 13c00cd..ab929d1 100644 --- a/src/ui/libsurvive_setup_window.rs +++ b/src/ui/libsurvive_setup_window.rs @@ -366,9 +366,10 @@ impl SimpleComponent for LibsurviveSetupWindow { let path_s = self.steam_lighthouse_path.clone(); let lh_path = Path::new(&path_s); if lh_path.is_file() { - let survive_cli_path = self.profile.as_ref().unwrap().get_survive_cli_path(); - if survive_cli_path.is_some() { - let mut runner = self.create_calibration_runner(survive_cli_path.unwrap()); + if let Some(survive_cli_path) = + self.profile.as_ref().unwrap().get_survive_cli_path() + { + let mut runner = self.create_calibration_runner(survive_cli_path); self.calibration_running.set(true); self.first_run_done = false; self.calibration_seconds_elapsed = 0.0; @@ -378,7 +379,7 @@ impl SimpleComponent for LibsurviveSetupWindow { let cont = self.calibration_running.clone(); glib::timeout_add_local(Duration::from_millis(1000), move || { timer_sender.input(LibsurviveSetupMsg::TickCalibrationRunner); - return glib::Continue(cont.get()); + glib::Continue(cont.get()) }); } self.calibration_runner = Some(runner); @@ -387,10 +388,7 @@ impl SimpleComponent for LibsurviveSetupWindow { .unwrap() .scroll_to(self.loading_page.as_ref().unwrap(), true); } else { - let parent = match self.win.as_ref() { - None => None, - Some(w) => Some(w.clone().upcast::()), - }; + let parent = self.win.as_ref().map(|w| w.clone().upcast::()); alert( "Survive CLI not found", Some(concat!( @@ -418,16 +416,14 @@ impl SimpleComponent for LibsurviveSetupWindow { chooser.open( Some(&self.win.as_ref().unwrap().clone()), gtk::gio::Cancellable::NONE, - move |res| match res { - Ok(file) => { - let path = file.path(); - if path.is_some() { + move |res| { + if let Ok(file) = res { + if let Some(path) = file.path() { fd_sender.input(LibsurviveSetupMsg::SetSteamLighthousePath(Some( - path.unwrap().to_str().unwrap().to_string(), + path.to_str().unwrap().to_string(), ))) } } - _ => {} }, ); } @@ -437,42 +433,37 @@ impl SimpleComponent for LibsurviveSetupWindow { (self.calibration_seconds_elapsed / (CALIBRATION_RUN_TIME_SECONDS * 2.0)) .min(1.0), ); - if !self.first_run_done { - if self.calibration_seconds_elapsed >= CALIBRATION_RUN_TIME_SECONDS { - if self.calibration_runner.is_some() { - self.first_run_done = true; - let runner = self.calibration_runner.as_mut().unwrap(); - runner.terminate(); - let mut n_runner = self.create_calibration_runner( - self.profile - .as_ref() - .unwrap() - .get_survive_cli_path() - .unwrap(), - ); - n_runner.start(); - self.calibration_runner = Some(n_runner); - } - } - } else { - if self.calibration_seconds_elapsed >= (CALIBRATION_RUN_TIME_SECONDS * 2.0) { + if !self.first_run_done + && self.calibration_seconds_elapsed >= CALIBRATION_RUN_TIME_SECONDS + { + if self.calibration_runner.is_some() { + self.first_run_done = true; let runner = self.calibration_runner.as_mut().unwrap(); runner.terminate(); - self.calibration_running.set(false); - self.carousel - .as_ref() - .unwrap() - .scroll_to(self.calibration_done_page.as_ref().unwrap(), true); + let mut n_runner = self.create_calibration_runner( + self.profile + .as_ref() + .unwrap() + .get_survive_cli_path() + .unwrap(), + ); + n_runner.start(); + self.calibration_runner = Some(n_runner); } + } else if self.calibration_seconds_elapsed >= (CALIBRATION_RUN_TIME_SECONDS * 2.0) { + let runner = self.calibration_runner.as_mut().unwrap(); + runner.terminate(); + self.calibration_running.set(false); + self.carousel + .as_ref() + .unwrap() + .scroll_to(self.calibration_done_page.as_ref().unwrap(), true); } } Self::Input::Cancel => { if self.calibration_running.get() { - match self.calibration_runner.as_mut() { - Some(runner) => { - runner.terminate(); - } - None => {} + if let Some(runner) = self.calibration_runner.as_mut() { + runner.terminate(); } self.calibration_running.set(false); self.carousel diff --git a/src/ui/main_view.rs b/src/ui/main_view.rs index 6e32734..e234003 100644 --- a/src/ui/main_view.rs +++ b/src/ui/main_view.rs @@ -357,7 +357,7 @@ impl SimpleComponent for MainView { }, connect_realize => move |dd| { limit_dropdown_width( - &dd, match model.enable_debug_view { + dd, match model.enable_debug_view { true => 18, false => -1, }); diff --git a/src/ui/preference_rows.rs b/src/ui/preference_rows.rs index 959c836..938c2b2 100644 --- a/src/ui/preference_rows.rs +++ b/src/ui/preference_rows.rs @@ -18,8 +18,8 @@ pub fn switch_row glib::signal::Inhibit + 'static>( .subtitle_lines(0) .build(); - if description.is_some() { - row.set_subtitle(description.unwrap()); + if let Some(d) = description { + row.set_subtitle(d); } let switch = gtk::Switch::builder() @@ -76,8 +76,8 @@ pub fn path_row) + 'static + Clone>( .icon_name(GString::from("folder-open-symbolic")) .build(); - if description.is_some() { - row.set_subtitle(description.unwrap()); + if let Some(d) = description { + row.set_subtitle(d); } let path_label = >k::Label::builder() @@ -111,21 +111,15 @@ pub fn path_row) + 'static + Clone>( withclones![path_label]; row.connect_activated(move |_| { withclones![path_label, cb]; - filedialog.select_folder( - root_win.as_ref(), - gio::Cancellable::NONE, - move |res| match res { - Ok(file) => { - let path = file.path(); - if path.is_some() { - let path_s = path.unwrap().to_str().unwrap().to_string(); - path_label.set_text(path_s.as_str()); - cb(Some(path_s)) - } + filedialog.select_folder(root_win.as_ref(), gio::Cancellable::NONE, move |res| { + if let Ok(file) = res { + if let Some(path) = file.path() { + let path_s = path.to_str().unwrap().to_string(); + path_label.set_text(path_s.as_str()); + cb(Some(path_s)) } - _ => {} - }, - ) + } + }) }); } @@ -151,15 +145,12 @@ pub fn combo_row( )) .build(); - if description.is_some() { - row.set_subtitle(description.unwrap()); + if let Some(desc) = description { + row.set_subtitle(desc); } - let selected = values.iter().position(|v| *v == value.to_string()); - row.set_selected(match selected { - Some(i) => i, - None => 0, - } as u32); + let selected = values.iter().position(|v| v == value); + row.set_selected(selected.unwrap_or(0) as u32); row.connect_selected_item_notify(cb); diff --git a/src/ui/profile_editor.rs b/src/ui/profile_editor.rs index fcc6c67..266ecba 100644 --- a/src/ui/profile_editor.rs +++ b/src/ui/profile_editor.rs @@ -317,8 +317,8 @@ impl SimpleComponent for ProfileEditor { .guard() .iter() .position(|evr| evr.name == name); - if pos.is_some() { - self.env_rows.guard().remove(pos.unwrap()); + if let Some(p) = pos { + self.env_rows.guard().remove(p); } } Self::Input::AddEnvVar(name) => { diff --git a/src/ui/util.rs b/src/ui/util.rs index c0be65d..3530bd6 100644 --- a/src/ui/util.rs +++ b/src/ui/util.rs @@ -13,12 +13,9 @@ pub fn limit_dropdown_width(dd: >k4::DropDown, chars: i32) { if dd_child.is_none() { break; } - match dd_child.clone().unwrap().downcast::() { - Ok(label) => { - label.set_max_width_chars(chars); - label.set_ellipsize(gtk4::pango::EllipsizeMode::End); - } - _ => {} + if let Ok(label) = dd_child.clone().unwrap().downcast::() { + label.set_max_width_chars(chars); + label.set_ellipsize(gtk4::pango::EllipsizeMode::End); } let nc = dd_child.unwrap().first_child().clone(); dd_child = nc; diff --git a/src/ui/wivrn_conf_editor.rs b/src/ui/wivrn_conf_editor.rs index 3c6bd3e..f4fc860 100644 --- a/src/ui/wivrn_conf_editor.rs +++ b/src/ui/wivrn_conf_editor.rs @@ -127,10 +127,7 @@ impl SimpleComponent for WivrnConfEditor { let scalex = self.scalex_entry.as_ref().unwrap().text().parse::(); let scaley = self.scaley_entry.as_ref().unwrap().text().parse::(); if scalex.is_ok() && scaley.is_ok() { - self.conf.scale = Some([ - scalex.as_ref().unwrap().clone(), - scaley.as_ref().unwrap().clone(), - ]); + self.conf.scale = Some([*scalex.as_ref().unwrap(), *scaley.as_ref().unwrap()]); } if scalex.is_ok() || scaley.is_ok() { let scale = scalex.unwrap_or(scaley.unwrap()); @@ -141,14 +138,14 @@ impl SimpleComponent for WivrnConfEditor { let mut enc = self.conf.encoders.remove(0); let bitrate = self.bitrate_entry.as_ref().unwrap().text().parse::(); - if bitrate.is_ok() { - enc.bitrate = Some(bitrate.unwrap()); + if let Ok(br) = bitrate { + enc.bitrate = Some(br); } let encoders = Encoder::as_vec(); let encoder = encoders.get(self.encoder_combo.as_ref().unwrap().selected() as usize); - if encoder.is_some() { - enc.encoder = encoder.unwrap().clone(); + if let Some(e) = encoder { + enc.encoder = e.clone(); } self.conf.encoders.insert(0, enc); diff --git a/src/xr_devices.rs b/src/xr_devices.rs index 4b7ba8e..bd6127d 100644 --- a/src/xr_devices.rs +++ b/src/xr_devices.rs @@ -9,7 +9,7 @@ pub enum XRDevice { HandTrackingRight, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Default, Clone, PartialEq, Eq)] pub struct XRDevices { pub head: Option, pub left: Option, @@ -20,23 +20,9 @@ pub struct XRDevices { pub hand_tracking_right: Option, } -impl Default for XRDevices { - fn default() -> Self { - Self { - head: None, - left: None, - right: None, - gamepad: None, - eyes: None, - hand_tracking_left: None, - hand_tracking_right: None, - } - } -} - impl XRDevices { pub fn from_log_message(s: String) -> Option { - let rows = s.split("\n"); + let rows = s.split('\n'); let mut in_section = false; let mut devs = Self::default(); for row in rows {