fix: lots of clippy errors

This commit is contained in:
Gabriele Musco 2023-08-15 17:16:41 +00:00
commit 4659eca89c
33 changed files with 197 additions and 302 deletions

View file

@ -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
)
}

View file

@ -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));

View file

@ -20,10 +20,7 @@ impl Git {
fn get_ref(&self) -> Option<String> {
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<Runner> {
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<Runner> {

View file

@ -15,19 +15,15 @@ pub fn get_build_basalt_runners(profile: &Profile, clean_build: bool) -> Vec<Run
},
dir: profile.features.basalt.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) => {
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());
let mut cmake_vars: HashMap<String, String> = HashMap::new();

View file

@ -15,19 +15,15 @@ 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) => {
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",

View file

@ -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
)
}

View file

@ -15,19 +15,15 @@ pub fn get_build_monado_runners(profile: &Profile, clean_build: bool) -> Vec<Run
},
dir: profile.xrservice_path.clone(),
};
match git.clone_or_pull(profile) {
Some(r) => runners.push(r),
None => {}
};
match git.get_checkout_ref_runner() {
Some(r) => {
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);
let mut env: HashMap<String, String> = HashMap::new();

View file

@ -15,19 +15,15 @@ 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) => {
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);
let mut cmake_vars: HashMap<String, String> = HashMap::new();

View file

@ -15,19 +15,15 @@ pub fn get_build_wivrn_runners(profile: &Profile, clean_build: bool) -> Vec<Runn
},
dir: profile.xrservice_path.clone(),
};
match git.clone_or_pull(profile) {
Some(r) => runners.push(r),
None => {}
};
match git.get_checkout_ref_runner() {
Some(r) => {
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);
let mut cmake_vars: HashMap<String, String> = HashMap::new();

View file

@ -31,7 +31,7 @@ impl Default for Config {
}
impl Config {
pub fn get_selected_profile(&self, profiles: &Vec<Profile>) -> 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<Profile>) {
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();
}
}

View file

