From ee0b8d571c8f183c3e83ee8ce12dfac88dc7594e Mon Sep 17 00:00:00 2001 From: Nickiel12 <35903114+Nickiel12@users.noreply.github.com> Date: Sat, 18 May 2024 15:55:42 -0700 Subject: [PATCH] cargo fmt --- src/coordinator/mod.rs | 35 ++++++----- src/coordinator/remote_video_processor.rs | 3 +- src/main.rs | 5 +- src/ui/mod.rs | 6 +- src/ui/settings_modal.rs | 71 ++++++++++++----------- src/ui/socket_panel.rs | 6 +- 6 files changed, 64 insertions(+), 62 deletions(-) diff --git a/src/coordinator/mod.rs b/src/coordinator/mod.rs index bf6b888..2bbd0f1 100644 --- a/src/coordinator/mod.rs +++ b/src/coordinator/mod.rs @@ -131,7 +131,11 @@ impl<'a> CoordState<'a> { let conn_string: String = { let read_settings = self.settings.read().await; - format!("ws://{}:{}", read_settings.camera_ip, read_settings.camera_port.to_string()) + format!( + "ws://{}:{}", + read_settings.camera_ip, + read_settings.camera_port.to_string() + ) }; match connect_async(conn_string).await { @@ -165,20 +169,21 @@ impl<'a> CoordState<'a> { let conn_string: String = { let read_settings = self.settings.read().await; - format!("ws://{}:{}", read_settings.tracker_ip, read_settings.tracker_port.to_string()) + format!( + "ws://{}:{}", + read_settings.tracker_ip, + read_settings.tracker_port.to_string() + ) }; - self.rt.spawn( - remote_video_loop( - conn_string, - self.pipeline.sink_frame.clone(), - self.to_mec.clone(), - self.keep_windows_pipe_alive.clone(), - self.tracker_state.clone(), - self.rt.clone() - ), - ); - + self.rt.spawn(remote_video_loop( + conn_string, + self.pipeline.sink_frame.clone(), + self.to_mec.clone(), + self.keep_windows_pipe_alive.clone(), + self.tracker_state.clone(), + self.rt.clone(), + )); } pub async fn check_states(&mut self) { @@ -190,9 +195,7 @@ impl<'a> CoordState<'a> { )); } - if !self.keep_windows_pipe_alive.load(Ordering::SeqCst) { - - } + if !self.keep_windows_pipe_alive.load(Ordering::SeqCst) {} if !self.sck_alive_server.load(Ordering::SeqCst) { info!("Restarting socket server"); diff --git a/src/coordinator/remote_video_processor.rs b/src/coordinator/remote_video_processor.rs index a6b66b4..2763018 100644 --- a/src/coordinator/remote_video_processor.rs +++ b/src/coordinator/remote_video_processor.rs @@ -94,7 +94,6 @@ pub async fn remote_video_loop( // rate limit updates sleep_until(Instant::now() + Duration::from_millis(50)).await; - } } } @@ -118,7 +117,7 @@ async fn listen_to_messages( process_incoming_string(message.to_string(), &tracker_state) .and_then(|_| calculate_tracking(&tracker_state)) .unwrap_or((0, 0, false)); - + if do_send { if let Err(e) = to_mec .send(ApplicationEvent::MoveEvent( diff --git a/src/main.rs b/src/main.rs index 3447bf3..35982eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,17 @@ +use gtk::prelude::{ApplicationExt, ApplicationExtManual}; use gtk::{glib, Application}; use log::{error, info}; -use gtk::prelude::{ApplicationExt, ApplicationExtManual}; use simplelog::SimpleLogger; use std::{env, sync::Arc}; use tokio::{runtime, sync::RwLock}; use crate::config::load_config; +mod config; mod coordinator; mod gstreamer_pipeline; mod joystick_source; mod remote_sources; -mod config; mod ui; const APP_ID: &str = "net.nickiel.joystick-controller-client"; @@ -50,4 +50,3 @@ fn main() -> glib::ExitCode { exit_code } - diff --git a/src/ui/mod.rs b/src/ui/mod.rs index e41e2f3..75d1d81 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -14,14 +14,13 @@ use crate::config::AppConfig; use crate::coordinator::{start_coordinator, ApplicationEvent, MoveEvent}; use crate::remote_sources::TrackerState; +mod settings_modal; mod socket_panel; mod tracker_panel; -mod settings_modal; use socket_panel::SocketPanel; use tracker_panel::TrackerPanel; - pub enum GuiUpdate { SocketState(bool), MoveEvent(MoveEvent), @@ -84,7 +83,6 @@ pub fn on_activate(app: &Application) { app.set_menubar(Some(&menubar)); info!("Menu bar set up"); - } pub fn build_ui(app: &Application, config: Arc>, runtime: Handle) { @@ -101,7 +99,6 @@ pub fn build_ui(app: &Application, config: Arc>, runtime: Hand .child(&main_box) .build(); - let rt = runtime.clone(); let config_modal_config = config.clone(); let connections_activate = gio::ActionEntry::builder("connections") @@ -114,7 +111,6 @@ pub fn build_ui(app: &Application, config: Arc>, runtime: Hand app.add_action_entries([connections_activate]); - // Main Event Channel let (to_mec, mec) = async_channel::unbounded::(); let (to_gui, gui_recv) = async_channel::bounded::(10); diff --git a/src/ui/settings_modal.rs b/src/ui/settings_modal.rs index 5bf1cd2..c43a2b7 100644 --- a/src/ui/settings_modal.rs +++ b/src/ui/settings_modal.rs @@ -1,14 +1,16 @@ use std::sync::Arc; use gtk::glib::{self, clone}; -use gtk::{prelude::{BoxExt, ButtonExt, EditableExt}, Application, ApplicationWindow, Box, Button, Entry, Label, Window}; +use gtk::{ + prelude::{BoxExt, ButtonExt, EditableExt}, + Application, ApplicationWindow, Box, Button, Entry, Label, Window, +}; +use log::{error, info}; use tokio::runtime::Handle; use tokio::sync::RwLock; -use log::{error, info}; use crate::config::{save_config, AppConfig}; - pub struct ConnectionsModal { pub window: Window, @@ -16,10 +18,14 @@ pub struct ConnectionsModal { } impl ConnectionsModal { - pub fn new(app: &Application, parent: &ApplicationWindow, rt: &Handle, app_config: &Arc>) -> Self { - + pub fn new( + app: &Application, + parent: &ApplicationWindow, + rt: &Handle, + app_config: &Arc>, + ) -> Self { // Send help :( - let config_read = rt.block_on(async {app_config.read().await}); + let config_read = rt.block_on(async { app_config.read().await }); let main_box = gtk::Box::new(gtk::Orientation::Vertical, 0); @@ -114,39 +120,38 @@ impl ConnectionsModal { main_box.append(&quit_button); let new_ref = app_config.clone(); - quit_button - .connect_activate(clone!( - @strong rt, - @weak camera_ip_entry, @weak camera_port_entry, - @weak tracker_ip_entry, @weak tracker_port_entry, - @weak tracker_refresh_millis => move |_| { + quit_button.connect_activate(clone!( + @strong rt, + @weak camera_ip_entry, @weak camera_port_entry, + @weak tracker_ip_entry, @weak tracker_port_entry, + @weak tracker_refresh_millis => move |_| { - let new_camera_ip = camera_ip_entry.text().to_string(); - let new_camera_port = camera_port_entry.text().parse::().unwrap(); + let new_camera_ip = camera_ip_entry.text().to_string(); + let new_camera_port = camera_port_entry.text().parse::().unwrap(); - let new_tracker_ip = tracker_ip_entry.text().to_string(); - let new_tracker_port = tracker_port_entry.text().parse::().unwrap(); - let new_tracker_millis = tracker_refresh_millis.text().parse::().unwrap(); + let new_tracker_ip = tracker_ip_entry.text().to_string(); + let new_tracker_port = tracker_port_entry.text().parse::().unwrap(); + let new_tracker_millis = tracker_refresh_millis.text().parse::().unwrap(); - { - // maybe just send the police. - let mut write_lock = rt.block_on(async {new_ref.write().await}); + { + // maybe just send the police. + let mut write_lock = rt.block_on(async {new_ref.write().await}); - write_lock.camera_ip = new_camera_ip; - write_lock.camera_port = new_camera_port; + write_lock.camera_ip = new_camera_ip; + write_lock.camera_port = new_camera_port; - write_lock.tracker_ip = new_tracker_ip; - write_lock.tracker_port = new_tracker_port; - write_lock.tracker_refresh_rate_millis = new_tracker_millis; - // why does this feel like the borrow checker gave me a pass? - if let Err(e) = save_config(&write_lock.to_owned()) { - error!("Could not save config! {e}"); - } - // FBI!!! OPEN UP!!!! + write_lock.tracker_ip = new_tracker_ip; + write_lock.tracker_port = new_tracker_port; + write_lock.tracker_refresh_rate_millis = new_tracker_millis; + // why does this feel like the borrow checker gave me a pass? + if let Err(e) = save_config(&write_lock.to_owned()) { + error!("Could not save config! {e}"); } + // FBI!!! OPEN UP!!!! + } - info!("Please nicholas, add a non-crashing parse"); - })); + info!("Please nicholas, add a non-crashing parse"); + })); ConnectionsModal { window, @@ -154,4 +159,4 @@ impl ConnectionsModal { top_level: main_box, } } -} \ No newline at end of file +} diff --git a/src/ui/socket_panel.rs b/src/ui/socket_panel.rs index 516963c..9dea4c7 100644 --- a/src/ui/socket_panel.rs +++ b/src/ui/socket_panel.rs @@ -1,6 +1,8 @@ use async_channel::Sender; use gtk::{ - glib, prelude::{BoxExt, ButtonExt}, Box, Button + glib, + prelude::{BoxExt, ButtonExt}, + Box, Button, }; use log::error; @@ -37,13 +39,11 @@ impl SocketPanel { &self.top_level } - pub fn button_label(&self, new_label: &str) { self.connect_button.set_label(new_label); } pub fn connect_button_callback(&self, to_mec: Sender) { - self.connect_button.connect_clicked(glib::clone!(@strong to_mec => move |_button| { match to_mec.try_send(ApplicationEvent::StartCameraSocket) { Ok(_) => {},