chore: Code cleanup

This commit is contained in:
Fabio Lenherr / DashieTM 2023-11-19 02:37:11 +01:00
parent 192dacb333
commit cb3dd257f1
22 changed files with 121 additions and 106 deletions

View file

@ -12,6 +12,19 @@
"dest": "cargo/vendor/ReSet-Lib-0.2.8", "dest": "cargo/vendor/ReSet-Lib-0.2.8",
"dest-filename": ".cargo-checksum.json" "dest-filename": ".cargo-checksum.json"
}, },
{
"type": "archive",
"archive-type": "tar-gzip",
"url": "https://static.crates.io/crates/ReSet-Lib/ReSet-Lib-0.3.5.crate",
"sha256": "a0f2428f460a6604b353461d8244b3ce8841adcd964a2165cd2f9b975462b19d",
"dest": "cargo/vendor/ReSet-Lib-0.3.5"
},
{
"type": "inline",
"contents": "{\"package\": \"a0f2428f460a6604b353461d8244b3ce8841adcd964a2165cd2f9b975462b19d\", \"files\": {}}",
"dest": "cargo/vendor/ReSet-Lib-0.3.5",
"dest-filename": ".cargo-checksum.json"
},
{ {
"type": "archive", "type": "archive",
"archive-type": "tar-gzip", "archive-type": "tar-gzip",

View file

@ -1,9 +1,8 @@
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::HashMap; use std::collections::HashMap;
use crate::components::base::listEntry::ListEntry;
use gtk::subclass::prelude::*; use gtk::subclass::prelude::*;
use gtk::{glib, CompositeTemplate, TemplateChild, Label, DropDown, StringList}; use gtk::{glib, CompositeTemplate, DropDown, Label, StringList, TemplateChild};
use super::cardEntry; use super::cardEntry;
@ -19,7 +18,7 @@ pub struct CardEntry {
pub resetCardList: TemplateChild<StringList>, pub resetCardList: TemplateChild<StringList>,
// first string is the alias name, the first return string is the index of the adapter and the // first string is the alias name, the first return string is the index of the adapter and the
// second the name of the profile // second the name of the profile
pub resetCardMap: RefCell<HashMap<String, (u32, String)>> pub resetCardMap: RefCell<HashMap<String, (u32, String)>>,
} }
#[glib::object_subclass] #[glib::object_subclass]

View file

@ -1,8 +1,6 @@
use std::collections::HashMap;
use crate::components::base::listEntry; use crate::components::base::listEntry;
use gtk::subclass::prelude::*; use gtk::subclass::prelude::*;
use gtk::{glib, CompositeTemplate, DropDown, Label, StringList}; use gtk::{glib, CompositeTemplate};
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[derive(Default, CompositeTemplate)] #[derive(Default, CompositeTemplate)]

View file

@ -1,9 +1,9 @@
pub mod settingBox; pub mod cardEntry;
pub mod settingBoxImpl; pub mod cardEntryImpl;
pub mod listEntry; pub mod listEntry;
pub mod listEntryImpl; pub mod listEntryImpl;
pub mod popup; pub mod popup;
pub mod popupImpl; pub mod popupImpl;
pub mod settingBox;
pub mod settingBoxImpl;
pub mod utils; pub mod utils;
pub mod cardEntry;
pub mod cardEntryImpl;

View file

@ -16,4 +16,5 @@ impl SettingBox {
entry.append(child); entry.append(child);
entry entry
} }
} }

View file

