mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-07-07 18:47:45 +02:00
chore: Code cleanup
This commit is contained in:
parent
192dacb333
commit
cb3dd257f1
22 changed files with 121 additions and 106 deletions
|
@ -1,7 +1,7 @@
|
|||
#![allow(non_snake_case)]
|
||||
pub mod savedWifiEntry;
|
||||
pub mod savedWifiEntryImpl;
|
||||
pub mod wifiBox;
|
||||
pub mod wifiBoxImpl;
|
||||
pub mod wifiEntry;
|
||||
pub mod wifiEntryImpl;
|
||||
pub mod savedWifiEntryImpl;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use gtk::{CompositeTemplate, glib, ListBox, Switch};
|
||||
use crate::components::wifi::wifiBox;
|
||||
use gtk::prelude::*;
|
||||
use gtk::subclass::prelude::*;
|
||||
use crate::components::wifi::wifiBox;
|
||||
use gtk::{glib, CompositeTemplate, ListBox, Switch};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::components::wifi::wifiEntry::WifiEntry;
|
||||
use crate::components::base::listEntry::ListEntry;
|
||||
use crate::components::wifi::wifiEntry::WifiEntry;
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(Default, CompositeTemplate)]
|
||||
|
@ -24,7 +24,7 @@ pub struct WifiBox {
|
|||
pub resetStoredWifiList: TemplateChild<ListBox>,
|
||||
#[template_child]
|
||||
pub resetAvailableNetworks: TemplateChild<ListEntry>,
|
||||
pub wifiEntries: Arc<Mutex<HashMap<Vec<u8>,Arc<ListEntry>>>>,
|
||||
pub wifiEntries: Arc<Mutex<HashMap<Vec<u8>, Arc<ListEntry>>>>,
|
||||
pub savedWifiEntries: Arc<Mutex<Vec<ListEntry>>>,
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use adw::glib;
|
||||
|
@ -8,9 +8,9 @@ use adw::prelude::{ButtonExt, EditableExt, PopoverExt};
|
|||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||
use dbus::blocking::Connection;
|
||||
use dbus::Error;
|
||||
use glib::{Cast, clone};
|
||||
use gtk::{AlertDialog, GestureClick};
|
||||
use glib::{clone, Cast};
|
||||
use gtk::prelude::WidgetExt;
|
||||
use gtk::{AlertDialog, GestureClick};
|
||||
use ReSet_Lib::network::network::{AccessPoint, WifiStrength};
|
||||
|
||||
use crate::components::wifi::wifiBox::getConnectionSettings;
|
||||
|
@ -144,56 +144,58 @@ pub fn click_stored_network(entry: Arc<WifiEntry>) {
|
|||
}
|
||||
|
||||
pub fn click_new_network(entry: Arc<WifiEntry>) {
|
||||
let connect_new_network =
|
||||
|result: Arc<AtomicBool>, entry: Arc<WifiEntry>, access_point: AccessPoint, password: String| {
|
||||
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);
|
||||
let connect_new_network = |result: Arc<AtomicBool>,
|
||||
entry: Arc<WifiEntry>,
|
||||
access_point: AccessPoint,
|
||||
password: String| {
|
||||
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);
|
||||
|
||||
glib::spawn_future_local(async 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(
|
||||
"org.xetibo.ReSet",
|
||||
"ConnectToNewAccessPoint",
|
||||
(access_point, password),
|
||||
);
|
||||
glib::MainContext::default().spawn_local(async move {
|
||||
glib::idle_add_once(move || {
|
||||
if res.is_err() {
|
||||
entry_ref
|
||||
.imp()
|
||||
.resetWifiPopup
|
||||
.imp()
|
||||
.resetPopupLabel
|
||||
.set_text("Could not connect to dbus.");
|
||||
result.store(false, std::sync::atomic::Ordering::SeqCst);
|
||||
return;
|
||||
}
|
||||
if res.unwrap() == (false,) {
|
||||
entry_ref
|
||||
.imp()
|
||||
.resetWifiPopup
|
||||
.imp()
|
||||
.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);
|
||||
});
|
||||
glib::spawn_future_local(async 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(
|
||||
"org.xetibo.ReSet",
|
||||
"ConnectToNewAccessPoint",
|
||||
(access_point, password),
|
||||
);
|
||||
glib::MainContext::default().spawn_local(async move {
|
||||
glib::idle_add_once(move || {
|
||||
if res.is_err() {
|
||||
entry_ref
|
||||
.imp()
|
||||
.resetWifiPopup
|
||||
.imp()
|
||||
.resetPopupLabel
|
||||
.set_text("Could not connect to dbus.");
|
||||
result.store(false, std::sync::atomic::Ordering::SeqCst);
|
||||
return;
|
||||
}
|
||||
if res.unwrap() == (false,) {
|
||||
entry_ref
|
||||
.imp()
|
||||
.resetWifiPopup
|
||||
.imp()
|
||||
.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
|
||||
};
|
||||
});
|
||||
// TODO crate spinner animation and block UI
|
||||
};
|
||||
|
||||
let result = Arc::new(AtomicBool::new(false));
|
||||
let result_ref = result.clone();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue