mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-04-12 08:28:32 +02:00
fix: Properly handle wifi and bluetooth turned on and off
This commit is contained in:
parent
e1be42a55d
commit
8796abb08f
|
@ -1,13 +1,13 @@
|
||||||
[package]
|
[package]
|
||||||
name = "reset"
|
name = "reset"
|
||||||
version = "0.1.6"
|
version = "0.1.8"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "A wip universal Linux settings application."
|
description = "A wip universal Linux settings application."
|
||||||
repository = "https://github.com/Xetibo/ReSet"
|
repository = "https://github.com/Xetibo/ReSet"
|
||||||
license = "GPL-3.0-only"
|
license = "GPL-3.0-only"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
reset_daemon = "0.7.1"
|
reset_daemon = "0.7.2"
|
||||||
re_set-lib = "0.8.7"
|
re_set-lib = "0.8.7"
|
||||||
adw = { version = "0.5.3", package = "libadwaita", features = ["v1_4"] }
|
adw = { version = "0.5.3", package = "libadwaita", features = ["v1_4"] }
|
||||||
dbus = "0.9.7"
|
dbus = "0.9.7"
|
||||||
|
|
2
PKGBUILD
2
PKGBUILD
|
@ -1,7 +1,7 @@
|
||||||
# Maintainer: Fabio Lenherr <dashie@dashie.org>
|
# Maintainer: Fabio Lenherr <dashie@dashie.org>
|
||||||
|
|
||||||
pkgname=reset
|
pkgname=reset
|
||||||
pkgver=0.1.6
|
pkgver=0.1.8
|
||||||
pkgrel=0
|
pkgrel=0
|
||||||
arch=('x86_64')
|
arch=('x86_64')
|
||||||
pkgdir="/usr/bin/${pkgname}"
|
pkgdir="/usr/bin/${pkgname}"
|
||||||
|
|
|
@ -9,7 +9,7 @@ use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||||
use dbus::blocking::Connection;
|
use dbus::blocking::Connection;
|
||||||
use dbus::message::SignalArgs;
|
use dbus::message::SignalArgs;
|
||||||
use dbus::{Error, Path};
|
use dbus::{Error, Path};
|
||||||
use glib::{clone, Cast};
|
use glib::{clone, Cast, PropertySet};
|
||||||
use gtk::glib::Variant;
|
use gtk::glib::Variant;
|
||||||
use gtk::prelude::{ActionableExt, ButtonExt, ListBoxRowExt, WidgetExt};
|
use gtk::prelude::{ActionableExt, ButtonExt, ListBoxRowExt, WidgetExt};
|
||||||
use gtk::{gio, StringObject};
|
use gtk::{gio, StringObject};
|
||||||
|
@ -48,6 +48,7 @@ fn setup_callbacks(
|
||||||
let bluetooth_box_ref = bluetooth_box.clone();
|
let bluetooth_box_ref = bluetooth_box.clone();
|
||||||
let listeners_ref = listeners.clone();
|
let listeners_ref = listeners.clone();
|
||||||
let imp = bluetooth_box.imp();
|
let imp = bluetooth_box.imp();
|
||||||
|
imp.reset_switch_initial.set(true);
|
||||||
imp.reset_visibility.set_activatable(true);
|
imp.reset_visibility.set_activatable(true);
|
||||||
imp.reset_visibility
|
imp.reset_visibility
|
||||||
.set_action_name(Some("navigation.push"));
|
.set_action_name(Some("navigation.push"));
|
||||||
|
@ -77,11 +78,15 @@ fn setup_callbacks(
|
||||||
set_bluetooth_adapter_pairability(imp.reset_current_bluetooth_adapter.borrow().path.clone(), state.is_active());
|
set_bluetooth_adapter_pairability(imp.reset_current_bluetooth_adapter.borrow().path.clone(), state.is_active());
|
||||||
}));
|
}));
|
||||||
|
|
||||||
imp.reset_bluetooth_switch
|
imp.reset_bluetooth_switch.connect_state_set(
|
||||||
.connect_state_set(move |_, state| {
|
clone!(@weak imp => @default-return glib::Propagation::Proceed, move |_, state| {
|
||||||
|
if imp.reset_switch_initial.load(Ordering::SeqCst) {
|
||||||
|
return glib::Propagation::Proceed;
|
||||||
|
}
|
||||||
if !state {
|
if !state {
|
||||||
let imp = bluetooth_box_ref.imp();
|
let imp = bluetooth_box_ref.imp();
|
||||||
let mut available_devices = imp.available_devices.borrow_mut();
|
let mut available_devices = imp.available_devices.borrow_mut();
|
||||||
|
let mut current_adapter = imp.reset_current_bluetooth_adapter.borrow_mut();
|
||||||
for entry in available_devices.iter() {
|
for entry in available_devices.iter() {
|
||||||
imp.reset_bluetooth_available_devices.remove(&**entry.1);
|
imp.reset_bluetooth_available_devices.remove(&**entry.1);
|
||||||
}
|
}
|
||||||
|
@ -102,10 +107,13 @@ fn setup_callbacks(
|
||||||
listeners_ref
|
listeners_ref
|
||||||
.bluetooth_listener
|
.bluetooth_listener
|
||||||
.store(false, Ordering::SeqCst);
|
.store(false, Ordering::SeqCst);
|
||||||
set_adapter_enabled(
|
let res = set_adapter_enabled(
|
||||||
imp.reset_current_bluetooth_adapter.borrow().path.clone(),
|
current_adapter.path.clone(),
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
if res {
|
||||||
|
current_adapter.powered = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let restart_ref = bluetooth_box_ref.clone();
|
let restart_ref = bluetooth_box_ref.clone();
|
||||||
let restart_listener_ref = listeners_ref.clone();
|
let restart_listener_ref = listeners_ref.clone();
|
||||||
|
@ -115,21 +123,21 @@ fn setup_callbacks(
|
||||||
imp.reset_bluetooth_pairable_switch.set_sensitive(true);
|
imp.reset_bluetooth_pairable_switch.set_sensitive(true);
|
||||||
}
|
}
|
||||||
gio::spawn_blocking(move || {
|
gio::spawn_blocking(move || {
|
||||||
|
let mut current_adapter = restart_ref.imp().reset_current_bluetooth_adapter.borrow_mut();
|
||||||
if set_adapter_enabled(
|
if set_adapter_enabled(
|
||||||
restart_ref
|
current_adapter
|
||||||
.imp()
|
|
||||||
.reset_current_bluetooth_adapter
|
|
||||||
.borrow()
|
|
||||||
.path
|
.path
|
||||||
.clone(),
|
.clone(),
|
||||||
true,
|
true,
|
||||||
) {
|
) {
|
||||||
|
current_adapter.powered = true;
|
||||||
start_bluetooth_listener(restart_listener_ref.clone(), restart_ref.clone());
|
start_bluetooth_listener(restart_listener_ref.clone(), restart_ref.clone());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
glib::Propagation::Proceed
|
glib::Propagation::Proceed
|
||||||
});
|
}),
|
||||||
|
);
|
||||||
bluetooth_box
|
bluetooth_box
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,12 +177,14 @@ pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
|
||||||
|
|
||||||
{
|
{
|
||||||
let current_adapter = imp.reset_current_bluetooth_adapter.borrow();
|
let current_adapter = imp.reset_current_bluetooth_adapter.borrow();
|
||||||
imp.reset_bluetooth_switch
|
let powered = current_adapter.powered;
|
||||||
.set_state(current_adapter.powered);
|
imp.reset_bluetooth_switch.set_state(powered);
|
||||||
|
imp.reset_bluetooth_switch.set_active(powered);
|
||||||
imp.reset_bluetooth_discoverable_switch
|
imp.reset_bluetooth_discoverable_switch
|
||||||
.set_active(current_adapter.discoverable);
|
.set_active(current_adapter.discoverable);
|
||||||
imp.reset_bluetooth_pairable_switch
|
imp.reset_bluetooth_pairable_switch
|
||||||
.set_active(current_adapter.pairable);
|
.set_active(current_adapter.pairable);
|
||||||
|
imp.reset_switch_initial.set(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
imp.reset_bluetooth_adapter.connect_selected_notify(
|
imp.reset_bluetooth_adapter.connect_selected_notify(
|
||||||
|
@ -219,6 +229,11 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
|
||||||
if listeners.bluetooth_listener.load(Ordering::SeqCst) {
|
if listeners.bluetooth_listener.load(Ordering::SeqCst) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let imp = bluetooth_box.imp();
|
||||||
|
|
||||||
|
if !imp.reset_current_bluetooth_adapter.borrow().powered {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let device_added_box = bluetooth_box.clone();
|
let device_added_box = bluetooth_box.clone();
|
||||||
let device_removed_box = bluetooth_box.clone();
|
let device_removed_box = bluetooth_box.clone();
|
||||||
|
@ -228,9 +243,7 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
let _: Result<(), Error> = proxy.method_call(BLUETOOTH, "StartBluetoothListener", ());
|
let _: Result<(), Error> = proxy.method_call(BLUETOOTH, "StartBluetoothListener", ());
|
||||||
loop_box
|
imp.reset_bluetooth_available_devices
|
||||||
.imp()
|
|
||||||
.reset_bluetooth_available_devices
|
|
||||||
.set_description(Some("Scanning..."));
|
.set_description(Some("Scanning..."));
|
||||||
let device_added =
|
let device_added =
|
||||||
BluetoothDeviceAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
BluetoothDeviceAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||||
|
|
|
@ -6,6 +6,7 @@ use gtk::{prelude::*, StringList};
|
||||||
use re_set_lib::bluetooth::bluetooth_structures::BluetoothAdapter;
|
use re_set_lib::bluetooth::bluetooth_structures::BluetoothAdapter;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
use crate::components::base::list_entry::ListEntry;
|
use crate::components::base::list_entry::ListEntry;
|
||||||
|
@ -41,6 +42,7 @@ pub struct BluetoothBox {
|
||||||
pub reset_current_bluetooth_adapter: Arc<RefCell<BluetoothAdapter>>,
|
pub reset_current_bluetooth_adapter: Arc<RefCell<BluetoothAdapter>>,
|
||||||
pub reset_model_list: Arc<RwLock<StringList>>,
|
pub reset_model_list: Arc<RwLock<StringList>>,
|
||||||
pub reset_model_index: Arc<RwLock<u32>>,
|
pub reset_model_index: Arc<RwLock<u32>>,
|
||||||
|
pub reset_switch_initial: AtomicBool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
|
|
|
@ -50,6 +50,7 @@ impl WifiBox {
|
||||||
fn setup_callbacks(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) -> Arc<WifiBox> {
|
fn setup_callbacks(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) -> Arc<WifiBox> {
|
||||||
let imp = wifi_box.imp();
|
let imp = wifi_box.imp();
|
||||||
let wifibox_ref = wifi_box.clone();
|
let wifibox_ref = wifi_box.clone();
|
||||||
|
imp.reset_switch_initial.set(true);
|
||||||
imp.reset_saved_networks.set_activatable(true);
|
imp.reset_saved_networks.set_activatable(true);
|
||||||
imp.reset_saved_networks
|
imp.reset_saved_networks
|
||||||
.set_action_name(Some("navigation.push"));
|
.set_action_name(Some("navigation.push"));
|
||||||
|
@ -62,6 +63,9 @@ fn setup_callbacks(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) -> Arc<Wif
|
||||||
set_combo_row_ellipsis(imp.reset_wifi_device.get());
|
set_combo_row_ellipsis(imp.reset_wifi_device.get());
|
||||||
imp.reset_wifi_switch.connect_state_set(
|
imp.reset_wifi_switch.connect_state_set(
|
||||||
clone!(@weak imp => @default-return glib::Propagation::Proceed, move |_, value| {
|
clone!(@weak imp => @default-return glib::Propagation::Proceed, move |_, value| {
|
||||||
|
if imp.reset_switch_initial.load(Ordering::SeqCst) {
|
||||||
|
return glib::Propagation::Proceed;
|
||||||
|
}
|
||||||
set_wifi_enabled(value);
|
set_wifi_enabled(value);
|
||||||
if !value {
|
if !value {
|
||||||
imp.reset_wifi_devices.write().unwrap().clear();
|
imp.reset_wifi_devices.write().unwrap().clear();
|
||||||
|
@ -93,17 +97,17 @@ pub fn scan_for_wifi(wifi_box: Arc<WifiBox>) {
|
||||||
let wifi_entries_path = wifi_box.imp().wifi_entries_path.clone();
|
let wifi_entries_path = wifi_box.imp().wifi_entries_path.clone();
|
||||||
|
|
||||||
gio::spawn_blocking(move || {
|
gio::spawn_blocking(move || {
|
||||||
let devices = get_wifi_devices();
|
|
||||||
let access_points = get_access_points();
|
|
||||||
let wifi_status = get_wifi_status();
|
let wifi_status = get_wifi_status();
|
||||||
|
let devices = get_wifi_devices();
|
||||||
|
if devices.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let access_points = get_access_points();
|
||||||
{
|
{
|
||||||
let imp = wifibox_ref.imp();
|
let imp = wifibox_ref.imp();
|
||||||
let list = imp.reset_model_list.write().unwrap();
|
let list = imp.reset_model_list.write().unwrap();
|
||||||
let mut model_index = imp.reset_model_index.write().unwrap();
|
let mut model_index = imp.reset_model_index.write().unwrap();
|
||||||
let mut map = imp.reset_wifi_devices.write().unwrap();
|
let mut map = imp.reset_wifi_devices.write().unwrap();
|
||||||
if devices.is_empty() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
imp.reset_current_wifi_device
|
imp.reset_current_wifi_device
|
||||||
.replace(devices.last().unwrap().clone());
|
.replace(devices.last().unwrap().clone());
|
||||||
for (index, device) in devices.into_iter().enumerate() {
|
for (index, device) in devices.into_iter().enumerate() {
|
||||||
|
@ -121,8 +125,9 @@ pub fn scan_for_wifi(wifi_box: Arc<WifiBox>) {
|
||||||
let mut wifi_entries_path = wifi_entries_path.write().unwrap();
|
let mut wifi_entries_path = wifi_entries_path.write().unwrap();
|
||||||
let imp = wifibox_ref.imp();
|
let imp = wifibox_ref.imp();
|
||||||
|
|
||||||
imp.reset_wifi_switch.set_active(wifi_status);
|
|
||||||
imp.reset_wifi_switch.set_state(wifi_status);
|
imp.reset_wifi_switch.set_state(wifi_status);
|
||||||
|
imp.reset_wifi_switch.set_active(wifi_status);
|
||||||
|
imp.reset_switch_initial.set(false);
|
||||||
|
|
||||||
let list = imp.reset_model_list.read().unwrap();
|
let list = imp.reset_model_list.read().unwrap();
|
||||||
imp.reset_wifi_device.set_model(Some(&*list));
|
imp.reset_wifi_device.set_model(Some(&*list));
|
||||||
|
|
|
@ -7,6 +7,7 @@ use gtk::{prelude::*, StringList};
|
||||||
use re_set_lib::network::network_structures::WifiDevice;
|
use re_set_lib::network::network_structures::WifiDevice;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
use crate::components::base::list_entry::ListEntry;
|
use crate::components::base::list_entry::ListEntry;
|
||||||
|
@ -37,6 +38,7 @@ pub struct WifiBox {
|
||||||
pub reset_current_wifi_device: Arc<RefCell<WifiDevice>>,
|
pub reset_current_wifi_device: Arc<RefCell<WifiDevice>>,
|
||||||
pub reset_model_list: Arc<RwLock<StringList>>,
|
pub reset_model_list: Arc<RwLock<StringList>>,
|
||||||
pub reset_model_index: Arc<RwLock<u32>>,
|
pub reset_model_index: Arc<RwLock<u32>>,
|
||||||
|
pub reset_switch_initial: AtomicBool,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Send for WifiBox {}
|
unsafe impl Send for WifiBox {}
|
||||||
|
|
|
@ -103,7 +103,7 @@ impl ReSetWindow {
|
||||||
.license_type(gtk::License::Gpl30)
|
.license_type(gtk::License::Gpl30)
|
||||||
.website("https://github.com/Xetibo/ReSet")
|
.website("https://github.com/Xetibo/ReSet")
|
||||||
.issue_url("https://github.com/Xetibo/ReSet/issues")
|
.issue_url("https://github.com/Xetibo/ReSet/issues")
|
||||||
.version("0.1.6")
|
.version("0.1.8")
|
||||||
.transient_for(window)
|
.transient_for(window)
|
||||||
.modal(true)
|
.modal(true)
|
||||||
.copyright("© 2022-2023 Xetibo")
|
.copyright("© 2022-2023 Xetibo")
|
||||||
|
|
|
@ -373,7 +373,6 @@
|
||||||
(4,183,"GtkLabel","label","WiFi",None,None,None,None,None,None,None,None,None),
|
(4,183,"GtkLabel","label","WiFi",None,None,None,None,None,None,None,None,None),
|
||||||
(4,183,"GtkWidget","css-classes","resetSettingLabel",None,None,None,None,None,None,None,None,None),
|
(4,183,"GtkWidget","css-classes","resetSettingLabel",None,None,None,None,None,None,None,None,None),
|
||||||
(4,183,"GtkWidget","margin-start","5",None,None,None,None,None,None,None,None,None),
|
(4,183,"GtkWidget","margin-start","5",None,None,None,None,None,None,None,None,None),
|
||||||
(4,184,"GtkSwitch","active","True",None,None,None,None,None,None,None,None,None),
|
|
||||||
(4,184,"GtkWidget","halign","end",None,None,None,None,None,None,None,None,None),
|
(4,184,"GtkWidget","halign","end",None,None,None,None,None,None,None,None,None),
|
||||||
(4,184,"GtkWidget","hexpand","True",None,None,None,None,None,None,None,None,None),
|
(4,184,"GtkWidget","hexpand","True",None,None,None,None,None,None,None,None,None),
|
||||||
(4,184,"GtkWidget","margin-end","5",None,None,None,None,None,None,None,None,None),
|
(4,184,"GtkWidget","margin-end","5",None,None,None,None,None,None,None,None,None),
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkSwitch" id="reset_wifi_switch">
|
<object class="GtkSwitch" id="reset_wifi_switch">
|
||||||
<property name="active">True</property>
|
|
||||||
<property name="halign">end</property>
|
<property name="halign">end</property>
|
||||||
<property name="hexpand">True</property>
|
<property name="hexpand">True</property>
|
||||||
<property name="margin-end">5</property>
|
<property name="margin-end">5</property>
|
||||||
|
|
Loading…
Reference in a new issue