Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 2 additions & 32 deletions relay/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ mod state;
mod update;
mod view;

// mod channel;
// use channel::ChannelMessage;

use self::{
// ipc::ipc_connection_loop,
message::{FromIpcThreadMessage, Message},
message::Message,
state::State,
update::update,
view::view,
Expand All @@ -22,30 +19,6 @@ use iced::{
};

fn main() -> iced::Result {
// Communication channels between the main_gui_thread and the ipc_connection_thread
// tx_kill = transmit FROM main_gui_thread TO ipc_thread
// named txx_kill because the only thing it does rn is send a kill message to the thread. Can be renamed
//tcp connection

// Connect to the server

/* let (tx_to_parent_thread, rx_from_tcp_thread) = std::sync::mpsc::channel::<ChannelMessage>();
let tcp_connection = thread::spawn(move || match TcpStream::connect("127.0.0.1:7878") {
Ok(mut stream) => {
println!("Successfully connected.");
let message = ChannelMessage::Connect;
tx_to_parent_thread.send(message);
}

Err(e) => {
println!("Connection failed: {}", e);
}
}); */

// let (tx_to_ipc_thread, rx_kill) = std::sync::mpsc::channel();
// let (tx_to_parent_thread, rx_from_parent_thread) = std::sync::mpsc::channel();
// let _ = tx.send(()); // temp

iced::application("RELAY", update, view)
.window_size((450.0, 300.0))
.exit_on_close_request(false)
Expand All @@ -61,20 +34,17 @@ fn main() -> iced::Result {
"Error connecting to IPC during GUI initialization: {e:?}"
));
};
// state.tcp_connect().expect("TCP connection failure"); // may not need to panic, recoverable error

(state, Task::none())
})
}

fn subscribe(_state: &State) -> iced::Subscription<Message> {
use Message as M;

// Subscription for displaying elapsed time -- temporary
// Subscription for displaying elapsed time
let time_sub = every(Duration::from_millis(10)).map(|_| M::Update);

// Subscription to send a message when the window close button (big red X) is clicked.
// Needed to execute cleanup operations before actually shutting down, such as saving etc
let window_close = iced::window::close_requests().map(|id| M::WindowCloseRequest(id));

// combine and return all subscriptions as one subscription to satisfy the return type
Expand Down
12 changes: 10 additions & 2 deletions relay/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,17 @@ pub(crate) enum FromIpcThreadMessage {
}

pub(crate) enum ToTcpThreadMessage {
// outgoing payload to TCP thread
Send(String),
}
//added this for tcp counter - Nyla Hughes

pub(crate) enum FromTcpThreadMessage {
Sent { bytes: usize, at: Instant },
/// TCP thread successfully connected to remote
Connected,
/// TCP thread disconnected (may include reason)
Disconnected(String),
/// A packet was sent to remote (In bytes)
Sent(usize),
/// Error reported
SendError(String),
}
Loading