This commit is contained in:
Nickiel12 2022-01-02 21:55:14 -08:00
commit 849d73d4a8
7 changed files with 71 additions and 72 deletions

View file

@ -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%}
}

View file

@ -13,12 +13,12 @@ pub fn create_keyboard_hooks(channel_tx: crossbeam_channel::Sender<String>, 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);
@ -49,6 +49,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(),
@ -61,11 +62,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));
@ -74,11 +77,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));
@ -88,6 +93,7 @@ impl Hotkeys {
}
pub fn change_scene(&self, scene: Scenes, sub_scene: Option<SubScenes>) {
println!("sending: {:?} : {:?}", scene, sub_scene);
let hotkey: &str;
if scene == Scenes::Augmented {
hotkey = self.hotkeys["hotkeys"]["obs"]["camera_scene_augmented"].as_str().unwrap()
@ -148,8 +154,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);

View file

@ -13,8 +13,9 @@ impl MessageHandler for StreamState {
fn handle_update(&mut self, update: StateUpdate, hotkey_handler: &Hotkeys)
-> (Option<StateUpdate>, Option<Vec<StateUpdate>>) {
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,20 +82,20 @@ 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!("{:?}", value);
if value == Scenes::Screen {
if self.current_scene != Scenes::Screen {
self.timer_start = SystemTime::now();
@ -98,9 +105,8 @@ impl MessageHandler for StreamState {
self.timer_finished = true;
}
if self.current_scene != value {
match self.current_scene {
match value {
Scenes::Camera => {
hotkey_handler.change_scene(Scenes::Camera, Some(self.camera_sub_scene));
},
@ -108,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);
}
}

View file

@ -60,6 +60,8 @@ impl Scenes {
#[derive(PartialEq, Debug, Clone, Copy)]
pub enum SlideChange {
Next,
Previous,
NextApp,
PreviousApp,
NextHotkey,
PreviousHotkey,
}

View file

@ -72,8 +72,12 @@ impl StateUpdate {
"Stream_Running" => {StateUpdate::StreamRunning(incoming_json["data"].as_bool().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)}
}
@ -110,8 +114,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 => {

View file

@ -64,43 +64,12 @@ 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::SceneIsAugmented(new_val) => {self.scene_is_augmented = new_val;},
StateUpdate::Scene(_) => {},
StateUpdate::SubScene(_) => {},
StateUpdate::ComputerMediaDoPause => {},
StateUpdate::ChangeSlide(_value) => {panic!("Stream_states_class is not supposed to get this update type");},
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},
}
}
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;
}
}

View file

@ -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()));
}