@ -18,7 +18,7 @@ use crate::components::base::listEntry::ListEntry;
use crate::components::base::utils::Listeners; use crate::components::base::utils::Listeners;
use crate::components::bluetooth::bluetoothBoxImpl; use crate::components::bluetooth::bluetoothBoxImpl;
use crate::components::bluetooth::bluetoothEntry::BluetoothEntry; use crate::components::bluetooth::bluetoothEntry::BluetoothEntry;
use crate::components::bluetooth::bluetoothEntryImpl::DeviceTypes; // use crate::components::bluetooth::bluetoothEntryImpl::DeviceTypes;
glib::wrapper! { glib::wrapper! {
pub struct BluetoothBox(ObjectSubclass<bluetoothBoxImpl::BluetoothBox>) pub struct BluetoothBox(ObjectSubclass<bluetoothBoxImpl::BluetoothBox>)
@ -170,7 +170,7 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
loop { loop {
let _ = conn.process(Duration::from_millis(1000)); let _ = conn.process(Duration::from_millis(1000));
if !listeners.bluetooth_listener.load(Ordering::SeqCst) if !listeners.bluetooth_listener.load(Ordering::SeqCst)
// || time.elapsed().unwrap() > Duration::from_millis(5000) // || time.elapsed().unwrap() > Duration::from_millis(5000)
{ {
glib::spawn_future(async move { glib::spawn_future(async move {
glib::idle_add_once(move || { glib::idle_add_once(move || {

View file

@ -1,7 +1,7 @@
use std::time::Duration; use std::time::Duration;
use crate::components::bluetooth::bluetoothEntryImpl; use crate::components::bluetooth::bluetoothEntryImpl;
use crate::components::bluetooth::bluetoothEntryImpl::DeviceTypes; // use crate::components::bluetooth::bluetoothEntryImpl::DeviceTypes;
use adw::glib; use adw::glib;
use adw::glib::Object; use adw::glib::Object;
use adw::subclass::prelude::ObjectSubclassIsExt; use adw::subclass::prelude::ObjectSubclassIsExt;
@ -23,7 +23,10 @@ impl BluetoothEntry {
let entry: BluetoothEntry = Object::builder().build(); let entry: BluetoothEntry = Object::builder().build();
let entryImp = entry.imp(); let entryImp = entry.imp();
entryImp.resetBluetoothLabel.get().set_text(&device.name); entryImp.resetBluetoothLabel.get().set_text(&device.name);
entryImp.resetBluetoothAddress.get().set_text(&device.address); entryImp
.resetBluetoothAddress
.get()
.set_text(&device.address);
// entryImp // entryImp
// .resetBluetoothDeviceType // .resetBluetoothDeviceType
// .get() // .get()

View file

@ -1,8 +1,8 @@
use crate::components::bluetooth::bluetoothEntry;
use gtk::subclass::prelude::*;
use gtk::{glib, Button, CompositeTemplate, Image, Label};
use std::cell::RefCell; use std::cell::RefCell;
use ReSet_Lib::bluetooth::bluetooth::BluetoothDevice; use ReSet_Lib::bluetooth::bluetooth::BluetoothDevice;
use gtk::{Button, CompositeTemplate, glib, Image, Label};
use gtk::subclass::prelude::*;
use crate::components::bluetooth::bluetoothEntry;
#[derive(Default, Copy, Clone)] #[derive(Default, Copy, Clone)]
pub enum DeviceTypes { pub enum DeviceTypes {
@ -26,7 +26,7 @@ pub struct BluetoothEntry {
#[template_child] #[template_child]
pub resetBluetoothButton: TemplateChild<Button>, pub resetBluetoothButton: TemplateChild<Button>,
pub deviceName: RefCell<String>, pub deviceName: RefCell<String>,
pub device: RefCell<BluetoothDevice> pub device: RefCell<BluetoothDevice>,
} }
#[glib::object_subclass] #[glib::object_subclass]

View file

@ -1,5 +1,6 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
pub mod bluetoothBox; pub mod bluetoothBox;
pub mod bluetoothEntry;
pub mod bluetoothBoxImpl; pub mod bluetoothBoxImpl;
pub mod bluetoothEntryImpl; pub mod bluetoothEntry;
pub mod bluetoothEntryImpl;

View file

@ -1,7 +1,7 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
pub mod sourceBox;
pub mod sourceBoxImpl;
pub mod outputStreamEntry; pub mod outputStreamEntry;
pub mod outputStreamEntryImpl; pub mod outputStreamEntryImpl;
pub mod sourceBox;
pub mod sourceBoxImpl;
pub mod sourceEntry; pub mod sourceEntry;
pub mod sourceEntryImpl; pub mod sourceEntryImpl;

View file

@ -1,12 +1,11 @@
use std::sync::atomic::Ordering;
use std::sync::Arc; use std::sync::Arc;
use std::time::{Duration, SystemTime}; use std::time::{Duration, SystemTime};
use crate::components::base::cardEntry::CardEntry; use crate::components::base::cardEntry::CardEntry;
use crate::components::base::listEntry::ListEntry; use crate::components::base::listEntry::ListEntry;
use crate::components::base::utils::{ use crate::components::base::utils::{
Listeners, OutputStreamAdded, OutputStreamChanged, OutputStreamRemoved, SourceAdded, OutputStreamAdded, OutputStreamChanged, OutputStreamRemoved, SourceAdded, SourceChanged,
SourceChanged, SourceRemoved, SourceRemoved,
}; };
use crate::components::input::sourceBoxImpl; use crate::components::input::sourceBoxImpl;
use crate::components::input::sourceEntry::set_source_volume; use crate::components::input::sourceEntry::set_source_volume;

View file

@ -3,7 +3,7 @@ use std::sync::Arc;
use std::time::SystemTime; use std::time::SystemTime;
use gtk::subclass::prelude::*; use gtk::subclass::prelude::*;
use gtk::{glib, Button, CompositeTemplate, Label, ProgressBar, Scale, CheckButton}; use gtk::{glib, Button, CheckButton, CompositeTemplate, Label, ProgressBar, Scale};
use ReSet_Lib::audio::audio::Source; use ReSet_Lib::audio::audio::Source;
use super::sourceEntry; use super::sourceEntry;

View file

@ -1,6 +1,7 @@
pub mod window;
pub mod wifi;
pub mod bluetooth;
pub mod output;
mod base; mod base;
mod input; pub mod bluetooth;
mod input;
pub mod output;
pub mod wifi;
pub mod window;

View file

@ -1,7 +1,7 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
pub mod sinkBox;
pub mod sinkBoxImpl;
pub mod inputStreamEntry; pub mod inputStreamEntry;
pub mod inputStreamEntryImpl; pub mod inputStreamEntryImpl;
pub mod sinkBox;
pub mod sinkBoxImpl;
pub mod sinkEntry; pub mod sinkEntry;
pub mod sinkEntryImpl; pub mod sinkEntryImpl;

View file

@ -1,12 +1,10 @@
use std::sync::atomic::Ordering;
use std::sync::Arc; use std::sync::Arc;
use std::time::{Duration, SystemTime}; use std::time::{Duration, SystemTime};
use crate::components::base::cardEntry::CardEntry; use crate::components::base::cardEntry::CardEntry;
use crate::components::base::listEntry::ListEntry; use crate::components::base::listEntry::ListEntry;
use crate::components::base::utils::{ use crate::components::base::utils::{
InputStreamAdded, InputStreamChanged, InputStreamRemoved, Listeners, SinkAdded, SinkChanged, InputStreamAdded, InputStreamChanged, InputStreamRemoved, SinkAdded, SinkChanged, SinkRemoved,
SinkRemoved,
}; };
use crate::components::output::sinkEntry::set_sink_volume; use crate::components::output::sinkEntry::set_sink_volume;
use adw::glib::Object; use adw::glib::Object;

View file

@ -4,7 +4,7 @@ use std::time::SystemTime;
use crate::components::output::sinkEntry; use crate::components::output::sinkEntry;
use gtk::subclass::prelude::*; use gtk::subclass::prelude::*;
use gtk::{glib, Button, CompositeTemplate, Label, ProgressBar, Scale, CheckButton}; use gtk::{glib, Button, CheckButton, CompositeTemplate, Label, ProgressBar, Scale};
use ReSet_Lib::audio::audio::Sink; use ReSet_Lib::audio::audio::Sink;
#[allow(non_snake_case)] #[allow(non_snake_case)]

View file

@ -1,7 +1,7 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
pub mod savedWifiEntry; pub mod savedWifiEntry;
pub mod savedWifiEntryImpl;
pub mod wifiBox; pub mod wifiBox;
pub mod wifiBoxImpl; pub mod wifiBoxImpl;
pub mod wifiEntry; pub mod wifiEntry;
pub mod wifiEntryImpl; pub mod wifiEntryImpl;
pub mod savedWifiEntryImpl;

View file

@ -1,12 +1,12 @@
use std::collections::HashMap; use crate::components::wifi::wifiBox;
use std::sync::{Arc, Mutex};
use gtk::{CompositeTemplate, glib, ListBox, Switch};
use gtk::prelude::*; use gtk::prelude::*;
use gtk::subclass::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::base::listEntry::ListEntry;
use crate::components::wifi::wifiEntry::WifiEntry;
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[derive(Default, CompositeTemplate)] #[derive(Default, CompositeTemplate)]
@ -24,7 +24,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<HashMap<Vec<u8>,Arc<ListEntry>>>>, pub wifiEntries: Arc<Mutex<HashMap<Vec<u8>, Arc<ListEntry>>>>,
pub savedWifiEntries: Arc<Mutex<Vec<ListEntry>>>, pub savedWifiEntries: Arc<Mutex<Vec<ListEntry>>>,
} }

View file

@ -1,5 +1,5 @@
use std::sync::Arc;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use adw::glib; use adw::glib;
@ -8,9 +8,9 @@ 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;
use glib::{Cast, clone}; use glib::{clone, Cast};
use gtk::{AlertDialog, GestureClick};
use gtk::prelude::WidgetExt; use gtk::prelude::WidgetExt;
use gtk::{AlertDialog, GestureClick};
use ReSet_Lib::network::network::{AccessPoint, WifiStrength}; use ReSet_Lib::network::network::{AccessPoint, WifiStrength};
use crate::components::wifi::wifiBox::getConnectionSettings; 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>) { pub fn click_new_network(entry: Arc<WifiEntry>) {
let connect_new_network = let connect_new_network = |result: Arc<AtomicBool>,
|result: Arc<AtomicBool>, entry: Arc<WifiEntry>, access_point: AccessPoint, password: String| { entry: Arc<WifiEntry>,
let entry_ref = entry.clone(); access_point: AccessPoint,
let popup = entry.imp().resetWifiPopup.imp(); password: String| {
popup.resetPopupLabel.set_text("Connecting..."); let entry_ref = entry.clone();
popup.resetPopupLabel.set_visible(true); let popup = entry.imp().resetWifiPopup.imp();
popup.resetPopupEntry.set_sensitive(false); popup.resetPopupLabel.set_text("Connecting...");
popup.resetPopupButton.set_sensitive(false); popup.resetPopupLabel.set_visible(true);
popup.resetPopupEntry.set_sensitive(false);
popup.resetPopupButton.set_sensitive(false);
glib::spawn_future_local(async move { glib::spawn_future_local(async 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(10000), 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",
"ConnectToNewAccessPoint", "ConnectToNewAccessPoint",
(access_point, password), (access_point, password),
); );
glib::MainContext::default().spawn_local(async move { glib::MainContext::default().spawn_local(async move {
glib::idle_add_once(move || { glib::idle_add_once(move || {
if res.is_err() { if res.is_err() {
entry_ref entry_ref
.imp() .imp()
.resetWifiPopup .resetWifiPopup
.imp() .imp()
.resetPopupLabel .resetPopupLabel
.set_text("Could not connect to dbus."); .set_text("Could not connect to dbus.");
result.store(false, std::sync::atomic::Ordering::SeqCst); result.store(false, std::sync::atomic::Ordering::SeqCst);
return; return;
} }
if res.unwrap() == (false,) { if res.unwrap() == (false,) {
entry_ref entry_ref
.imp() .imp()
.resetWifiPopup .resetWifiPopup
.imp() .imp()
.resetPopupLabel .resetPopupLabel
.set_text("Could not connect to access point."); .set_text("Could not connect to access point.");
result.store(false, std::sync::atomic::Ordering::SeqCst); result.store(false, std::sync::atomic::Ordering::SeqCst);
return; return;
} }
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);
});
}); });
}); });
// TODO crate spinner animation and block UI });
}; // TODO crate spinner animation and block UI
};
let result = Arc::new(AtomicBool::new(false)); let result = Arc::new(AtomicBool::new(false));
let result_ref = result.clone(); let result_ref = result.clone();

View file

@ -1,6 +1,6 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
pub mod window; pub mod handleSidebarClick;
pub mod windowImpl;
pub mod sidebarEntry; pub mod sidebarEntry;
pub mod sidebarEntryImpl; pub mod sidebarEntryImpl;
pub mod handleSidebarClick; pub mod window;
pub mod windowImpl;

View file

@ -1,12 +1,12 @@
use std::sync::Arc; use std::sync::Arc;
use adw::subclass::prelude::ObjectSubclassIsExt;
use glib::Object;
use gtk::{FlowBox, glib};
use gtk::prelude::*;
use crate::components::base::utils::Listeners; use crate::components::base::utils::Listeners;
use crate::components::window::sidebarEntryImpl; use crate::components::window::sidebarEntryImpl;
use crate::components::window::sidebarEntryImpl::{Categories, SidebarAction}; use crate::components::window::sidebarEntryImpl::{Categories, SidebarAction};
use adw::subclass::prelude::ObjectSubclassIsExt;
use glib::Object;
use gtk::prelude::*;
use gtk::{glib, FlowBox};
glib::wrapper! { glib::wrapper! {
pub struct SidebarEntry(ObjectSubclass<sidebarEntryImpl::SidebarEntry>) pub struct SidebarEntry(ObjectSubclass<sidebarEntryImpl::SidebarEntry>)

View file

@ -2,8 +2,8 @@ use std::cell::{Cell, RefCell};
use std::sync::Arc; use std::sync::Arc;
use glib::subclass::InitializingObject; use glib::subclass::InitializingObject;
use gtk::{CompositeTemplate, FlowBox, glib, Image, Label, ListBoxRow};
use gtk::subclass::prelude::*; use gtk::subclass::prelude::*;
use gtk::{glib, CompositeTemplate, FlowBox, Image, Label, ListBoxRow};
use crate::components::base::utils::Listeners; use crate::components::base::utils::Listeners;
use crate::components::window::handleSidebarClick::HANDLE_HOME; use crate::components::window::handleSidebarClick::HANDLE_HOME;
@ -29,18 +29,18 @@ pub struct SidebarEntry {
pub category: Cell<Categories>, pub category: Cell<Categories>,
pub isSubcategory: Cell<bool>, pub isSubcategory: Cell<bool>,
pub onClickEvent: RefCell<SidebarAction>, pub onClickEvent: RefCell<SidebarAction>,
pub name : RefCell<String>, pub name: RefCell<String>,
} }
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub struct SidebarAction { pub struct SidebarAction {
pub onClickEvent: fn(Arc<Listeners>,FlowBox), pub onClickEvent: fn(Arc<Listeners>, FlowBox),
} }
impl Default for SidebarAction { impl Default for SidebarAction {
fn default() -> Self { fn default() -> Self {
Self { Self {
onClickEvent: HANDLE_HOME onClickEvent: HANDLE_HOME,
} }
} }
} }