Skip to content

Commit

Permalink
Add: Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephira58 committed Jul 20, 2023
1 parent 5f9070f commit 48a33bb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/rust-core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,18 @@ jobs:
wait-for-processing: true

# Runs cargo fmt and pushes any changes to the github repo
format:
name: Run Cargo fmt
update:
name: Run Cargo FMT
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt
override: true
- uses: mbrobbel/rustfmt-check@master
toolchain: stable
- uses: actions-rs/cargo@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
command: fmt
args:

# Runs cargo update to update the cargo.lock file
update:
Expand Down
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use regex::Regex;
use std::net::{IpAddr, TcpStream};
use std::time::Duration;
use regex::Regex;

pub async fn is_server_alive(ip: IpAddr, port: u16, timeout_secs: u64) -> bool {
if let Ok(_) = TcpStream::connect_timeout(&(ip, port).into(), Duration::from_secs(timeout_secs)) {
if let Ok(_) = TcpStream::connect_timeout(&(ip, port).into(), Duration::from_secs(timeout_secs))
{
true
} else {
false
Expand All @@ -12,7 +13,8 @@ pub async fn is_server_alive(ip: IpAddr, port: u16, timeout_secs: u64) -> bool {

pub fn validate_ip_address(ip_address: &str) -> bool {
// Regular expression pattern for matching IP addresses
let pattern = r"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";
let pattern =
r"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";
let regex = Regex::new(pattern).unwrap();
regex.is_match(ip_address)
}
34 changes: 20 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use std::{net::IpAddr, str::FromStr, time::Duration, thread};
use eframe::egui;
use egui_notify::{Anchor, Toast, Toasts};
use std::{net::IpAddr, str::FromStr, thread, time::Duration};
use vault_gui::*;
use egui_notify::{Anchor, Toasts, Toast};


use std::sync::mpsc;

Expand Down Expand Up @@ -74,14 +73,23 @@ impl eframe::App for MyApp {
if !self.server_valid {
ui.heading("Vault GUI");
ui.label("Please enter the ip and port of the sql server below");

ui.horizontal(|ui| {
ui.label("IP:");
if ui.label("IP:").hovered() {
egui::show_tooltip(ui.ctx(), egui::Id::new("ip_tooltip"), |ui| {
ui.label("IPV4 Only");
});
}
ui.text_edit_singleline(&mut self.ip);
});

ui.horizontal(|ui| {
ui.label("Port:");
ui.add(egui::DragValue::new(&mut self.port).speed(1.0).clamp_range(0..=65535));
ui.add(
egui::DragValue::new(&mut self.port)
.speed(1.0)
.clamp_range(0..=65535),
);
});

if ui.button("Connect").clicked() {
Expand All @@ -91,20 +99,19 @@ impl eframe::App for MyApp {
if !ip_verified {
cb(self.toasts.error("Invalid IP Address!"));
println!("Invalid IP Address!");
return
return;
}

println!("IP: {}", self.ip);
println!("Port: {}", self.port);
println!("Testing connection to server...");

let ip: IpAddr = IpAddr::from_str(&self.ip).unwrap();
let port = self.port;

// Create a channel to communicate the result of the ping test
let tx = self.tx.clone();

//TODO: Fix this async code and try to make it not freeze the gui

thread::spawn(move || {
let result = tokio::runtime::Runtime::new()
.unwrap()
Expand All @@ -131,11 +138,11 @@ impl eframe::App for MyApp {
if ui.button("Login").clicked() {
println!("Username: {}", self.username);
println!("Password: {}", self.password);
}
}

if ui.button("Return").clicked() {
self.server_valid = false;
}
}
});
}

Expand All @@ -149,8 +156,7 @@ impl eframe::App for MyApp {
println!("Connection Failed!")
}
}

});
self.toasts.show(ctx); // Requests to render toasts
}
}
}

0 comments on commit 48a33bb

Please sign in to comment.