Merge pull request #1 from Nickiel12/windows

Windows
This commit is contained in:
Nickiel12 2021-12-31 09:45:11 -08:00 committed by GitHub
commit 97a2bf9744
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 79 additions and 52 deletions

View file

@ -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"}
inputbot = {path = "D:\\InputBot"}

View file

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

View file

@ -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]) {

View file

@ -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",

View file

@ -1,8 +1,13 @@
use std::process::Command;
use super::stream_states::{state_update::StateUpdate, enums::{SlideChange, SubScenes, Scenes}};
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<String>, 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<SubScenes>) {
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<SubScenes>) {
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();

View file

@ -13,7 +13,8 @@ impl MessageHandler for StreamState {
fn handle_update(&mut self, update: StateUpdate, hotkey_handler: &Hotkeys)
-> (Option<StateUpdate>, Option<Vec<StateUpdate>>) {
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(_) => {},

View file

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

3
src/todo.txt Normal file
View file

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