From 6134ef88435f2969891a6b649c9e055dc7edb6e2 Mon Sep 17 00:00:00 2001 From: Nickiel12 <35903114+Nickiel12@users.noreply.github.com> Date: Thu, 30 Dec 2021 17:30:25 -0800 Subject: [PATCH] more things --- src/modules/message_handler.rs | 22 ++++++++++++++++++++-- src/modules/socket_handler.rs | 6 +++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/modules/message_handler.rs b/src/modules/message_handler.rs index 2955bfb..81a2ad3 100644 --- a/src/modules/message_handler.rs +++ b/src/modules/message_handler.rs @@ -58,7 +58,17 @@ impl MessageHandler for StreamState { return (Some(update), Some(instructions)); } }, - StateUpdate::TimerCanRun(value) => {self.timer_can_run = value; return (Some(update), None)}, + StateUpdate::TimerCanRun(value) => { + self.timer_can_run = value; + self.timer_start = SystemTime::now(); + if value { + let mut instruction = Vec::new(); + instruction.push(StateUpdate::TimerText(String::from("0.0"))); + return (Some(update), Some(instruction)) + } else { + return (Some(update), None); + } + } StateUpdate::TimerLength(value) => {self.timer_length = value; return (Some(update), None)}, StateUpdate::TimerText(value) => {self.timer_text = value.clone(); return (Some(StateUpdate::TimerText(value)), None)}, StateUpdate::SubScene(value) => { @@ -79,6 +89,14 @@ impl MessageHandler for StreamState { StateUpdate::Scene(value) => { hotkey_handler.change_scene(value, None); self.current_scene = value; + + if value == Scenes::Screen { + self.timer_start = SystemTime::now(); + self.timer_finished = false; + } else { + self.timer_finished = true; + } + return (Some(update), None); }, StateUpdate::StreamSoundToggleOn(value) => {hotkey_handler.toggle_stream_sound(value); return (Some(update), None)}, @@ -92,7 +110,7 @@ impl MessageHandler for StreamState { } fn tick(&mut self) -> (Option, Option) { - if self.timer_finished == false { + if self.timer_finished == false && self.timer_can_run == true { let change = self.timer_start.elapsed(); match change { Err(_) => {(None, None)}, diff --git a/src/modules/socket_handler.rs b/src/modules/socket_handler.rs index 6e5e5a4..7bc4453 100644 --- a/src/modules/socket_handler.rs +++ b/src/modules/socket_handler.rs @@ -53,7 +53,7 @@ impl Socket { pub fn handle_client(stream: Arc, update_tx: Sender, program_shutdown_flag: sync_flag::SyncFlagRx) { let mut buffer = [0; 1024]; - stream.set_read_timeout(Some(Duration::from_millis(100))).expect("Could not set a read timeout"); + stream.set_read_timeout(Some(Duration::from_millis(10))).expect("Could not set a read timeout"); while program_shutdown_flag.get() { match stream.as_ref().read(&mut buffer) { Err(_) => {}, @@ -85,11 +85,11 @@ impl Socket { let mut tx = streams.get(i).unwrap().as_ref(); match tx.write(message.clone().as_bytes()) { - Err(_) => {streams.remove(i); continue;}, + Err(_) => {streams.remove(i); println!("removed a socket"); continue;}, Ok(_) => {}, } + tx.write(b"\n").unwrap(); tx.flush().unwrap(); - println!("sent"); } } } \ No newline at end of file