Skip to content

Commit

Permalink
added error
Browse files Browse the repository at this point in the history
  • Loading branch information
marci1175 committed Jan 18, 2024
1 parent dce5aad commit 1ab43f0
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build_info.matthias_build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024.01.17. 22:13
2024.01.18. 21:43
87 changes: 71 additions & 16 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,72 @@ impl eframe::App for backend::TemplateApp {
ConnectionState::Disconnected;
}
}
ConnectionState::Error => {
if ui.button("Connect").clicked() {
let ip = self.client_ui.send_on_ip.clone();

let sender = self.connection_sender.clone();

tokio::task::spawn(async move {
match ClientConnection::connect(format!(
"http://{}",
ip
))
.await
{
Ok(ok) => {
if let Err(err) = sender.send(Some(ok)) {
dbg!(err);
};
}
Err(err) => {
std::thread::spawn(move || unsafe {
MessageBoxW(
0,
str::encode_utf16(
err.to_string().as_str(),
)
.chain(std::iter::once(0))
.collect::<Vec<_>>()
.as_ptr(),
w!("Error"),
MB_ICONERROR,
);
});
if let Err(err) = sender.send(None) {
dbg!(err);
};
}
};
});

self.autosync_should_run
.store(true, std::sync::atomic::Ordering::Relaxed);

//reset autosync
self.autosync_sender = None;

self.client_connection.state = ConnectionState::Connecting;
}
},
}

match self.client_connection.state {
ConnectionState::Connected => {
ui.label(RichText::from("Connected").color(Color32::GREEN));
}
ConnectionState::Disconnected => {
ui.label(RichText::from("Disconnected").color(Color32::RED));
}
ConnectionState::Connecting => {
ui.label(
RichText::from("Connecting").color(Color32::LIGHT_GREEN),
);
ui.label(
match self.client_connection.state {
ConnectionState::Connected => {
RichText::from("Connected").color(Color32::GREEN)
}
ConnectionState::Disconnected => {
RichText::from("Disconnected").color(Color32::LIGHT_RED)
}
ConnectionState::Connecting => {
RichText::from("Connecting").color(Color32::LIGHT_GREEN)
}
ConnectionState::Error => {
RichText::from("Error when trying to connect").color(Color32::RED)
}
}
}
);

ui.allocate_ui(vec2(25., 25.), |ui| {
if ui
Expand Down Expand Up @@ -301,10 +352,14 @@ impl eframe::App for backend::TemplateApp {
match self.connection_reciver.try_recv() {
Ok(connection) => {
if let Some(connection) = connection {
self.client_connection.state = ConnectionState::Connected;
self.client_connection = connection
} else {
self.client_connection.state = ConnectionState::Disconnected;
if connection.client.is_some() {
self.client_connection.state = ConnectionState::Connected;
self.client_connection = connection
}
else {
println!("err");
self.client_connection.state = ConnectionState::Error;
}
}
}
Err(err) => {
Expand Down
5 changes: 2 additions & 3 deletions src/app/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,12 +672,9 @@ impl ClientConnection {
.await
{
Ok(message_reply) => {
dbg!(message_reply.into_inner().message);
Some(client_clone)
}
Err(error) => {
dbg!(&error);

std::thread::spawn(move || unsafe {
MessageBoxW(
0,
Expand All @@ -704,6 +701,7 @@ pub enum ConnectionState {
Connected,
Disconnected,
Connecting,
Error,
}

impl Default for ConnectionState {
Expand All @@ -718,6 +716,7 @@ impl Debug for ConnectionState {
ConnectionState::Connected => "Connected",
ConnectionState::Disconnected => "Disconnected",
ConnectionState::Connecting => "Connecting",
ConnectionState::Error => "Error",
})
}
}
Expand Down

0 comments on commit 1ab43f0

Please sign in to comment.