mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-07-13 05:07:45 +02:00
fix: Use metered properly
This commit is contained in:
parent
4b09745fce
commit
e1b027a68d
18 changed files with 245 additions and 264 deletions
|
@ -1,6 +1,7 @@
|
|||
use std::rc::Rc;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::components::utils::{BASE, DBUS_PATH, WIRELESS};
|
||||
use crate::components::wifi::saved_wifi_entry_impl;
|
||||
use crate::components::wifi::utils::get_connection_settings;
|
||||
use crate::components::wifi::wifi_box_impl::WifiBox;
|
||||
|
@ -66,11 +67,11 @@ fn delete_connection(path: Path<'static>) {
|
|||
gio::spawn_blocking(move || {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.Xetibo.ReSet.Daemon",
|
||||
"/org/Xetibo/ReSet/Daemon",
|
||||
BASE,
|
||||
DBUS_PATH,
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let _: Result<(), Error> =
|
||||
proxy.method_call("org.Xetibo.ReSet.Wireless", "DeleteConnection", (path,));
|
||||
proxy.method_call(WIRELESS, "DeleteConnection", (path,));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -6,6 +6,10 @@ use re_set_lib::network::connection::Connection as ResetConnection;
|
|||
use std::collections::HashMap;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::components::utils::BASE;
|
||||
use crate::components::utils::DBUS_PATH;
|
||||
use crate::components::utils::WIRELESS;
|
||||
|
||||
#[derive(Default, Copy, Clone)]
|
||||
pub enum IpProtocol {
|
||||
#[default]
|
||||
|
@ -19,12 +23,12 @@ type ResultType =
|
|||
pub fn get_connection_settings(path: Path<'static>) -> ResetConnection {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.Xetibo.ReSet.Daemon",
|
||||
"/org/Xetibo/ReSet/Daemon",
|
||||
BASE,
|
||||
DBUS_PATH,
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let res: ResultType =
|
||||
proxy.method_call("org.Xetibo.ReSet.Wireless", "GetConnectionSettings", (path,));
|
||||
proxy.method_call(WIRELESS, "GetConnectionSettings", (path,));
|
||||
if res.is_err() {
|
||||
ResetConnection::default();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::sync::Arc;
|
|||
use std::time::Duration;
|
||||
|
||||
use crate::components::base::utils::Listeners;
|
||||
use crate::components::utils::set_combo_row_ellipsis;
|
||||
use crate::components::utils::{set_combo_row_ellipsis, BASE, DBUS_PATH, WIRELESS};
|
||||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::{ComboRowExt, ListBoxRowExt, PreferencesGroupExt, PreferencesRowExt};
|
||||
|
@ -103,10 +103,8 @@ pub fn scan_for_wifi(wifi_box: Arc<WifiBox>) {
|
|||
let list = imp.reset_model_list.write().unwrap();
|
||||
let mut model_index = imp.reset_model_index.write().unwrap();
|
||||
let mut map = imp.reset_wifi_devices.write().unwrap();
|
||||
{
|
||||
if imp.reset_current_wifi_device.borrow().path == Path::from("/") {
|
||||
return;
|
||||
}
|
||||
if devices.is_empty() {
|
||||
return;
|
||||
}
|
||||
imp.reset_current_wifi_device
|
||||
.replace(devices.last().unwrap().clone());
|
||||
|
@ -192,24 +190,15 @@ pub fn show_stored_connections(wifi_box: Arc<WifiBox>) {
|
|||
|
||||
pub fn dbus_start_network_events() {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.Xetibo.ReSet.Daemon",
|
||||
"/org/Xetibo/ReSet/Daemon",
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let _: Result<(), Error> =
|
||||
proxy.method_call("org.Xetibo.ReSet.Wireless", "StartNetworkListener", ());
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let _: Result<(), Error> = proxy.method_call(WIRELESS, "StartNetworkListener", ());
|
||||
}
|
||||
|
||||
pub fn get_access_points() -> Vec<AccessPoint> {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.Xetibo.ReSet.Daemon",
|
||||
"/org/Xetibo/ReSet/Daemon",
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let res: Result<(Vec<AccessPoint>,), Error> =
|
||||
proxy.method_call("org.Xetibo.ReSet.Wireless", "ListAccessPoints", ());
|
||||
proxy.method_call(WIRELESS, "ListAccessPoints", ());
|
||||
if res.is_err() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
@ -219,24 +208,15 @@ pub fn get_access_points() -> Vec<AccessPoint> {
|
|||
|
||||
pub fn set_wifi_device(path: Path<'static>) {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.Xetibo.ReSet.Daemon",
|
||||
"/org/Xetibo/ReSet/Daemon",
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let _: Result<(bool,), Error> =
|
||||
proxy.method_call("org.Xetibo.ReSet.Wireless", "SetWifiDevice", (path,));
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let _: Result<(bool,), Error> = proxy.method_call(WIRELESS, "SetWifiDevice", (path,));
|
||||
}
|
||||
|
||||
pub fn get_wifi_devices() -> Vec<WifiDevice> {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.Xetibo.ReSet.Daemon",
|
||||
"/org/Xetibo/ReSet/Daemon",
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let res: Result<(Vec<WifiDevice>,), Error> =
|
||||
proxy.method_call("org.Xetibo.ReSet.Wireless", "GetAllWifiDevices", ());
|
||||
proxy.method_call(WIRELESS, "GetAllWifiDevices", ());
|
||||
if res.is_err() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
@ -246,13 +226,8 @@ pub fn get_wifi_devices() -> Vec<WifiDevice> {
|
|||
|
||||
pub fn get_wifi_status() -> bool {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.Xetibo.ReSet.Daemon",
|
||||
"/org/Xetibo/ReSet/Daemon",
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let res: Result<(bool,), Error> =
|
||||
proxy.method_call("org.Xetibo.ReSet.Wireless", "GetWifiStatus", ());
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let res: Result<(bool,), Error> = proxy.method_call(WIRELESS, "GetWifiStatus", ());
|
||||
if res.is_err() {
|
||||
return false;
|
||||
}
|
||||
|
@ -261,13 +236,8 @@ pub fn get_wifi_status() -> bool {
|
|||
|
||||
pub fn get_stored_connections() -> Vec<(Path<'static>, Vec<u8>)> {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.Xetibo.ReSet.Daemon",
|
||||
"/org/Xetibo/ReSet/Daemon",
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let res: ResultMap =
|
||||
proxy.method_call("org.Xetibo.ReSet.Wireless", "ListStoredConnections", ());
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let res: ResultMap = proxy.method_call(WIRELESS, "ListStoredConnections", ());
|
||||
if res.is_err() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
@ -277,13 +247,8 @@ pub fn get_stored_connections() -> Vec<(Path<'static>, Vec<u8>)> {
|
|||
|
||||
pub fn set_wifi_enabled(enabled: bool) {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.Xetibo.ReSet.Daemon",
|
||||
"/org/Xetibo/ReSet/Daemon",
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let _: Result<(bool,), Error> =
|
||||
proxy.method_call("org.Xetibo.ReSet.Wireless", "SetWifiEnabled", (enabled,));
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let _: Result<(bool,), Error> = proxy.method_call(WIRELESS, "SetWifiEnabled", (enabled,));
|
||||
}
|
||||
|
||||
pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
|
||||
|
@ -300,26 +265,18 @@ pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
|
|||
let removed_ref = wifi_box.clone();
|
||||
let changed_ref = wifi_box.clone();
|
||||
let wifi_changed_ref = wifi_box.clone();
|
||||
let access_point_added = AccessPointAdded::match_rule(
|
||||
Some(&"org.Xetibo.ReSet.Daemon".into()),
|
||||
Some(&Path::from("/org/Xetibo/ReSet/Daemon")),
|
||||
)
|
||||
.static_clone();
|
||||
let access_point_removed = AccessPointRemoved::match_rule(
|
||||
Some(&"org.Xetibo.ReSet.Daemon".into()),
|
||||
Some(&Path::from("/org/Xetibo/ReSet/Daemon")),
|
||||
)
|
||||
.static_clone();
|
||||
let access_point_changed = AccessPointChanged::match_rule(
|
||||
Some(&"org.Xetibo.ReSet.Daemon".into()),
|
||||
Some(&Path::from("/org/Xetibo/ReSet/Daemon")),
|
||||
)
|
||||
.static_clone();
|
||||
let device_changed = WifiDeviceChanged::match_rule(
|
||||
Some(&"org.Xetibo.ReSet.Daemon".into()),
|
||||
Some(&Path::from("/org/Xetibo/ReSet/Daemon")),
|
||||
)
|
||||
.static_clone();
|
||||
let access_point_added =
|
||||
AccessPointAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||
.static_clone();
|
||||
let access_point_removed =
|
||||
AccessPointRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||
.static_clone();
|
||||
let access_point_changed =
|
||||
AccessPointChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||
.static_clone();
|
||||
let device_changed =
|
||||
WifiDeviceChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||
.static_clone();
|
||||
let res = conn.add_match(access_point_added, move |ir: AccessPointAdded, _, _| {
|
||||
let wifi_box = added_ref.clone();
|
||||
glib::spawn_future(async move {
|
||||
|
|
|
@ -2,6 +2,7 @@ use std::ops::Deref;
|
|||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::components::utils::{WIRELESS, DBUS_PATH, BASE};
|
||||
use crate::components::wifi::utils::get_connection_settings;
|
||||
use adw::glib;
|
||||
use adw::glib::{Object, PropertySet};
|
||||
|
@ -123,12 +124,12 @@ pub fn click_disconnect(entry: Arc<WifiEntry>) {
|
|||
let imp = entry_ref.imp();
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.Xetibo.ReSet.Daemon",
|
||||
"/org/Xetibo/ReSet/Daemon",
|
||||
BASE,
|
||||
DBUS_PATH,
|
||||
Duration::from_millis(10000),
|
||||
);
|
||||
let res: Result<(bool,), Error> = proxy.method_call(
|
||||
"org.Xetibo.ReSet.Wireless",
|
||||
WIRELESS,
|
||||
"DisconnectFromCurrentAccessPoint",
|
||||
(),
|
||||
);
|
||||
|
@ -154,12 +155,12 @@ pub fn click_stored_network(entry: Arc<WifiEntry>) {
|
|||
gio::spawn_blocking(move || {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.Xetibo.ReSet.Daemon",
|
||||
"/org/Xetibo/ReSet/Daemon",
|
||||
BASE,
|
||||
DBUS_PATH,
|
||||
Duration::from_millis(10000),
|
||||
);
|
||||
let res: Result<(bool,), Error> = proxy.method_call(
|
||||
"org.Xetibo.ReSet.Wireless",
|
||||
WIRELESS,
|
||||
"ConnectToKnownAccessPoint",
|
||||
(access_point,),
|
||||
);
|
||||
|
@ -197,12 +198,12 @@ pub fn click_new_network(entry: Arc<WifiEntry>) {
|
|||
gio::spawn_blocking(move || {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.Xetibo.ReSet.Daemon",
|
||||
"/org/Xetibo/ReSet/Daemon",
|
||||
BASE,
|
||||
DBUS_PATH,
|
||||
Duration::from_millis(10000),
|
||||
);
|
||||
let res: Result<(bool,), Error> = proxy.method_call(
|
||||
"org.Xetibo.ReSet.Wireless",
|
||||
WIRELESS,
|
||||
"ConnectToNewAccessPoint",
|
||||
(access_point, password),
|
||||
);
|
||||
|
|
|
@ -18,6 +18,7 @@ use re_set_lib::network::connection::{
|
|||
|
||||
use IpProtocol::{IPv4, IPv6};
|
||||
|
||||
use crate::components::utils::{BASE, DBUS_PATH, WIRELESS};
|
||||
use crate::components::wifi::utils::IpProtocol;
|
||||
use crate::components::wifi::wifi_address_entry::WifiAddressEntry;
|
||||
use crate::components::wifi::wifi_options_impl;
|
||||
|
@ -59,7 +60,7 @@ impl WifiOptions {
|
|||
.set_active(conn.settings.autoconnect);
|
||||
self_imp
|
||||
.reset_wifi_metered
|
||||
.set_active(conn.settings.metered != -1);
|
||||
.set_active(conn.settings.metered != 0);
|
||||
match &conn.device {
|
||||
TypeSettings::WIFI(wifi) => {
|
||||
self_imp.reset_wifi_link_speed.set_visible(false);
|
||||
|
@ -389,12 +390,12 @@ fn set_connection_settings(path: Path<'static>, prop: HashMap<String, PropMap>)
|
|||
gio::spawn_blocking(move || {
|
||||
let conn = dbus::blocking::Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.Xetibo.ReSet.Daemon",
|
||||
"/org/Xetibo/ReSet/Daemon",
|
||||
BASE,
|
||||
DBUS_PATH,
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let _: Result<(bool,), Error> = proxy.method_call(
|
||||
"org.Xetibo.ReSet.Wireless",
|
||||
WIRELESS,
|
||||
"SetConnectionSettings",
|
||||
(path, prop),
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue