From 480f5b0c113cd306638ce71cb26cce9c628b15c7 Mon Sep 17 00:00:00 2001 From: Nickiel12 <35903114+Nickiel12@users.noreply.github.com> Date: Fri, 31 Dec 2021 19:34:24 -0800 Subject: [PATCH 1/5] added differentiation of hotkey and app --- src/modules/external_interface.rs | 21 +++++++++++++-------- src/modules/stream_states/enums.rs | 14 ++++---------- src/modules/stream_states/state_update.rs | 14 ++++++++++---- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/modules/external_interface.rs b/src/modules/external_interface.rs index 2fdb52d..0ae08d5 100644 --- a/src/modules/external_interface.rs +++ b/src/modules/external_interface.rs @@ -13,12 +13,12 @@ pub fn create_keyboard_hooks(channel_tx: crossbeam_channel::Sender, clos let tx_1 = channel_tx.clone(); inputbot::KeybdKey::PageUpKey.bind(move || { - tx_1.send(StateUpdate::ChangeSlide(SlideChange::Next).to_json().to_string()).unwrap(); + tx_1.send(StateUpdate::ChangeSlide(SlideChange::PreviousHotkey).to_json().to_string()).unwrap(); }); let tx_2 = channel_tx.clone(); inputbot::KeybdKey::PageDownKey.bind(move || { - tx_2.send(StateUpdate::ChangeSlide(SlideChange::Previous).to_json().to_string()).unwrap(); + tx_2.send(StateUpdate::ChangeSlide(SlideChange::NextHotkey).to_json().to_string()).unwrap(); }); inputbot::handle_input_events(close_flag); @@ -42,6 +42,7 @@ impl Hotkeys { } pub fn send_obs(&self, hotkey: &str) { if cfg!(target_family = "windows") { + println!("sending to obs"); Command::new(String::from(AHK_FILES_FOLDER) + "send_obs_back_to_propre.exe") .args([self.hotkeys["windows"]["propresenter_re"].as_str().unwrap(), self.hotkeys["windows"]["obs_re"].as_str().unwrap(), @@ -54,11 +55,13 @@ impl Hotkeys { }; } - pub fn next_slide(&self) { + pub fn next_slide(&self, from_hotkey: bool) { + let from_hotkey_str = {if from_hotkey {"1"} else {"0"}}; if cfg!(target_family = "windows") { Command::new(String::from(AHK_FILES_FOLDER) + "propre_send.exe") .args([self.hotkeys["windows"]["propresenter_re"].as_str().unwrap(), - self.hotkeys["general"]["clicker_forward"].as_str().unwrap()]) + self.hotkeys["general"]["clicker_forward"].as_str().unwrap(), + from_hotkey_str]) .spawn() .expect("next_slide process call failed"); std::thread::sleep(std::time::Duration::from_millis(200)); @@ -67,11 +70,13 @@ impl Hotkeys { }; } - pub fn prev_slide(&self) { + pub fn prev_slide(&self, from_hotkey: bool) { + let from_hotkey_str = {if from_hotkey {"1"} else {"0"}}; if cfg!(target_family = "windows") { Command::new(String::from(AHK_FILES_FOLDER) + "propre_send.exe") .args([self.hotkeys["windows"]["propresenter_re"].as_str().unwrap(), - self.hotkeys["general"]["clicker_backward"].as_str().unwrap()]) + self.hotkeys["general"]["clicker_backward"].as_str().unwrap(), + from_hotkey_str]) .spawn() .expect("next_slide process call failed"); std::thread::sleep(std::time::Duration::from_millis(200)); @@ -142,8 +147,8 @@ fn hotkeys() { hotkeys: settings_json, }; hk.change_scene(Scenes::Augmented, Some(SubScenes::CameraDefault)); - hk.next_slide(); - hk.prev_slide(); + hk.next_slide(false); + hk.prev_slide(false); hk.send_obs("a hotkey"); hk.toggle_computer_sound(true); hk.toggle_stream_sound(true); diff --git a/src/modules/stream_states/enums.rs b/src/modules/stream_states/enums.rs index c62d47f..6462676 100644 --- a/src/modules/stream_states/enums.rs +++ b/src/modules/stream_states/enums.rs @@ -60,16 +60,10 @@ impl Scenes { #[derive(PartialEq, Debug, Clone, Copy)] pub enum SlideChange { - Next, - Previous, + NextApp, + PreviousApp, + NextHotkey, + PreviousHotkey, } -impl SlideChange { - pub fn to_string(&self) -> String { - match self { - SlideChange::Next => {String::from_str("Next_Slide").unwrap()}, - SlideChange::Previous => {String::from_str("Prev_Slide").unwrap()}, - } - } -} diff --git a/src/modules/stream_states/state_update.rs b/src/modules/stream_states/state_update.rs index 8670357..940a363 100644 --- a/src/modules/stream_states/state_update.rs +++ b/src/modules/stream_states/state_update.rs @@ -73,8 +73,12 @@ impl StateUpdate { "Stream_Running" => {StateUpdate::StreamRunning(string_to_bool(incoming_json["data"].as_str().unwrap()))} - "Next_Slide" => {StateUpdate::ChangeSlide(SlideChange::Next)}, - "Prev_Slide" => {StateUpdate::ChangeSlide(SlideChange::Previous)} + "Next_Slide" => { + if incoming_json["data"] == "hotkey" {StateUpdate::ChangeSlide(SlideChange::NextHotkey)} + else {StateUpdate::ChangeSlide(SlideChange::NextApp)}}, + "Prev_Slide" => { + if incoming_json["data"] == "hotkey" {StateUpdate::ChangeSlide(SlideChange::PreviousHotkey)} + else {StateUpdate::ChangeSlide(SlideChange::PreviousApp)}} //Unimplemented _ => {panic!("trying to use a button type I don't know!: {}", value)} } @@ -111,8 +115,10 @@ impl StateUpdate { ("Toggle_Computer_Volume", "".to_string())}, StateUpdate::ChangeSlide(value) => { match value { - SlideChange::Next => {("Next_Slide", "".to_string())}, - SlideChange::Previous => {("Prev_Slide", "".to_string())}, + SlideChange::NextApp => {("Next_Slide", "".to_string())}, + SlideChange::NextHotkey => {("Next_Slide", "hotkey".to_string())}, + SlideChange::PreviousApp => {("Prev_Slide", "".to_string())}, + SlideChange::PreviousHotkey => {("Prev_Slide", "hotkey".to_string())}, } }, StateUpdate::UpdateClient => { From 1738a030c4bb43211788a664737ba5577b312ede Mon Sep 17 00:00:00 2001 From: Nickiel12 <35903114+Nickiel12@users.noreply.github.com> Date: Fri, 31 Dec 2021 19:34:40 -0800 Subject: [PATCH 2/5] bug fixes --- src/modules/message_handler.rs | 30 +++++++++++------- .../stream_states/stream_states_class.rs | 31 +++---------------- 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/src/modules/message_handler.rs b/src/modules/message_handler.rs index 9d40cc9..037911b 100644 --- a/src/modules/message_handler.rs +++ b/src/modules/message_handler.rs @@ -13,8 +13,9 @@ impl MessageHandler for StreamState { fn handle_update(&mut self, update: StateUpdate, hotkey_handler: &Hotkeys) -> (Option, Option>) { - if update != StateUpdate::UpdateClient && update != StateUpdate::ChangeSlide(SlideChange::Next) && - update != StateUpdate::ChangeSlide(SlideChange::Previous){ + if update != StateUpdate::UpdateClient && update != StateUpdate::ChangeSlide(SlideChange::NextApp) && + update != StateUpdate::ChangeSlide(SlideChange::PreviousApp) && update != StateUpdate::ChangeSlide(SlideChange::PreviousHotkey) + && update != StateUpdate::ChangeSlide(SlideChange::NextHotkey) { self.update(update.clone()); } @@ -29,12 +30,18 @@ impl MessageHandler for StreamState { self.timer_start = SystemTime::now(); } match direction { - SlideChange::Next => { - hotkey_handler.next_slide(); + SlideChange::NextHotkey => { + hotkey_handler.next_slide(true); + }, + SlideChange::NextApp => { + hotkey_handler.next_slide(false); + }, + SlideChange::PreviousHotkey => { + hotkey_handler.prev_slide(true); + }, + SlideChange::PreviousApp => { + hotkey_handler.prev_slide(false); }, - SlideChange::Previous => { - hotkey_handler.prev_slide(); - } } if self.change_scene_on_change_slide_hotkey { let mut instructions = Vec::new(); @@ -75,22 +82,24 @@ impl MessageHandler for StreamState { StateUpdate::SubScene(value) => { if value.get_type() == Scenes::Camera { if self.current_scene == Scenes::Camera { - hotkey_handler.change_scene(Scenes::Camera, Some(self.camera_sub_scene)); + hotkey_handler.change_scene(Scenes::Camera, Some(value)); } self.camera_sub_scene = value; return (Some(update), None) } else if value.get_type() == Scenes::Screen { if self.current_scene == Scenes::Screen{ - hotkey_handler.change_scene(Scenes::Screen, Some(self.screen_sub_scene)); + hotkey_handler.change_scene(Scenes::Screen, Some(value)); } self.screen_sub_scene = value; return (Some(update), None) } }, StateUpdate::Scene(value) => { - + println!("dong: {:?}", value); if value == Scenes::Screen { + println!("doink: {:?}", self.current_scene); if self.current_scene != Scenes::Screen { + println!("ping"); self.timer_start = SystemTime::now(); self.timer_finished = false; } @@ -98,7 +107,6 @@ impl MessageHandler for StreamState { self.timer_finished = true; } - if self.current_scene != value { match self.current_scene { Scenes::Camera => { diff --git a/src/modules/stream_states/stream_states_class.rs b/src/modules/stream_states/stream_states_class.rs index 9f627ab..65bb099 100644 --- a/src/modules/stream_states/stream_states_class.rs +++ b/src/modules/stream_states/stream_states_class.rs @@ -64,14 +64,14 @@ impl StreamState { StateUpdate::TimerCanRun(new_val) => {self.timer_can_run = new_val;}, StateUpdate::TimerLength(new_val) => {self.timer_length = new_val;}, StateUpdate::TimerText(new_val) => {self.timer_text = new_val;}, - StateUpdate::Scene(new_val) => {self.change_scene(&new_val)}, - StateUpdate::SubScene(new_val) => {self.change_sub_scene(&new_val)}, StateUpdate::SceneIsAugmented(new_val) => { self.scene_is_augmented = new_val; self.change_scene(&Scenes::Augmented)}, - StateUpdate::ComputerMediaDoPause => {}, - StateUpdate::ChangeSlide(_value) => {panic!("Stream_states_class is not supposed to get this update type");}, - StateUpdate::UpdateClient => {}, + StateUpdate::Scene(_) => {}, + StateUpdate::SubScene(_) => {}, + StateUpdate::ComputerMediaDoPause => {}, + StateUpdate::ChangeSlide(_value) => {panic!("Stream_states_class is not supposed to get this update type");}, + StateUpdate::UpdateClient => {}, } } @@ -82,25 +82,4 @@ impl StreamState { Scenes::Screen => {self.current_scene = *scene}, } } - - pub fn change_sub_scene(&mut self, scene: &SubScenes) { - match scene { - SubScenes::CameraDefault | SubScenes::CameraWithUpperRight | - SubScenes::CameraWithLargeUpperRight | SubScenes::CameraWithLowerRight - => {StreamState::set_camera_scene(self, scene)}, - SubScenes::ScreenDefault | SubScenes::ScreenWithUpperRight | - SubScenes::ScreenWithLowerRight - => {StreamState::set_screen_scene(self, scene)}, - } - } - - fn set_camera_scene(&mut self, scene: &SubScenes) { - self.camera_sub_scene = scene.clone(); - self.current_scene = Scenes::Camera; - } - - fn set_screen_scene(&mut self, scene: &SubScenes) { - self.screen_sub_scene = scene.clone(); - self.current_scene = Scenes::Screen; - } } From b158b9068eb22209079cccf1d5dab37b8c9d1e02 Mon Sep 17 00:00:00 2001 From: Nickiel12 <35903114+Nickiel12@users.noreply.github.com> Date: Fri, 31 Dec 2021 19:34:48 -0800 Subject: [PATCH 3/5] bug fixes --- src/modules/message_handler.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/modules/message_handler.rs b/src/modules/message_handler.rs index 037911b..83c3d85 100644 --- a/src/modules/message_handler.rs +++ b/src/modules/message_handler.rs @@ -95,9 +95,7 @@ impl MessageHandler for StreamState { } }, StateUpdate::Scene(value) => { - println!("dong: {:?}", value); if value == Scenes::Screen { - println!("doink: {:?}", self.current_scene); if self.current_scene != Scenes::Screen { println!("ping"); self.timer_start = SystemTime::now(); From 6b7edb7ce8766c7b79451142435cb353863bfa07 Mon Sep 17 00:00:00 2001 From: Nickiel12 <35903114+Nickiel12@users.noreply.github.com> Date: Fri, 31 Dec 2021 19:35:04 -0800 Subject: [PATCH 4/5] added from hotkey checks --- ahk_files/propre_send.ahk | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/ahk_files/propre_send.ahk b/ahk_files/propre_send.ahk index 8521d22..980394a 100644 --- a/ahk_files/propre_send.ahk +++ b/ahk_files/propre_send.ahk @@ -8,10 +8,19 @@ SetTitleMatchMode, Fast If WinExist(A_Args[1]) ; propresenter { ; if propresenter isn't active, switch and send clicker forward - if !WinActive(A_Args[1]){ - WinActivate - sleep 200 + if (A_Args[3]) { ; 1 for from_hotkey 0 for from app + if !WinActive(A_Args[1]){ + WinActivate + sleep 200 + arg := A_Args[2] + Send {%arg%} + } + } else { + if !WinActive(A_Args[1]){ + WinActivate + sleep 200 + } + arg := A_Args[2] + Send {%arg%} } - arg := A_Args[2] - Send {%arg%} } \ No newline at end of file From 23dceaf2ba9deba66cc6978c1f810f550da52aae Mon Sep 17 00:00:00 2001 From: Nickiel12 <35903114+Nickiel12@users.noreply.github.com> Date: Fri, 31 Dec 2021 19:54:52 -0800 Subject: [PATCH 5/5] got rid of delayed sending --- src/modules/external_interface.rs | 1 + src/modules/message_handler.rs | 5 +++-- src/modules/stream_states/stream_states_class.rs | 12 +----------- src/tests/state_update_tests.rs | 8 ++++---- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/modules/external_interface.rs b/src/modules/external_interface.rs index 0ae08d5..12f4081 100644 --- a/src/modules/external_interface.rs +++ b/src/modules/external_interface.rs @@ -86,6 +86,7 @@ impl Hotkeys { } pub fn change_scene(&self, scene: Scenes, sub_scene: Option) { + println!("sending: {:?} : {:?}", scene, sub_scene); let hotkey: &str; if scene == Scenes::Augmented { hotkey = self.hotkeys["hotkeys"]["obs"]["camera_scene_augmented"].as_str().unwrap() diff --git a/src/modules/message_handler.rs b/src/modules/message_handler.rs index 83c3d85..b4c2c13 100644 --- a/src/modules/message_handler.rs +++ b/src/modules/message_handler.rs @@ -95,9 +95,9 @@ impl MessageHandler for StreamState { } }, StateUpdate::Scene(value) => { + println!("{:?}", value); if value == Scenes::Screen { if self.current_scene != Scenes::Screen { - println!("ping"); self.timer_start = SystemTime::now(); self.timer_finished = false; } @@ -106,7 +106,7 @@ impl MessageHandler for StreamState { } if self.current_scene != value { - match self.current_scene { + match value { Scenes::Camera => { hotkey_handler.change_scene(Scenes::Camera, Some(self.camera_sub_scene)); }, @@ -114,6 +114,7 @@ impl MessageHandler for StreamState { hotkey_handler.change_scene(Scenes::Screen, Some(self.screen_sub_scene)); }, Scenes::Augmented => { + println!("Augment!"); hotkey_handler.change_scene(Scenes::Augmented, None); } } diff --git a/src/modules/stream_states/stream_states_class.rs b/src/modules/stream_states/stream_states_class.rs index 65bb099..e4ac6ed 100644 --- a/src/modules/stream_states/stream_states_class.rs +++ b/src/modules/stream_states/stream_states_class.rs @@ -64,9 +64,7 @@ impl StreamState { StateUpdate::TimerCanRun(new_val) => {self.timer_can_run = new_val;}, StateUpdate::TimerLength(new_val) => {self.timer_length = new_val;}, StateUpdate::TimerText(new_val) => {self.timer_text = new_val;}, - StateUpdate::SceneIsAugmented(new_val) => { - self.scene_is_augmented = new_val; - self.change_scene(&Scenes::Augmented)}, + StateUpdate::SceneIsAugmented(new_val) => {self.scene_is_augmented = new_val;}, StateUpdate::Scene(_) => {}, StateUpdate::SubScene(_) => {}, StateUpdate::ComputerMediaDoPause => {}, @@ -74,12 +72,4 @@ impl StreamState { StateUpdate::UpdateClient => {}, } } - - pub fn change_scene(&mut self, scene: &Scenes) { - match scene { - Scenes::Augmented => {self.current_scene = *scene;} - Scenes::Camera => {self.current_scene = *scene}, - Scenes::Screen => {self.current_scene = *scene}, - } - } } diff --git a/src/tests/state_update_tests.rs b/src/tests/state_update_tests.rs index 50c2645..d485cb0 100644 --- a/src/tests/state_update_tests.rs +++ b/src/tests/state_update_tests.rs @@ -86,11 +86,11 @@ fn test_json_to_state_update() { assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( "{\"type\": \"update\", \"update\": \"Next_Slide\"}" - ).unwrap()), StateUpdate::ChangeSlide(SlideChange::Next)); + ).unwrap()), StateUpdate::ChangeSlide(SlideChange::NextHotkey)); assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( "{\"type\": \"update\", \"update\": \"Prev_Slide\"}" - ).unwrap()), StateUpdate::ChangeSlide(SlideChange::Previous)); + ).unwrap()), StateUpdate::ChangeSlide(SlideChange::PreviousHotkey)); assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( "{\"type\": \"update\", \"update\":\"all\"}" @@ -131,8 +131,8 @@ fn test_state_update_to_json() { assert_eq!(StateUpdate::SubScene(SubScenes::ScreenWithLowerRight), StateUpdate::json_to_state_update(StateUpdate::SubScene(SubScenes::ScreenWithLowerRight).to_json())); assert_eq!(StateUpdate::Scene(Scenes::Camera), StateUpdate::json_to_state_update(StateUpdate::Scene(Scenes::Camera).to_json())); assert_eq!(StateUpdate::Scene(Scenes::Screen), StateUpdate::json_to_state_update(StateUpdate::Scene(Scenes::Screen).to_json())); - assert_eq!(StateUpdate::ChangeSlide(SlideChange::Next), StateUpdate::json_to_state_update(StateUpdate::ChangeSlide(SlideChange::Next).to_json())); - assert_eq!(StateUpdate::ChangeSlide(SlideChange::Previous), StateUpdate::json_to_state_update(StateUpdate::ChangeSlide(SlideChange::Previous).to_json())); + assert_eq!(StateUpdate::ChangeSlide(SlideChange::NextHotkey), StateUpdate::json_to_state_update(StateUpdate::ChangeSlide(SlideChange::NextHotkey).to_json())); + assert_eq!(StateUpdate::ChangeSlide(SlideChange::PreviousHotkey), StateUpdate::json_to_state_update(StateUpdate::ChangeSlide(SlideChange::PreviousHotkey).to_json())); assert_eq!(StateUpdate::UpdateClient, StateUpdate::json_to_state_update(StateUpdate::UpdateClient.to_json())); } \ No newline at end of file