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] 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 => {