@ -80,7 +80,7 @@ pub fn check_dependency(dep: Dependency) -> bool {
return true;
}
}
return false;
false
}
pub fn check_dependencies(deps: Vec<Dependency>) -> Vec<DependencyCheckResult> {

View file

@ -38,7 +38,7 @@ pub fn download_file(url: String, path: String) -> JoinHandle<Result<(), reqwest
.expect("Could not get HTTP response bytes")
.chunks(CHUNK_SIZE)
{
writer.write(chunk).expect("Failed to write chunk");
writer.write_all(chunk).expect("Failed to write chunk");
}
writer.flush().expect("Failed to flush download writer");
Ok(())

View file

@ -33,10 +33,7 @@ fn get_active_runtime_json_path() -> 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<ActiveRuntime> {
}
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(),

View file

@ -28,14 +28,10 @@ fn get_openvrpaths_vrpath_path() -> String {
}
pub fn is_steam(ovr_paths: &OpenVrPaths) -> bool {
ovr_paths
.runtime
.iter()
.find(|rt| {
ovr_paths.runtime.iter().any(|rt| {
rt.to_lowercase()
.ends_with("/steam/steamapps/common/steamvr")
})
.is_some()
}
fn get_backup_steam_openvrpaths_path() -> String {
@ -50,9 +46,8 @@ fn get_backed_up_steam_openvrpaths() -> Option<OpenVrPaths> {
}
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 {

View file

@ -11,13 +11,10 @@ use std::{
pub fn get_writer(path_s: &String) -> BufWriter<std::fs::File> {
let path = Path::new(path_s);
match path.parent() {
Some(parent) => {
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<BufReader<File>> {
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<T: serde::de::DeserializeOwned>(path_s: &String) -> Option<T> {
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<bool, Errno> {

View file

@ -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<E>(self, v: String) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
Ok(LogLevel::from_string(v))
Ok(LogLevel::from_str(&v).unwrap())
}
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
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<Self, Self::Err> {
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,

View file

@ -10,7 +10,7 @@ pub struct MonadoLog {
}
impl MonadoLog {
pub fn from_str(s: &str) -> Option<Self> {
pub fn new_from_str(s: &str) -> Option<Self> {
serde_json::from_str::<Self>(s).ok()
}
}

View file

@ -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!"),

View file

@ -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")
}

View file

@ -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<String>) -> 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())

View file

@ -34,15 +34,10 @@ impl RunnerPipeline {
return;
}
self.has_started = true;
match self.get_current_runner() {
None => {
return;
}
Some(runner) => {
if let Some(runner) = self.get_current_runner() {
runner.borrow_mut().start();
}
}
}
pub fn update(&mut self) {
if !self.has_started {

View file

@ -6,8 +6,8 @@ pub fn alert(title: &str, msg: Option<&str>, parent: Option<&gtk::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);

View file

@ -193,11 +193,11 @@ 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 {
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
.sender()
@ -258,11 +258,11 @@ impl SimpleComponent for App {
}
fn shutdown(&mut self, _widgets: &mut Self::Widgets, _output: relm4::Sender<Self::Output>) {
if self.xrservice_runner.is_some() {
if self.xrservice_runner.as_mut().unwrap().status() == RunnerStatus::Running {
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,14 +386,13 @@ 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.start_xrservice();
@ -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<Self>,
) -> ComponentParts<Self> {
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)
});
}

View file

@ -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

View file

@ -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(),
));
});
}

View file

@ -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",
},
}

View file

@ -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::<gtk::Window>()),
};
let parent = self.win.as_ref().map(|w| w.clone().upcast::<gtk::Window>());
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,8 +433,9 @@ 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.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();
@ -453,9 +450,7 @@ impl SimpleComponent for LibsurviveSetupWindow {
n_runner.start();
self.calibration_runner = Some(n_runner);
}
}
} else {
if self.calibration_seconds_elapsed >= (CALIBRATION_RUN_TIME_SECONDS * 2.0) {
} 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);
@ -465,15 +460,11 @@ impl SimpleComponent for LibsurviveSetupWindow {
.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) => {
if let Some(runner) = self.calibration_runner.as_mut() {
runner.terminate();
}
None => {}
}
self.calibration_running.set(false);
self.carousel
.as_ref()

View file

@ -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,
});

View file

@ -18,8 +18,8 @@ pub fn switch_row<F: Fn(&gtk::Switch, bool) -> 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<F: Fn(Option<String>) + '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 = &gtk::Label::builder()
@ -111,21 +111,15 @@ pub fn path_row<F: Fn(Option<String>) + '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();
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<F: Fn(&adw::ComboRow) + 'static>(
))
.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);

View file

@ -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) => {

View file

@ -13,13 +13,10 @@ pub fn limit_dropdown_width(dd: &gtk4::DropDown, chars: i32) {
if dd_child.is_none() {
break;
}
match dd_child.clone().unwrap().downcast::<gtk4::Label>() {
Ok(label) => {
if let Ok(label) = dd_child.clone().unwrap().downcast::<gtk4::Label>() {
label.set_max_width_chars(chars);
label.set_ellipsize(gtk4::pango::EllipsizeMode::End);
}
_ => {}
}
let nc = dd_child.unwrap().first_child().clone();
dd_child = nc;
}

View file

@ -127,10 +127,7 @@ impl SimpleComponent for WivrnConfEditor {
let scalex = self.scalex_entry.as_ref().unwrap().text().parse::<f32>();
let scaley = self.scaley_entry.as_ref().unwrap().text().parse::<f32>();
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::<u32>();
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);

View file

@ -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<String>,
pub left: Option<String>,
@ -20,23 +20,9 @@ pub struct XRDevices {
pub hand_tracking_right: Option<String>,
}
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<Self> {
let rows = s.split("\n");
let rows = s.split('\n');
let mut in_section = false;
let mut devs = Self::default();
for row in rows {