fix BLE wifi status delivery and websocket compile issues
This commit is contained in:
@@ -6,7 +6,7 @@ use crate::core::{message::*, plugin::*};
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use serde::Serialize;
|
||||
use serde_json::json;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::process::Command;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
@@ -60,7 +60,7 @@ impl WifiPlugin {
|
||||
|
||||
ctx.tx.send(Envelope {
|
||||
from: "wifi",
|
||||
to: Destination::Manager,
|
||||
to: Destination::Broadcast,
|
||||
message: Message::WifiResult(payload),
|
||||
})?;
|
||||
|
||||
@@ -95,9 +95,12 @@ impl WifiPlugin {
|
||||
let networks = output
|
||||
.lines()
|
||||
.filter(|line| !line.trim().is_empty())
|
||||
.map(|line| {
|
||||
.filter_map(|line| {
|
||||
let mut parts = line.splitn(3, ':');
|
||||
let ssid = parts.next().unwrap_or_default().trim().to_string();
|
||||
if ssid.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let signal = parts
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
@@ -106,13 +109,22 @@ impl WifiPlugin {
|
||||
.unwrap_or_default();
|
||||
let security = parts.next().unwrap_or_default().trim().to_string();
|
||||
|
||||
WifiNetwork {
|
||||
Some(WifiNetwork {
|
||||
ssid,
|
||||
signal,
|
||||
security,
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
.fold(
|
||||
(HashSet::new(), Vec::new()),
|
||||
|(mut seen, mut networks), network| {
|
||||
if seen.insert(network.ssid.clone()) {
|
||||
networks.push(network);
|
||||
}
|
||||
(seen, networks)
|
||||
},
|
||||
)
|
||||
.1;
|
||||
|
||||
Ok(json!({
|
||||
"ok": true,
|
||||
@@ -122,7 +134,11 @@ impl WifiPlugin {
|
||||
}
|
||||
|
||||
fn connect_network(&self, ssid: &str, password: &str) -> Result<serde_json::Value> {
|
||||
let output = Self::run_nmcli(&["device", "wifi", "connect", ssid, "password", password])?;
|
||||
let mut args = vec!["device", "wifi", "connect", ssid];
|
||||
if !password.trim().is_empty() {
|
||||
args.extend(["password", password]);
|
||||
}
|
||||
let output = Self::run_nmcli(&args)?;
|
||||
|
||||
Ok(json!({
|
||||
"ok": true,
|
||||
@@ -234,6 +250,10 @@ impl Plugin for WifiPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
fn dependencies(&self) -> Vec<&'static str> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
fn init(&mut self, ctx: PluginContext) -> Result<()> {
|
||||
self.ctx = Some(ctx);
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user