mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-04-12 08:28:32 +02:00
feat: Add remove event for wifi entries
This commit is contained in:
parent
12f92ac597
commit
f5f6246ad1
|
@ -1,6 +1,7 @@
|
|||
use crate::components::base::listEntryImpl;
|
||||
use adw::glib;
|
||||
use adw::glib::{IsA, Object};
|
||||
use dbus::Path;
|
||||
use gtk::prelude::ListBoxRowExt;
|
||||
use gtk::Widget;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use gtk::{CompositeTemplate, glib};
|
||||
use gtk::subclass::prelude::*;
|
||||
use crate::components::base::listEntry;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, CompositeTemplate};
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(Default, CompositeTemplate)]
|
||||
|
|
|
@ -67,22 +67,15 @@ pub fn scanForWifi(wifiBox: Arc<WifiBox>) {
|
|||
let accessPoints = get_access_points();
|
||||
let wifiEntriesListener = wifiEntries.clone();
|
||||
let wifiEntries = wifiEntries.clone();
|
||||
{
|
||||
let mut wifiEntries = wifiEntries.lock().unwrap();
|
||||
for accessPoint in accessPoints {
|
||||
wifiEntries.push(accessPoint);
|
||||
}
|
||||
}
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let mut wifiEntries = wifiEntries.lock().unwrap();
|
||||
let selfImp = wifibox_ref.imp();
|
||||
for _ in 0..wifiEntries.len() {
|
||||
selfImp
|
||||
.resetWifiList
|
||||
.append(&ListEntry::new(&*WifiEntry::new(
|
||||
wifiEntries.pop().unwrap(),
|
||||
)));
|
||||
for accessPoint in accessPoints {
|
||||
let path = accessPoint.dbus_path.clone();
|
||||
let entry = Arc::new(ListEntry::new(&*WifiEntry::new(accessPoint)));
|
||||
wifiEntries.insert(path, entry.clone());
|
||||
selfImp.resetWifiList.append(&*entry);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -109,6 +102,7 @@ pub fn scanForWifi(wifiBox: Arc<WifiBox>) {
|
|||
println!("Could not connect listener");
|
||||
}
|
||||
loop {
|
||||
let wifiEntriesListener = wifiEntriesListener.clone();
|
||||
if wifiBoxImpl
|
||||
.listener_active
|
||||
.load(std::sync::atomic::Ordering::SeqCst)
|
||||
|
@ -122,24 +116,38 @@ pub fn scanForWifi(wifiBox: Arc<WifiBox>) {
|
|||
let access_point = res.unwrap();
|
||||
match access_point {
|
||||
Events::AddedEvent(access_point) => {
|
||||
{
|
||||
let mut wifiEntries = wifiEntriesListener.lock().unwrap();
|
||||
println!("got this access point:");
|
||||
dbg!(access_point.0.clone());
|
||||
wifiEntries.push(access_point.0);
|
||||
}
|
||||
let wifiEntriesListener = wifiEntriesListener.clone();
|
||||
let wifiBoxImpl = wifibox_ref_listener.clone();
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let mut wifiEntries = wifiEntriesListener.lock().unwrap();
|
||||
wifiBoxImpl.imp().resetWifiList.append(&ListEntry::new(
|
||||
&*WifiEntry::new(wifiEntries.pop().unwrap()),
|
||||
));
|
||||
let path = access_point.0.dbus_path.clone();
|
||||
if wifiEntries.get(&path).is_some() {
|
||||
// don't add the entry if it exists, somehow networkmanager
|
||||
// spams these added things?
|
||||
// TODO perhaps use ssid?
|
||||
return;
|
||||
}
|
||||
let entry =
|
||||
Arc::new(ListEntry::new(&*WifiEntry::new(access_point.0)));
|
||||
wifiEntries.insert(path, entry.clone());
|
||||
wifiBoxImpl.imp().resetWifiList.append(&*entry);
|
||||
});
|
||||
});
|
||||
}
|
||||
Events::RemovedEvent(path) => {
|
||||
let wifiBoxImpl = wifibox_ref_listener.clone();
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let mut wifiEntries = wifiEntriesListener.lock().unwrap();
|
||||
let entry = wifiEntries.remove(&path.0);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
}
|
||||
wifiBoxImpl.imp().resetWifiList.remove(&*entry.unwrap());
|
||||
});
|
||||
});
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
} else {
|
||||
println!("no message there :)");
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use std::collections::HashMap;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use ReSet_Lib::network::network::AccessPoint;
|
||||
use dbus::Path;
|
||||
use gtk::{CompositeTemplate, glib, ListBox, Switch};
|
||||
use gtk::prelude::*;
|
||||
use gtk::subclass::prelude::*;
|
||||
|
@ -25,7 +27,7 @@ pub struct WifiBox {
|
|||
pub resetStoredWifiList: TemplateChild<ListBox>,
|
||||
#[template_child]
|
||||
pub resetAvailableNetworks: TemplateChild<ListEntry>,
|
||||
pub wifiEntries: Arc<Mutex<Vec<AccessPoint>>>,
|
||||
pub wifiEntries: Arc<Mutex<HashMap<Path<'static>,Arc<ListEntry>>>>,
|
||||
pub savedWifiEntries: Arc<Mutex<Vec<ListEntry>>>,
|
||||
pub listener_active: Arc<AtomicBool>,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue