rearranged setup variables

This commit is contained in:
Nickiel12 2021-12-29 21:30:13 -08:00
parent bead4a5b99
commit 6a2d56b0bc

View file

@ -1,4 +1,4 @@
use std::{time::Duration}; use std::{time::Duration, thread};
use crossbeam_channel::unbounded; use crossbeam_channel::unbounded;
use modules::{socket_handler::Socket, stream_states::stream_states_class::StreamState, message_handler::{MessageHandler}}; use modules::{socket_handler::Socket, stream_states::stream_states_class::StreamState, message_handler::{MessageHandler}};
@ -20,16 +20,22 @@ const SERVER_ADDRESS: &str = "10.0.0.168:5000";
fn main() { fn main() {
let mut state = StreamState::new(); let mut state = StreamState::new();
let socket_listener = Socket::make_listener(SERVER_ADDRESS); let (control_c_flag_tx, control_c_called_flag_rx) = sync_flag::new_syncflag(false);
let (from_socket_tx, from_socket_rx) = unbounded::<String>(); let (from_socket_tx, from_socket_rx) = unbounded::<String>();
let hotkey_channel_tx = from_socket_tx.clone();
let socket_listener = Socket::make_listener(SERVER_ADDRESS);
let mut socket = Socket::handle_connections(socket_listener, from_socket_tx); let mut socket = Socket::handle_connections(socket_listener, from_socket_tx);
let (control_c_flag_tx, control_c_called_flag_rx) = sync_flag::new_syncflag(false);
setup_control_c(control_c_flag_tx); setup_control_c(control_c_flag_tx);
let _outgoing = std::net::TcpStream::connect(SERVER_ADDRESS).unwrap(); let _outgoing = std::net::TcpStream::connect(SERVER_ADDRESS).unwrap();
socket.send("this is a message".to_string()); socket.send("this is a message".to_string());
let hotkey_handle = thread::spawn(move || {
modules::hotkey_handler::create_keyboard_hooks(hotkey_channel_tx);
});
//until control_c is caught, check the queue of incoming //until control_c is caught, check the queue of incoming
//requests from the socket handler. //requests from the socket handler.
while !control_c_called_flag_rx.get() { while !control_c_called_flag_rx.get() {
@ -46,6 +52,7 @@ fn main() {
} }
socket.close(); socket.close();
hotkey_handle.join();
} }
fn setup_control_c(mut control_c_flag_tx: sync_flag::SyncFlagTx) { fn setup_control_c(mut control_c_flag_tx: sync_flag::SyncFlagTx) {