mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-04-18 18:48:33 +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 crate::components::base::listEntryImpl;
|
||||||
use adw::glib;
|
use adw::glib;
|
||||||
use adw::glib::{IsA, Object};
|
use adw::glib::{IsA, Object};
|
||||||
|
use dbus::Path;
|
||||||
use gtk::prelude::ListBoxRowExt;
|
use gtk::prelude::ListBoxRowExt;
|
||||||
use gtk::Widget;
|
use gtk::Widget;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use gtk::{CompositeTemplate, glib};
|
|
||||||
use gtk::subclass::prelude::*;
|
|
||||||
use crate::components::base::listEntry;
|
use crate::components::base::listEntry;
|
||||||
|
use gtk::subclass::prelude::*;
|
||||||
|
use gtk::{glib, CompositeTemplate};
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[derive(Default, CompositeTemplate)]
|
#[derive(Default, CompositeTemplate)]
|
||||||
|
|
|
@ -67,22 +67,15 @@ pub fn scanForWifi(wifiBox: Arc<WifiBox>) {
|
||||||
let accessPoints = get_access_points();
|
let accessPoints = get_access_points();
|
||||||
let wifiEntriesListener = wifiEntries.clone();
|
let wifiEntriesListener = wifiEntries.clone();
|
||||||
let wifiEntries = 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::spawn_future(async move {
|
||||||
glib::idle_add_once(move || {
|
glib::idle_add_once(move || {
|
||||||
let mut wifiEntries = wifiEntries.lock().unwrap();
|
let mut wifiEntries = wifiEntries.lock().unwrap();
|
||||||
let selfImp = wifibox_ref.imp();
|
let selfImp = wifibox_ref.imp();
|
||||||
for _ in 0..wifiEntries.len() {
|
for accessPoint in accessPoints {
|
||||||
selfImp
|
let path = accessPoint.dbus_path.clone();
|
||||||
.resetWifiList
|
let entry = Arc::new(ListEntry::new(&*WifiEntry::new(accessPoint)));
|
||||||
.append(&ListEntry::new(&*WifiEntry::new(
|
wifiEntries.insert(path, entry.clone());
|
||||||
wifiEntries.pop().unwrap(),
|
selfImp.resetWifiList.append(&*entry);
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -109,6 +102,7 @@ pub fn scanForWifi(wifiBox: Arc<WifiBox>) {
|
||||||
println!("Could not connect listener");
|
println!("Could not connect listener");
|
||||||
}
|
}
|
||||||
loop {
|
loop {
|
||||||
|
let wifiEntriesListener = wifiEntriesListener.clone();
|
||||||
if wifiBoxImpl
|
if wifiBoxImpl
|
||||||
.listener_active
|
.listener_active
|
||||||
.load(std::sync::atomic::Ordering::SeqCst)
|
.load(std::sync::atomic::Ordering::SeqCst)
|
||||||
|
@ -122,24 +116,38 @@ pub fn scanForWifi(wifiBox: Arc<WifiBox>) {
|
||||||
let access_point = res.unwrap();
|
let access_point = res.unwrap();
|
||||||
match access_point {
|
match access_point {
|
||||||
Events::AddedEvent(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 wifiEntriesListener = wifiEntriesListener.clone();
|
||||||
let wifiBoxImpl = wifibox_ref_listener.clone();
|
let wifiBoxImpl = wifibox_ref_listener.clone();
|
||||||
glib::spawn_future(async move {
|
glib::spawn_future(async move {
|
||||||
glib::idle_add_once(move || {
|
glib::idle_add_once(move || {
|
||||||
let mut wifiEntries = wifiEntriesListener.lock().unwrap();
|
let mut wifiEntries = wifiEntriesListener.lock().unwrap();
|
||||||
wifiBoxImpl.imp().resetWifiList.append(&ListEntry::new(
|
let path = access_point.0.dbus_path.clone();
|
||||||
&*WifiEntry::new(wifiEntries.pop().unwrap()),
|
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 {
|
} else {
|
||||||
println!("no message there :)");
|
println!("no message there :)");
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use ReSet_Lib::network::network::AccessPoint;
|
use ReSet_Lib::network::network::AccessPoint;
|
||||||
|
use dbus::Path;
|
||||||
use gtk::{CompositeTemplate, glib, ListBox, Switch};
|
use gtk::{CompositeTemplate, glib, ListBox, Switch};
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::subclass::prelude::*;
|
use gtk::subclass::prelude::*;
|
||||||
|
@ -25,7 +27,7 @@ pub struct WifiBox {
|
||||||
pub resetStoredWifiList: TemplateChild<ListBox>,
|
pub resetStoredWifiList: TemplateChild<ListBox>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub resetAvailableNetworks: TemplateChild<ListEntry>,
|
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 savedWifiEntries: Arc<Mutex<Vec<ListEntry>>>,
|
||||||
pub listener_active: Arc<AtomicBool>,
|
pub listener_active: Arc<AtomicBool>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue