Skip to content

Commit

Permalink
✨ Kreedzt - add system compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreedzt committed Apr 7, 2023
1 parent 5e9e8d7 commit c259c2a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 48 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
strategy:
fail-fast: false
matrix:
platform: [windows-latest]
# platform: [macos-latest, ubuntu-20.04, windows-latest]
#platform: [windows-latest]
platform: [macos-latest, ubuntu-20.04, windows-latest]

runs-on: ${{ matrix.platform }}
steps:
Expand Down
68 changes: 22 additions & 46 deletions src-tauri/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub fn ping_addr(addr: &str, timeout: u32) -> String {

#[cfg(target_os = "macos")]
pub fn ping_addr(addr: &str, timeout: u32) -> String {
let output = Command::new("sh")
.args(&["-c", "ping", "-c", "3", "-t", &(timeout / 1000).to_string(), addr])
let output = Command::new("ping")
.args(&["-c", "3", "-t", &(timeout / 1000).to_string(), addr])
.output()
.expect("failed to ping");

Expand All @@ -37,8 +37,8 @@ pub fn ping_addr(addr: &str, timeout: u32) -> String {

#[cfg(target_os = "linux")]
pub fn ping_addr(addr: &str, timeout: u32) -> String {
let output = Command::new("sh")
.args(&["-c", "ping", "-c", "3", "-t", &(timeout / 1000).to_string(), addr])
let output = Command::new("ping")
.args(&["-c", "3", "-W", &(timeout / 1000).to_string(), addr])
.output()
.expect("failed to ping");

Expand Down Expand Up @@ -106,30 +106,18 @@ pub fn get_ping_res_ms(res: &str) -> i16 {
let mut ms = -1;

if let Some(t) = res.lines().last() {
for packets_res in t.split(",") {
if packets_res.trim().is_empty() {
continue;
}

// eg1: [Average, 23ms]
// eg2: [Lost, 3 (100% loss) ]
let mut loop_key = String::new();
let mut loop_value = String::new();

for (index, kv_res) in packets_res.split("=").enumerate() {
let kv_res = kv_res.trim();
if kv_res.is_empty() {
if t.contains("=") {
for ping_res in t.split("=") {
if ping_res.starts_with("round-trip") {
continue;
}
if index == 0 {
loop_key = kv_res.to_string();
} else if index == 1 {
loop_value = kv_res.to_string();
}
}

if loop_key == AVERAGE_KEY {
ms = loop_value.replace("ms", "").parse().unwrap();
for (index, res_ms) in ping_res.split("/").enumerate() {
if index == 1 {
ms = res_ms.parse::<f32>().unwrap().floor() as i16;
break;
}
}
}
}
}
Expand All @@ -142,30 +130,18 @@ pub fn get_ping_res_ms(res: &str) -> i16 {
let mut ms = -1;

if let Some(t) = res.lines().last() {
for packets_res in t.split(",") {
if packets_res.trim().is_empty() {
continue;
}

// eg1: [Average, 23ms]
// eg2: [Lost, 3 (100% loss) ]
let mut loop_key = String::new();
let mut loop_value = String::new();

for (index, kv_res) in packets_res.split("=").enumerate() {
let kv_res = kv_res.trim();
if kv_res.is_empty() {
if t.contains("=") {
for ping_res in t.split("=") {
if ping_res.starts_with("round-trip") {
continue;
}
if index == 0 {
loop_key = kv_res.to_string();
} else if index == 1 {
loop_value = kv_res.to_string();
}
}

if loop_key == AVERAGE_KEY {
ms = loop_value.replace("ms", "").parse().unwrap();
for (index, res_ms) in ping_res.split("/").enumerate() {
if index == 1 {
ms = res_ms.parse::<f32>().unwrap().floor() as i16;
break;
}
}
}
}
}
Expand Down

0 comments on commit c259c2a

Please sign in to comment.