mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-04-19 02:58:33 +02:00
fix: Don't use popups for wifi
This commit is contained in:
parent
b68bc0ab77
commit
1080a03b8b
|
@ -4,10 +4,11 @@ use crate::components::wifi::savedWifiEntryImpl;
|
||||||
use adw::glib;
|
use adw::glib;
|
||||||
use adw::glib::Object;
|
use adw::glib::Object;
|
||||||
use adw::prelude::{ButtonExt, WidgetExt};
|
use adw::prelude::{ButtonExt, WidgetExt};
|
||||||
use dbus::{Error, Path};
|
|
||||||
use dbus::blocking::Connection;
|
use dbus::blocking::Connection;
|
||||||
use glib::{clone, PropertySet};
|
use dbus::{Error, Path};
|
||||||
use glib::subclass::types::ObjectSubclassIsExt;
|
use glib::subclass::types::ObjectSubclassIsExt;
|
||||||
|
use glib::{clone, PropertySet};
|
||||||
|
use gtk::gio;
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct SavedWifiEntry(ObjectSubclass<savedWifiEntryImpl::SavedWifiEntry>)
|
pub struct SavedWifiEntry(ObjectSubclass<savedWifiEntryImpl::SavedWifiEntry>)
|
||||||
|
@ -22,22 +23,28 @@ impl SavedWifiEntry {
|
||||||
// TODO handle edit
|
// TODO handle edit
|
||||||
entryImp.resetSavedWifiLabel.set_text(name);
|
entryImp.resetSavedWifiLabel.set_text(name);
|
||||||
entryImp.resetConnectionPath.set(path);
|
entryImp.resetConnectionPath.set(path);
|
||||||
entryImp.resetDeleteSavedWifiButton.connect_clicked(clone!(@weak entry as entry => move |_| {
|
entryImp.resetDeleteSavedWifiButton.connect_clicked(
|
||||||
|
clone!(@weak entry as entry => move |_| {
|
||||||
|
delete_connection(entry.imp().resetConnectionPath.take());
|
||||||
|
// TODO handle error
|
||||||
|
let parent = entry.parent().unwrap();
|
||||||
|
parent.set_visible(false);
|
||||||
|
parent.unparent();
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
entry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_connection(path: Path<'static>) {
|
||||||
|
gio::spawn_blocking(move || {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(
|
||||||
"org.xetibo.ReSet",
|
"org.xetibo.ReSet",
|
||||||
"/org/xetibo/ReSet",
|
"/org/xetibo/ReSet",
|
||||||
Duration::from_millis(1000),
|
Duration::from_millis(1000),
|
||||||
);
|
);
|
||||||
let res: Result<(bool,), Error> = proxy.method_call("org.xetibo.ReSet", "DeleteConnection", (entry.imp().resetConnectionPath.take(),));
|
let _: Result<(), Error> =
|
||||||
if res.is_err() || res.unwrap() == (false,) {
|
proxy.method_call("org.xetibo.ReSet", "DeleteConnection", (path,));
|
||||||
// TODO handle error -> inform user
|
});
|
||||||
return;
|
|
||||||
}
|
|
||||||
let parent = entry.parent().unwrap();
|
|
||||||
parent.set_visible(false);
|
|
||||||
parent.unparent();
|
|
||||||
}));
|
|
||||||
entry
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,15 +7,18 @@ use adw::glib::{Object, PropertySet};
|
||||||
use adw::prelude::{ButtonExt, EditableExt, PopoverExt};
|
use adw::prelude::{ButtonExt, EditableExt, PopoverExt};
|
||||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||||
use dbus::blocking::Connection;
|
use dbus::blocking::Connection;
|
||||||
use dbus::Error;
|
use dbus::{Error, Path};
|
||||||
use glib::{clone, Cast};
|
use glib::{clone, Cast};
|
||||||
use gtk::prelude::WidgetExt;
|
use gtk::prelude::{ListBoxRowExt, WidgetExt};
|
||||||
use gtk::{AlertDialog, GestureClick};
|
use gtk::{gio, AlertDialog, GestureClick};
|
||||||
use ReSet_Lib::network::network::{AccessPoint, WifiStrength};
|
use ReSet_Lib::network::network::{AccessPoint, WifiStrength};
|
||||||
|
|
||||||
|
use crate::components::base::listEntry::ListEntry;
|
||||||
use crate::components::wifi::wifiBox::getConnectionSettings;
|
use crate::components::wifi::wifiBox::getConnectionSettings;
|
||||||
use crate::components::wifi::wifiEntryImpl;
|
use crate::components::wifi::wifiEntryImpl;
|
||||||
|
|
||||||
|
use super::savedWifiEntry::SavedWifiEntry;
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct WifiEntry(ObjectSubclass<wifiEntryImpl::WifiEntry>)
|
pub struct WifiEntry(ObjectSubclass<wifiEntryImpl::WifiEntry>)
|
||||||
@extends gtk::Box, gtk::Widget,
|
@extends gtk::Box, gtk::Widget,
|
||||||
|
@ -35,7 +38,6 @@ impl WifiEntry {
|
||||||
let ssid = access_point.ssid.clone();
|
let ssid = access_point.ssid.clone();
|
||||||
let name_opt = String::from_utf8(ssid).unwrap_or_else(|_| String::from(""));
|
let name_opt = String::from_utf8(ssid).unwrap_or_else(|_| String::from(""));
|
||||||
let name = name_opt.as_str();
|
let name = name_opt.as_str();
|
||||||
let stored = access_point.stored;
|
|
||||||
entryImp.wifiStrength.set(strength);
|
entryImp.wifiStrength.set(strength);
|
||||||
entryImp.resetWifiLabel.get().set_text(name);
|
entryImp.resetWifiLabel.get().set_text(name);
|
||||||
entryImp.resetWifiEncrypted.set_visible(false);
|
entryImp.resetWifiEncrypted.set_visible(false);
|
||||||
|
@ -49,7 +51,10 @@ impl WifiEntry {
|
||||||
WifiStrength::Weak => Some("network-wireless-signal-weak-symbolic"),
|
WifiStrength::Weak => Some("network-wireless-signal-weak-symbolic"),
|
||||||
WifiStrength::None => Some("network-wireless-signal-none-symbolic"),
|
WifiStrength::None => Some("network-wireless-signal-none-symbolic"),
|
||||||
});
|
});
|
||||||
if access_point.connected == true {
|
if !access_point.stored {
|
||||||
|
entryImp.resetWifiEditButton.set_sensitive(false);
|
||||||
|
}
|
||||||
|
if access_point.connected {
|
||||||
entryImp
|
entryImp
|
||||||
.resetWifiConnected
|
.resetWifiConnected
|
||||||
.get()
|
.get()
|
||||||
|
@ -61,16 +66,16 @@ impl WifiEntry {
|
||||||
}
|
}
|
||||||
entryImp.accessPoint.set(access_point);
|
entryImp.accessPoint.set(access_point);
|
||||||
let gesture = GestureClick::new();
|
let gesture = GestureClick::new();
|
||||||
if stored {
|
gesture.connect_released(clone!(@weak entryImp => move |_, _, _, _| {
|
||||||
gesture.connect_released(move |_, _, _, _| {
|
let access_point = entryImp.accessPoint.borrow();
|
||||||
|
if access_point.connected {
|
||||||
|
click_disconnect();
|
||||||
|
} else if access_point.stored {
|
||||||
click_stored_network(stored_entry.clone());
|
click_stored_network(stored_entry.clone());
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
entryImp.resetWifiEditButton.set_sensitive(false);
|
|
||||||
gesture.connect_released(move |_, _, _, _| {
|
|
||||||
click_new_network(new_entry.clone());
|
click_new_network(new_entry.clone());
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
}));
|
||||||
entry.add_controller(gesture);
|
entry.add_controller(gesture);
|
||||||
entry
|
entry
|
||||||
}
|
}
|
||||||
|
@ -84,63 +89,69 @@ impl WifiEntry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn click_stored_network(entry: Arc<WifiEntry>) {
|
pub fn click_disconnect() {
|
||||||
let alert = AlertDialog::builder().build();
|
println!("called disconnect");
|
||||||
let root = &entry.root().unwrap();
|
gio::spawn_blocking(move || {
|
||||||
let root = root.downcast_ref::<gtk::Window>();
|
|
||||||
if root.is_none() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let root = root.unwrap();
|
|
||||||
let entryImp = entry.imp();
|
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(
|
||||||
"org.xetibo.ReSet",
|
"org.xetibo.ReSet",
|
||||||
"/org/xetibo/ReSet",
|
"/org/xetibo/ReSet",
|
||||||
Duration::from_millis(1000),
|
Duration::from_millis(10000),
|
||||||
);
|
);
|
||||||
let access_point = entryImp.accessPoint.clone().into_inner();
|
|
||||||
if access_point.connected == true {
|
|
||||||
let res: Result<(bool,), Error> =
|
let res: Result<(bool,), Error> =
|
||||||
proxy.method_call("org.xetibo.ReSet", "DisconnectFromCurrentAccessPoint", ());
|
proxy.method_call("org.xetibo.ReSet", "DisconnectFromCurrentAccessPoint", ());
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
alert.set_message("Error on connecting to dbus.");
|
println!("res of disconnect was error bro");
|
||||||
alert.show(Some(root));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let (res,) = res.unwrap();
|
|
||||||
if res == false {
|
|
||||||
alert.set_message("Could not disconnect from access point.");
|
|
||||||
alert.show(Some(root));
|
|
||||||
} else {
|
|
||||||
entryImp.resetWifiConnected.get().set_from_icon_name(None);
|
|
||||||
let mut access_point = entryImp.accessPoint.borrow_mut();
|
|
||||||
(*access_point).connected = false;
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
println!("disconnect worked");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
pub fn click_stored_network(entry: Arc<WifiEntry>) {
|
||||||
|
let result = Arc::new(AtomicBool::new(false));
|
||||||
|
let entryImp = entry.imp();
|
||||||
|
let access_point = entryImp.accessPoint.borrow().clone();
|
||||||
|
let entry_ref = entry.clone();
|
||||||
|
let popup = entry.imp().resetWifiPopup.imp();
|
||||||
|
popup.resetPopupLabel.set_text("Connecting...");
|
||||||
|
popup.resetPopupLabel.set_visible(true);
|
||||||
|
popup.resetPopupEntry.set_sensitive(false);
|
||||||
|
popup.resetPopupButton.set_sensitive(false);
|
||||||
|
|
||||||
|
gio::spawn_blocking(move || {
|
||||||
|
let conn = Connection::new_session().unwrap();
|
||||||
|
let proxy = conn.with_proxy(
|
||||||
|
"org.xetibo.ReSet",
|
||||||
|
"/org/xetibo/ReSet",
|
||||||
|
Duration::from_millis(10000),
|
||||||
|
);
|
||||||
let res: Result<(bool,), Error> = proxy.method_call(
|
let res: Result<(bool,), Error> = proxy.method_call(
|
||||||
"org.xetibo.ReSet",
|
"org.xetibo.ReSet",
|
||||||
"ConnectToKnownAccessPoint",
|
"ConnectToKnownAccessPoint",
|
||||||
(access_point,),
|
(access_point,),
|
||||||
);
|
);
|
||||||
|
glib::spawn_future(async move {
|
||||||
|
glib::idle_add_once(move || {
|
||||||
|
let imp = entry_ref.imp();
|
||||||
|
let popup = imp.resetWifiPopup.imp();
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
alert.set_message("Error on connecting to dbus.");
|
popup.resetPopupLabel.set_text("Could not connect to dbus.");
|
||||||
alert.show(Some(root));
|
result.store(false, std::sync::atomic::Ordering::SeqCst);
|
||||||
} else {
|
return;
|
||||||
let (res,) = res.unwrap();
|
|
||||||
if res == false {
|
|
||||||
alert.set_message("Could not connect to access point.");
|
|
||||||
alert.show(Some(root));
|
|
||||||
} else {
|
|
||||||
entryImp
|
|
||||||
.resetWifiConnected
|
|
||||||
.get()
|
|
||||||
.set_from_icon_name(Some("network-wireless-connected-symbolic"));
|
|
||||||
let mut access_point = entryImp.accessPoint.borrow_mut();
|
|
||||||
(*access_point).connected = true;
|
|
||||||
}
|
}
|
||||||
|
if res.unwrap() == (false,) {
|
||||||
|
popup
|
||||||
|
.resetPopupLabel
|
||||||
|
.set_text("Could not connect to access point.");
|
||||||
|
result.store(false, std::sync::atomic::Ordering::SeqCst);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
entry_ref.imp().resetWifiPopup.popdown();
|
||||||
|
result.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// TODO crate spinner animation and block UI
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn click_new_network(entry: Arc<WifiEntry>) {
|
pub fn click_new_network(entry: Arc<WifiEntry>) {
|
||||||
|
@ -155,7 +166,7 @@ pub fn click_new_network(entry: Arc<WifiEntry>) {
|
||||||
popup.resetPopupEntry.set_sensitive(false);
|
popup.resetPopupEntry.set_sensitive(false);
|
||||||
popup.resetPopupButton.set_sensitive(false);
|
popup.resetPopupButton.set_sensitive(false);
|
||||||
|
|
||||||
glib::spawn_future_local(async move {
|
gio::spawn_blocking(move || {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(
|
||||||
"org.xetibo.ReSet",
|
"org.xetibo.ReSet",
|
||||||
|
@ -167,9 +178,10 @@ pub fn click_new_network(entry: Arc<WifiEntry>) {
|
||||||
"ConnectToNewAccessPoint",
|
"ConnectToNewAccessPoint",
|
||||||
(access_point, password),
|
(access_point, password),
|
||||||
);
|
);
|
||||||
glib::MainContext::default().spawn_local(async move {
|
glib::spawn_future(async move {
|
||||||
glib::idle_add_once(move || {
|
glib::idle_add_once(move || {
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
|
println!("error bro");
|
||||||
entry_ref
|
entry_ref
|
||||||
.imp()
|
.imp()
|
||||||
.resetWifiPopup
|
.resetWifiPopup
|
||||||
|
@ -180,6 +192,7 @@ pub fn click_new_network(entry: Arc<WifiEntry>) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if res.unwrap() == (false,) {
|
if res.unwrap() == (false,) {
|
||||||
|
println!("wrong pw");
|
||||||
entry_ref
|
entry_ref
|
||||||
.imp()
|
.imp()
|
||||||
.resetWifiPopup
|
.resetWifiPopup
|
||||||
|
@ -189,6 +202,7 @@ pub fn click_new_network(entry: Arc<WifiEntry>) {
|
||||||
result.store(false, std::sync::atomic::Ordering::SeqCst);
|
result.store(false, std::sync::atomic::Ordering::SeqCst);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
println!("worked?");
|
||||||
entry_ref.imp().resetWifiPopup.popdown();
|
entry_ref.imp().resetWifiPopup.popdown();
|
||||||
result.store(true, std::sync::atomic::Ordering::SeqCst);
|
result.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,8 +3,11 @@ use crate::components::wifi::wifiEntry;
|
||||||
use gtk::subclass::prelude::*;
|
use gtk::subclass::prelude::*;
|
||||||
use gtk::{glib, Button, CompositeTemplate, Image, Label};
|
use gtk::{glib, Button, CompositeTemplate, Image, Label};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use std::sync::Arc;
|
||||||
use ReSet_Lib::network::network::{AccessPoint, WifiStrength};
|
use ReSet_Lib::network::network::{AccessPoint, WifiStrength};
|
||||||
|
|
||||||
|
use super::wifiBox::WifiBox;
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[derive(Default, CompositeTemplate)]
|
#[derive(Default, CompositeTemplate)]
|
||||||
#[template(resource = "/org/Xetibo/ReSet/resetWifiEntry.ui")]
|
#[template(resource = "/org/Xetibo/ReSet/resetWifiEntry.ui")]
|
||||||
|
|
|
@ -31,6 +31,7 @@ pub const HANDLE_WIFI_CLICK: fn(Arc<Listeners>, FlowBox) =
|
||||||
listeners.stop_audio_listener();
|
listeners.stop_audio_listener();
|
||||||
listeners.stop_bluetooth_listener();
|
listeners.stop_bluetooth_listener();
|
||||||
let wifiBox = Arc::new(WifiBox::new());
|
let wifiBox = Arc::new(WifiBox::new());
|
||||||
|
show_stored_connections(wifiBox.clone());
|
||||||
scanForWifi(listeners.clone(), wifiBox.clone());
|
scanForWifi(listeners.clone(), wifiBox.clone());
|
||||||
let wifiFrame = wrapInFrame(SettingBox::new(&*wifiBox));
|
let wifiFrame = wrapInFrame(SettingBox::new(&*wifiBox));
|
||||||
resetMain.remove_all();
|
resetMain.remove_all();
|
||||||
|
|
Loading…
Reference in a new issue