feat: small code cleanup

This commit is contained in:
Gabriele Musco 2023-06-20 22:12:11 +02:00
commit dcece17445
No known key found for this signature in database
GPG key ID: 1068D795C80E51DE
3 changed files with 10 additions and 13 deletions

View file

@ -74,7 +74,7 @@ pub struct App {
#[derive(Debug)] #[derive(Debug)]
pub enum Msg { pub enum Msg {
UpdateView, ClockTicking,
BuildProfile, BuildProfile,
EnableDebugViewChanged(bool), EnableDebugViewChanged(bool),
DoStartStopXRService, DoStartStopXRService,
@ -151,7 +151,7 @@ impl SimpleComponent for App {
self.reset(); self.reset();
match message { match message {
Msg::UpdateView => { Msg::ClockTicking => {
match &mut self.xrservice_runner { match &mut self.xrservice_runner {
None => {} None => {}
Some(runner) => { Some(runner) => {
@ -407,7 +407,6 @@ impl SimpleComponent for App {
selected_profile: config.get_selected_profile(&profiles), selected_profile: config.get_selected_profile(&profiles),
}) })
.forward(sender.input_sender(), |message| match message { .forward(sender.input_sender(), |message| match message {
MainViewOutMsg::UpdateView => Msg::UpdateView,
MainViewOutMsg::EnableDebugViewChanged(val) => Msg::EnableDebugViewChanged(val), MainViewOutMsg::EnableDebugViewChanged(val) => Msg::EnableDebugViewChanged(val),
MainViewOutMsg::DoStartStopXRService => Msg::DoStartStopXRService, MainViewOutMsg::DoStartStopXRService => Msg::DoStartStopXRService,
MainViewOutMsg::ProfileSelected(name) => Msg::ProfileSelected(name), MainViewOutMsg::ProfileSelected(name) => Msg::ProfileSelected(name),
@ -418,7 +417,7 @@ impl SimpleComponent for App {
enable_debug_view: config.debug_view_enabled, enable_debug_view: config.debug_view_enabled,
}) })
.forward(sender.input_sender(), |message| match message { .forward(sender.input_sender(), |message| match message {
_ => Msg::UpdateView, _ => Msg::ClockTicking,
}), }),
about_dialog: AboutDialog::builder() about_dialog: AboutDialog::builder()
.transient_for(root) .transient_for(root)
@ -496,7 +495,7 @@ impl SimpleComponent for App {
let timer_sender = sender.clone(); let timer_sender = sender.clone();
glib::timeout_add_local(Duration::from_millis(1000), move || { glib::timeout_add_local(Duration::from_millis(1000), move || {
timer_sender.input(Msg::UpdateView); timer_sender.input(Msg::ClockTicking);
return glib::Continue(true); return glib::Continue(true);
}); });

View file

@ -7,7 +7,7 @@ use crate::{
}; };
use gtk::prelude::*; use gtk::prelude::*;
use relm4::prelude::*; use relm4::prelude::*;
use std::{cell::Cell, thread::JoinHandle}; use std::thread::JoinHandle;
#[derive(PartialEq, Eq, Debug, Clone)] #[derive(PartialEq, Eq, Debug, Clone)]
pub enum InstallWivrnStatus { pub enum InstallWivrnStatus {
@ -21,7 +21,7 @@ pub struct InstallWivrnBox {
selected_profile: Profile, selected_profile: Profile,
install_wivrn_status: InstallWivrnStatus, install_wivrn_status: InstallWivrnStatus,
#[tracker::do_not_track] #[tracker::do_not_track]
download_thread: Cell<Option<JoinHandle<Result<(), reqwest::Error>>>>, download_thread: Option<JoinHandle<Result<(), reqwest::Error>>>,
#[tracker::do_not_track] #[tracker::do_not_track]
install_runner: Option<Runner>, install_runner: Option<Runner>,
} }
@ -135,10 +135,9 @@ impl SimpleComponent for InstallWivrnBox {
match message { match message {
Self::Input::ClockTicking => { Self::Input::ClockTicking => {
if self.download_thread.get_mut().is_some() { if self.download_thread.is_some() {
let finished = self let finished = self
.download_thread .download_thread
.get_mut()
.as_ref() .as_ref()
.unwrap() .unwrap()
.is_finished(); .is_finished();
@ -173,10 +172,10 @@ impl SimpleComponent for InstallWivrnBox {
} }
Self::Input::DownloadWivrn => { Self::Input::DownloadWivrn => {
self.set_install_wivrn_status(InstallWivrnStatus::InProgress); self.set_install_wivrn_status(InstallWivrnStatus::InProgress);
self.download_thread.set(Some(download_file( self.download_thread = Some(download_file(
"https://github.com/Meumeu/WiVRn/releases/latest/download/WiVRn-oculus-release.apk".into(), "https://github.com/Meumeu/WiVRn/releases/latest/download/WiVRn-oculus-release.apk".into(),
wivrn_apk_download_path() wivrn_apk_download_path()
))); ));
} }
Self::Input::InstallWivrnApk => { Self::Input::InstallWivrnApk => {
let mut runner = get_adb_install_runner(&wivrn_apk_download_path()); let mut runner = get_adb_install_runner(&wivrn_apk_download_path());
@ -197,7 +196,7 @@ impl SimpleComponent for InstallWivrnBox {
let model = Self { let model = Self {
selected_profile: init.selected_profile, selected_profile: init.selected_profile,
install_wivrn_status: InstallWivrnStatus::Done(None), install_wivrn_status: InstallWivrnStatus::Done(None),
download_thread: Cell::new(None), download_thread: None,
install_runner: None, install_runner: None,
tracker: 0, tracker: 0,
}; };

View file

@ -44,7 +44,6 @@ pub enum MainViewMsg {
#[derive(Debug)] #[derive(Debug)]
pub enum MainViewOutMsg { pub enum MainViewOutMsg {
UpdateView,
EnableDebugViewChanged(bool), EnableDebugViewChanged(bool),
DoStartStopXRService, DoStartStopXRService,
ProfileSelected(String), ProfileSelected(String),