bug fixes and stuff
This commit is contained in:
parent
156c3e8475
commit
f4161c8dbb
8 changed files with 75 additions and 24 deletions
45
.vscode/launch.json
vendored
Normal file
45
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug executable 'church_controller'",
|
||||
"cargo": {
|
||||
"args": [
|
||||
"build",
|
||||
"--bin=church_controller",
|
||||
"--package=church_controller"
|
||||
],
|
||||
"filter": {
|
||||
"name": "church_controller",
|
||||
"kind": "bin"
|
||||
}
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug unit tests in executable 'church_controller'",
|
||||
"cargo": {
|
||||
"args": [
|
||||
"test",
|
||||
"--no-run",
|
||||
"--bin=church_controller",
|
||||
"--package=church_controller"
|
||||
],
|
||||
"filter": {
|
||||
"name": "church_controller",
|
||||
"kind": "bin"
|
||||
}
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -50,7 +50,7 @@ fn main() {
|
|||
while !control_c_called_flag_rx.get() {
|
||||
match from_socket_rx.recv_timeout(Duration::from_millis(100)) {
|
||||
Ok(message) => {
|
||||
println!("{}", message);
|
||||
println!("main recieved: {}", message);
|
||||
let json = serde_json::from_str(&message).unwrap();
|
||||
let update = StateUpdate::json_to_state_update(json);
|
||||
if update == StateUpdate::UpdateClient {
|
||||
|
@ -94,6 +94,7 @@ fn setup_control_c(mut control_c_flag_tx: sync_flag::SyncFlagTx) {
|
|||
}
|
||||
|
||||
fn update_all(state: &StreamState, socket: &Socket) {
|
||||
println!("updating all");
|
||||
socket.send(StateUpdate::StreamRunning(state.stream_running).to_json().to_string());
|
||||
socket.send(StateUpdate::StreamSoundToggleOn(state.stream_is_muted).to_json().to_string());
|
||||
socket.send(StateUpdate::ToggleComputerSoundOn(state.computer_sound_is_on).to_json().to_string());
|
||||
|
|
|
@ -106,7 +106,7 @@ impl Hotkeys {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn toggle_media_play_pause(&self, _value: bool) {
|
||||
pub fn toggle_media_play_pause(&self) {
|
||||
if cfg!(target_os = "windows") {
|
||||
Command::new(String::from(AHK_FILES_FOLDER) + "music_toggle.exe")
|
||||
.arg(self.hotkeys["windows"]["propresenter_re"].to_string())
|
||||
|
@ -139,5 +139,5 @@ fn hotkeys() {
|
|||
hk.send_obs(String::from("a hotkey"));
|
||||
hk.toggle_computer_sound(true);
|
||||
hk.toggle_stream_sound(true);
|
||||
hk.toggle_media_play_pause(false);
|
||||
hk.toggle_media_play_pause();
|
||||
}
|
|
@ -12,7 +12,10 @@ pub trait MessageHandler { //the first one goes to
|
|||
impl MessageHandler for StreamState {
|
||||
fn handle_update(&mut self, update: StateUpdate, hotkey_handler: &Hotkeys)
|
||||
-> (Option<StateUpdate>, Option<Vec<StateUpdate>>) {
|
||||
|
||||
if update != StateUpdate::UpdateClient{
|
||||
self.update(update.clone());
|
||||
}
|
||||
|
||||
if self.debug_mode {
|
||||
return (None, None)
|
||||
|
@ -80,7 +83,7 @@ impl MessageHandler for StreamState {
|
|||
},
|
||||
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::ComputerMediaDoPause(value) => {hotkey_handler.toggle_media_play_pause(value); return (Some(update), None)},
|
||||
StateUpdate::ComputerMediaDoPause => {hotkey_handler.toggle_media_play_pause(); return (Some(update), None)},
|
||||
StateUpdate::UpdateClient => {},
|
||||
StateUpdate::StreamRunning(_) => {},
|
||||
//_ => {}
|
||||
|
|
|
@ -35,7 +35,8 @@ impl Socket {
|
|||
let mut streams = thread_owned_streams.lock().unwrap();
|
||||
streams.push(Arc::clone(&stream));
|
||||
//pass off a clone of the thread-passable pointer
|
||||
Socket::handle_client(stream.as_ref(), messenger_tx.clone(), thread_stop_flag.clone());
|
||||
drop(streams);
|
||||
Socket::handle_client(Arc::clone(&stream), messenger_tx.clone(), thread_stop_flag.clone());
|
||||
}
|
||||
thread::sleep(Duration::from_millis(100));
|
||||
}
|
||||
|
@ -50,11 +51,11 @@ impl Socket {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn handle_client(mut stream: &TcpStream, update_tx: Sender<String>, program_shutdown_flag: sync_flag::SyncFlagRx) {
|
||||
pub fn handle_client(stream: Arc<TcpStream>, update_tx: Sender<String>, program_shutdown_flag: sync_flag::SyncFlagRx) {
|
||||
let mut buffer = [0; 1024];
|
||||
stream.set_read_timeout(Some(Duration::from_millis(100))).expect("Could not set a read timeout");
|
||||
while program_shutdown_flag.get() {
|
||||
match stream.read(&mut buffer) {
|
||||
match stream.as_ref().read(&mut buffer) {
|
||||
Err(_) => {},
|
||||
Ok(read_size) => {
|
||||
//Tcp is supposed to have a 0 byte read if closed by client
|
||||
|
@ -79,11 +80,16 @@ impl Socket {
|
|||
}
|
||||
|
||||
pub fn send(&self, message: String) {
|
||||
let streams = self.socket_txs.lock().unwrap();
|
||||
for socket_tx in streams.iter(){
|
||||
let mut tx = socket_tx.as_ref();
|
||||
tx.write(message.clone().as_bytes()).unwrap();
|
||||
let mut streams = self.socket_txs.lock().unwrap();
|
||||
for i in 0..streams.len(){
|
||||
let mut tx = streams.get(i).unwrap().as_ref();
|
||||
|
||||
match tx.write(message.clone().as_bytes()) {
|
||||
Err(_) => {streams.remove(i); continue;},
|
||||
Ok(_) => {},
|
||||
}
|
||||
tx.flush().unwrap();
|
||||
println!("sent");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ pub enum StateUpdate {
|
|||
StreamRunning(bool),
|
||||
StreamSoundToggleOn(bool),
|
||||
ToggleComputerSoundOn(bool),
|
||||
ComputerMediaDoPause(bool),
|
||||
ComputerMediaDoPause,
|
||||
ChangeSceneOnChangeSlide(bool),
|
||||
SceneIsAugmented(bool),
|
||||
TimerCanRun(bool),
|
||||
|
@ -66,7 +66,7 @@ impl StateUpdate {
|
|||
//Extra Toggles
|
||||
"Toggle_Computer_Volume" => {StateUpdate::ToggleComputerSoundOn(string_to_bool(incoming_json["data"].as_str().unwrap()))},
|
||||
"Toggle_Stream_Volume" => {StateUpdate::StreamSoundToggleOn(string_to_bool(incoming_json["data"].as_str().unwrap()))},
|
||||
"Media_Pause_Play" => {StateUpdate::ComputerMediaDoPause(string_to_bool(incoming_json["data"].as_str().unwrap()))},
|
||||
"Media_Pause_Play" => {StateUpdate::ComputerMediaDoPause},
|
||||
"Timer_Text" => {StateUpdate::TimerText(incoming_json["data"].as_str().unwrap().to_string())}
|
||||
|
||||
"all" => {StateUpdate::UpdateClient},
|
||||
|
@ -107,8 +107,8 @@ impl StateUpdate {
|
|||
("SubScene", scene.to_string())},
|
||||
StateUpdate::Scene(scene) => {
|
||||
("Scene", scene.to_string())},
|
||||
StateUpdate::ComputerMediaDoPause(is_true) => {
|
||||
("Toggle_Computer_Volume", is_true.to_string())},
|
||||
StateUpdate::ComputerMediaDoPause => {
|
||||
("Toggle_Computer_Volume", "".to_string())},
|
||||
StateUpdate::ChangeSlide(value) => {
|
||||
match value {
|
||||
SlideChange::Next => {("Next_Slide", "".to_string())},
|
||||
|
|
|
@ -69,9 +69,9 @@ impl StreamState {
|
|||
StateUpdate::SceneIsAugmented(new_val) => {
|
||||
self.scene_is_augmented = new_val;
|
||||
self.change_scene(&Scenes::Augmented)},
|
||||
StateUpdate::UpdateClient => todo!(),
|
||||
StateUpdate::ComputerMediaDoPause(do_pause) => {self.computer_sound_is_on = do_pause;},
|
||||
StateUpdate::ComputerMediaDoPause => {},
|
||||
StateUpdate::ChangeSlide(_value) => {panic!("Stream_states_class is not supposed to get this update type");},
|
||||
StateUpdate::UpdateClient => {},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,11 +50,7 @@ fn test_json_to_state_update() {
|
|||
|
||||
assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str(
|
||||
"{\"type\": \"update\", \"update\": \"Media_Pause_Play\", \"data\": \"true\"}"
|
||||
).unwrap()), StateUpdate::ComputerMediaDoPause(true));
|
||||
|
||||
assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str(
|
||||
"{\"type\": \"update\", \"update\": \"Media_Pause_Play\", \"data\": \"false\"}"
|
||||
).unwrap()), StateUpdate::ComputerMediaDoPause(false));
|
||||
).unwrap()), StateUpdate::ComputerMediaDoPause);
|
||||
|
||||
assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str(
|
||||
"{\"type\": \"update\", \"update\": \"SubScene\", \"data\": \"Camera_None\"}"
|
||||
|
|
Loading…
Reference in a new issue