From 48a33bb47aa58028e06f6cf501fbbdf7d471157b Mon Sep 17 00:00:00 2001 From: Aviion Gibbs Date: Fri, 21 Jul 2023 00:21:55 +0930 Subject: [PATCH] Add: Cargo fmt --- .github/workflows/rust-core.yaml | 13 ++++++------ src/lib.rs | 8 +++++--- src/main.rs | 34 +++++++++++++++++++------------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/.github/workflows/rust-core.yaml b/.github/workflows/rust-core.yaml index aeed275..30f96af 100644 --- a/.github/workflows/rust-core.yaml +++ b/.github/workflows/rust-core.yaml @@ -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: diff --git a/src/lib.rs b/src/lib.rs index 7811cbc..51425fb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 @@ -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) } diff --git a/src/main.rs b/src/main.rs index 34917d5..c3a83ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; @@ -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() { @@ -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() @@ -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; - } + } }); } @@ -149,8 +156,7 @@ impl eframe::App for MyApp { println!("Connection Failed!") } } - }); self.toasts.show(ctx); // Requests to render toasts } -} \ No newline at end of file +}