diff --git a/Cargo.toml b/Cargo.toml index 13f2c9b..fba248a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,4 @@ workctl = "0.2.0" ctrlc = "3.2.1" serde_json = "1.0" crossbeam-channel = "0.5" -inputbot = {path = "/home/nick/Documents/GitHub/InputBot"} \ No newline at end of file +inputbot = {path = "D:\\InputBot"} \ No newline at end of file diff --git a/src/ahk_files/music_toggle.ahk b/ahk_files/music_toggle.ahk similarity index 100% rename from src/ahk_files/music_toggle.ahk rename to ahk_files/music_toggle.ahk diff --git a/src/ahk_files/pause_play_global.ahk b/ahk_files/pause_play_global.ahk similarity index 100% rename from src/ahk_files/pause_play_global.ahk rename to ahk_files/pause_play_global.ahk diff --git a/src/ahk_files/program_opener.ahk b/ahk_files/program_opener.ahk similarity index 100% rename from src/ahk_files/program_opener.ahk rename to ahk_files/program_opener.ahk diff --git a/src/ahk_files/program_opener_debug.ahk b/ahk_files/program_opener_debug.ahk similarity index 100% rename from src/ahk_files/program_opener_debug.ahk rename to ahk_files/program_opener_debug.ahk diff --git a/src/ahk_files/propre_send.ahk b/ahk_files/propre_send.ahk similarity index 90% rename from src/ahk_files/propre_send.ahk rename to ahk_files/propre_send.ahk index 6189205..8521d22 100644 --- a/src/ahk_files/propre_send.ahk +++ b/ahk_files/propre_send.ahk @@ -10,6 +10,8 @@ If WinExist(A_Args[1]) ; propresenter { ; if propresenter isn't active, switch and send clicker forward if !WinActive(A_Args[1]){ WinActivate - Send A_Args[2] + sleep 200 } + arg := A_Args[2] + Send {%arg%} } \ No newline at end of file diff --git a/src/ahk_files/send_obs_back_to_propre.ahk b/ahk_files/send_obs_back_to_propre.ahk similarity index 90% rename from src/ahk_files/send_obs_back_to_propre.ahk rename to ahk_files/send_obs_back_to_propre.ahk index 1f014df..128eb60 100644 --- a/src/ahk_files/send_obs_back_to_propre.ahk +++ b/ahk_files/send_obs_back_to_propre.ahk @@ -10,10 +10,14 @@ If WinExist(A_Args[2]) ;OBS { ; if obs isn't active, switch to it, and send the hotkey If !WinActive(A_Args[2]) { WinActivate - Send A_Args[3] + sleep 200 } + arg := A_Args[3] + Send {%arg%} } +sleep 100 + If WinExist(A_Args[1]) ; Propresenter { ; switch back to propresenter If !WinActive(A_Args[1]) { diff --git a/src/ahk_files/window_activator.ahk b/ahk_files/window_activator.ahk similarity index 100% rename from src/ahk_files/window_activator.ahk rename to ahk_files/window_activator.ahk diff --git a/options.json b/options.json index 7504793..b75e5e5 100644 --- a/options.json +++ b/options.json @@ -16,24 +16,24 @@ "obs_screen_switch_delay_length": 0.4 }, "windows":{ - "obs_re": "OBS ", + "obs_re": "OBS *", "propresenter_re": "ProPresenter - .*", "chrome_re": ".* - Google Chrome" }, "hotkeys":{ "obs":{ - "camera_scene_hotkey" : "shift+alt+ctrl+*", - "screen_scene_hotkey" : "shift+alt+ctrl+/", - "camera_scene_augmented" : "shift+alt+ctrl+-", - "unmute_stream" : "shift+alt+ctrl+u", - "mute_stream" : "shift+alt+ctrl+i", + "camera_scene_hotkey" : "F13", + "screen_scene_hotkey" : "F14", + "camera_scene_augmented" : "F15", + "unmute_stream" : "shift+F13", + "mute_stream" : "shift+F14", "start_stream" : "ctrl+shift+j", "stop_stream" : "ctrl+alt+j", - "Camera_Top_Right" : "ctrl+alt+]", - "Camera_Bottom_Right" : "ctrl+shift+]", - "Camera_Large_Top_Right" : "ctrl+shift+alt+]", - "Screen_Top_Right" : "ctrl+alt+[", - "Screen_Bottom_Right" : "ctrl+shift+[" + "Camera_Top_Right" : "F16", + "Camera_Bottom_Right" : "F17", + "Camera_Large_Top_Right" : "F18", + "Screen_Top_Right" : "F19", + "Screen_Bottom_Right" : "F20" }, "general":{ "clicker_forward" : "page down", diff --git a/src/modules/external_interface.rs b/src/modules/external_interface.rs index 8b45fb9..d763378 100644 --- a/src/modules/external_interface.rs +++ b/src/modules/external_interface.rs @@ -1,8 +1,13 @@ use std::process::Command; use super::stream_states::{state_update::StateUpdate, enums::{SlideChange, SubScenes, Scenes}}; -const AHK_FILES_FOLDER: &str = "./src/ahk_files/"; -pub const OPTIONS_PATH: &str = "./options.json"; +const AHK_FILES_FOLDER: &str = ".\\ahk_files\\"; +pub const OPTIONS_PATH: &str = ".\\options.json"; + + /* + const AHK_FILES_FOLDER: &str = "./src/ahk_files/"; + pub const OPTIONS_PATH: &str = "./options.json"; + */ pub fn create_keyboard_hooks(channel_tx: crossbeam_channel::Sender, close_flag: workctl::sync_flag::SyncFlagRx) { @@ -24,22 +29,22 @@ pub struct Hotkeys { } impl Hotkeys { - pub fn get_hotkey_from_scene(&self, scene: SubScenes) -> String { + pub fn get_hotkey_from_scene(&self, scene: SubScenes) -> &str { match scene { - SubScenes::CameraDefault => {self.hotkeys["hotkeys"]["obs"]["camera_scene_hotkey"].to_string()}, - SubScenes::CameraWithUpperRight => {self.hotkeys["hotkeys"]["obs"]["Camera_Top_Right"].to_string()}, - SubScenes::CameraWithLargeUpperRight => {self.hotkeys["hotkeys"]["obs"]["Camera_Large_Top_Right"].to_string()}, - SubScenes::CameraWithLowerRight => {self.hotkeys["hotkeys"]["obs"]["Camera_Bottom_Right"].to_string()}, - SubScenes::ScreenDefault => {self.hotkeys["hotkeys"]["obs"]["screen_scene_hotkey"].to_string()}, - SubScenes::ScreenWithUpperRight => {self.hotkeys["hotkeys"]["obs"]["Screen_Top_Right"].to_string()}, - SubScenes::ScreenWithLowerRight => {self.hotkeys["hotkeys"]["obs"]["Screen_Bottom_Right"].to_string()}, + SubScenes::CameraDefault => {self.hotkeys["hotkeys"]["obs"]["camera_scene_hotkey"].as_str().unwrap()}, + SubScenes::CameraWithUpperRight => {self.hotkeys["hotkeys"]["obs"]["Camera_Top_Right"].as_str().unwrap()}, + SubScenes::CameraWithLargeUpperRight => {self.hotkeys["hotkeys"]["obs"]["Camera_Large_Top_Right"].as_str().unwrap()}, + SubScenes::CameraWithLowerRight => {self.hotkeys["hotkeys"]["obs"]["Camera_Bottom_Right"].as_str().unwrap()}, + SubScenes::ScreenDefault => {self.hotkeys["hotkeys"]["obs"]["screen_scene_hotkey"].as_str().unwrap()}, + SubScenes::ScreenWithUpperRight => {self.hotkeys["hotkeys"]["obs"]["Screen_Top_Right"].as_str().unwrap()}, + SubScenes::ScreenWithLowerRight => {self.hotkeys["hotkeys"]["obs"]["Screen_Bottom_Right"].as_str().unwrap()}, } } - pub fn send_obs(&self, hotkey: String) { - if cfg!(target_os = "windows") { + pub fn send_obs(&self, hotkey: &str) { + if cfg!(target_family = "windows") { Command::new(String::from(AHK_FILES_FOLDER) + "send_obs_back_to_propre.exe") - .args([self.hotkeys["windows"]["propresenter_re"].to_string(), - self.hotkeys["windows"]["obs_re"].to_string(), + .args([self.hotkeys["windows"]["propresenter_re"].as_str().unwrap(), + self.hotkeys["windows"]["obs_re"].as_str().unwrap(), hotkey]) .spawn() .expect("next_slide process call failed"); @@ -49,33 +54,33 @@ impl Hotkeys { } pub fn next_slide(&self) { - if cfg!(target_os = "windows") { + if cfg!(target_family = "windows") { Command::new(String::from(AHK_FILES_FOLDER) + "switch_and_send.exe") - .args([self.hotkeys["windows"]["propresenter_re"].to_string(), - self.hotkeys["general"]["clicker_forward"].to_string()]) + .args([self.hotkeys["windows"]["propresenter_re"].as_str().unwrap(), + self.hotkeys["general"]["clicker_forward"].as_str().unwrap()]) .spawn() .expect("next_slide process call failed"); } else { - println!("pretend linux is sending prosenter next: {}", self.hotkeys["general"]["clicker_forward"].to_string()) + println!("pretend linux is sending prosenter next: {}", self.hotkeys["general"]["clicker_forward"].as_str().unwrap()) }; } pub fn prev_slide(&self) { - if cfg!(target_os = "windows") { + if cfg!(target_family = "windows") { Command::new(String::from(AHK_FILES_FOLDER) + "switch_and_send.exe") - .args([self.hotkeys["windows"]["propresenter_re"].to_string(), - self.hotkeys["general"]["clicker_backward"].to_string()]) + .args([self.hotkeys["windows"]["propresenter_re"].as_str().unwrap(), + self.hotkeys["general"]["clicker_backward"].as_str().unwrap()]) .spawn() .expect("next_slide process call failed"); } else { - println!("pretend linux is sending prosenter next: {}", self.hotkeys["general"]["clicker_backward"].to_string()) + println!("pretend linux is sending prosenter next: {}", self.hotkeys["general"]["clicker_backward"].as_str().unwrap()) }; } - pub fn change_scene(&self, _scene: Scenes, sub_scene: Option) { - let hotkey: String; - if sub_scene.is_none() { - hotkey = self.hotkeys["hotkeys"]["obs"]["camera_scene_augmented"].to_string() + pub fn change_scene(&self, scene: Scenes, sub_scene: Option) { + let hotkey: &str; + if scene == Scenes::Augmented { + hotkey = self.hotkeys["hotkeys"]["obs"]["camera_scene_augmented"].as_str().unwrap() } else { hotkey = self.get_hotkey_from_scene(sub_scene.unwrap()) }; @@ -83,11 +88,11 @@ impl Hotkeys { } pub fn toggle_stream_sound(&self, turn_on: bool) { - let hotkey: String; + let hotkey: &str; if turn_on { - hotkey = self.hotkeys["hotkeys"]["obs"]["unmute_stream"].to_string(); + hotkey = self.hotkeys["hotkeys"]["obs"]["unmute_stream"].as_str().unwrap(); } else { - hotkey = self.hotkeys["hotkeys"]["obs"]["mute_stream"].to_string(); + hotkey = self.hotkeys["hotkeys"]["obs"]["mute_stream"].as_str().unwrap(); } self.send_obs(hotkey); } @@ -95,25 +100,25 @@ impl Hotkeys { pub fn toggle_computer_sound(&self, value: bool) { let direction: u8 = if value {1} else {0}; let time_delay = self.hotkeys["general"]["music_fade_time"].as_i64().unwrap(); - if cfg!(target_os = "windows") { + if cfg!(target_family = "windows") { Command::new(String::from(AHK_FILES_FOLDER) + "music_toggle.exe") .arg(direction.to_string()) .arg(time_delay.to_string()) .spawn() .expect("next_slide process call failed"); } else { - println!("pretend linux is sending prosenter next: {}", self.hotkeys["general"]["clicker_backward"].to_string()) + println!("pretend linux is sending prosenter next: {}", self.hotkeys["general"]["clicker_backward"].as_str().unwrap()) }; } pub fn toggle_media_play_pause(&self) { - if cfg!(target_os = "windows") { + if cfg!(target_family = "windows") { Command::new(String::from(AHK_FILES_FOLDER) + "music_toggle.exe") - .arg(self.hotkeys["windows"]["propresenter_re"].to_string()) + .arg(self.hotkeys["windows"]["propresenter_re"].as_str().unwrap()) .spawn() .expect("next_slide process call failed"); } else { - println!("pretend linux is sending prosenter next: {}", self.hotkeys["general"]["clicker_backward"].to_string()) + println!("pretend linux is sending prosenter next: {}", self.hotkeys["general"]["clicker_backward"].as_str().unwrap()) }; } } @@ -136,7 +141,7 @@ fn hotkeys() { hk.change_scene(Scenes::Augmented, Some(SubScenes::CameraDefault)); hk.next_slide(); hk.prev_slide(); - hk.send_obs(String::from("a hotkey")); + hk.send_obs("a hotkey"); hk.toggle_computer_sound(true); hk.toggle_stream_sound(true); hk.toggle_media_play_pause(); diff --git a/src/modules/message_handler.rs b/src/modules/message_handler.rs index 81a2ad3..6a7c83c 100644 --- a/src/modules/message_handler.rs +++ b/src/modules/message_handler.rs @@ -13,7 +13,8 @@ impl MessageHandler for StreamState { fn handle_update(&mut self, update: StateUpdate, hotkey_handler: &Hotkeys) -> (Option, Option>) { - if update != StateUpdate::UpdateClient{ + if update != StateUpdate::UpdateClient && update != StateUpdate::ChangeSlide(SlideChange::Next) && + update != StateUpdate::ChangeSlide(SlideChange::Previous){ self.update(update.clone()); } @@ -87,7 +88,6 @@ impl MessageHandler for StreamState { } }, StateUpdate::Scene(value) => { - hotkey_handler.change_scene(value, None); self.current_scene = value; if value == Scenes::Screen { @@ -97,10 +97,22 @@ impl MessageHandler for StreamState { self.timer_finished = true; } + match self.current_scene { + Scenes::Camera => { + hotkey_handler.change_scene(Scenes::Camera, Some(self.camera_sub_scene)); + }, + Scenes::Screen => { + hotkey_handler.change_scene(Scenes::Screen, Some(self.screen_sub_scene)); + }, + Scenes::Augmented => { + hotkey_handler.change_scene(Scenes::Augmented, None); + } + } + return (Some(update), None); }, StateUpdate::StreamSoundToggleOn(value) => {hotkey_handler.toggle_stream_sound(value); return (Some(update), None)}, - StateUpdate::ToggleComputerSoundOn(value) => {hotkey_handler.toggle_computer_sound(value); return (Some(update), None)}, + StateUpdate::ToggleComputerSoundOn(value) => {hotkey_handler.toggle_computer_sound(!value); return (Some(StateUpdate::ToggleComputerSoundOn(!value)), None)}, StateUpdate::ComputerMediaDoPause => {hotkey_handler.toggle_media_play_pause(); return (Some(update), None)}, StateUpdate::UpdateClient => {}, StateUpdate::StreamRunning(_) => {}, diff --git a/src/modules/socket_handler.rs b/src/modules/socket_handler.rs index 7bc4453..9734d5f 100644 --- a/src/modules/socket_handler.rs +++ b/src/modules/socket_handler.rs @@ -81,6 +81,7 @@ impl Socket { pub fn send(&self, message: String) { let mut streams = self.socket_txs.lock().unwrap(); + if streams.len() == 0 {return} for i in 0..streams.len(){ let mut tx = streams.get(i).unwrap().as_ref(); diff --git a/src/todo.txt b/src/todo.txt new file mode 100644 index 0000000..b448049 --- /dev/null +++ b/src/todo.txt @@ -0,0 +1,3 @@ +also, that weird "dropped connection, i be silent" bug is still there. Is it a windows file descriptor drop? + +Next events are crashing the program \ No newline at end of file