mirror of
				https://github.com/Xetibo/ReSet.git
				synced 2025-11-04 09:45:19 +01:00 
			
		
		
		
	feat: Initial work on bluetooth on and off
This commit is contained in:
		
							parent
							
								
									4a34144ebc
								
							
						
					
					
						commit
						b2b4ae0661
					
				
					 2 changed files with 30 additions and 22 deletions
				
			
		| 
						 | 
				
			
			@ -30,30 +30,38 @@ unsafe impl Send for BluetoothBox {}
 | 
			
		|||
unsafe impl Sync for BluetoothBox {}
 | 
			
		||||
 | 
			
		||||
impl BluetoothBox {
 | 
			
		||||
    pub fn new() -> Self {
 | 
			
		||||
        Object::builder().build()
 | 
			
		||||
    pub fn new(listeners: Arc<Listeners>) -> Arc<Self> {
 | 
			
		||||
        let obj: Arc<Self> = Arc::new(Object::builder().build());
 | 
			
		||||
        setupCallbacks(listeners, obj)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn setupCallbacks(&self) {
 | 
			
		||||
        let selfImp = self.imp();
 | 
			
		||||
        selfImp.resetVisibility.set_activatable(true);
 | 
			
		||||
        selfImp
 | 
			
		||||
            .resetVisibility
 | 
			
		||||
            .set_action_name(Some("navigation.push"));
 | 
			
		||||
        selfImp
 | 
			
		||||
            .resetVisibility
 | 
			
		||||
            .set_action_target_value(Some(&Variant::from("visibility")));
 | 
			
		||||
 | 
			
		||||
        selfImp
 | 
			
		||||
            .resetBluetoothMainTab
 | 
			
		||||
            .set_action_name(Some("navigation.pop"));
 | 
			
		||||
    }
 | 
			
		||||
    pub fn setupCallbacks(&self) {}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Default for BluetoothBox {
 | 
			
		||||
    fn default() -> Self {
 | 
			
		||||
        Self::new()
 | 
			
		||||
    }
 | 
			
		||||
fn setupCallbacks(
 | 
			
		||||
    listeners: Arc<Listeners>,
 | 
			
		||||
    bluetooth_box: Arc<BluetoothBox>,
 | 
			
		||||
) -> Arc<BluetoothBox> {
 | 
			
		||||
    let imp = bluetooth_box.imp();
 | 
			
		||||
    // let bluetooth_box_ref = bluetooth_box.clone();
 | 
			
		||||
    imp.resetVisibility.set_activatable(true);
 | 
			
		||||
    imp.resetVisibility.set_action_name(Some("navigation.push"));
 | 
			
		||||
    imp.resetVisibility
 | 
			
		||||
        .set_action_target_value(Some(&Variant::from("visibility")));
 | 
			
		||||
 | 
			
		||||
    imp.resetBluetoothMainTab
 | 
			
		||||
        .set_action_name(Some("navigation.pop"));
 | 
			
		||||
    // TODO add a manual search button here
 | 
			
		||||
    imp.resetBluetoothSwitch.connect_state_set(move |_, state| {
 | 
			
		||||
        // TODO restart bluetooth search here.
 | 
			
		||||
        if !state {
 | 
			
		||||
            listeners.bluetooth_listener.store(false, Ordering::SeqCst);
 | 
			
		||||
        } else {
 | 
			
		||||
            listeners.bluetooth_listener.store(true, Ordering::SeqCst);
 | 
			
		||||
        }
 | 
			
		||||
        glib::Propagation::Proceed
 | 
			
		||||
    });
 | 
			
		||||
    bluetooth_box
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,7 +23,7 @@ pub const HANDLE_CONNECTIVITY_CLICK: fn(Arc<Listeners>, FlowBox) =
 | 
			
		|||
        show_stored_connections(wifiBox.clone());
 | 
			
		||||
        scanForWifi(wifiBox.clone());
 | 
			
		||||
        let wifiFrame = wrapInFrame(SettingBox::new(&*wifiBox));
 | 
			
		||||
        let bluetooth_box = Arc::new(BluetoothBox::new());
 | 
			
		||||
        let bluetooth_box = BluetoothBox::new(listeners.clone());
 | 
			
		||||
        populate_conntected_bluetooth_devices(bluetooth_box.clone());
 | 
			
		||||
        start_bluetooth_listener(listeners.clone(), bluetooth_box.clone());
 | 
			
		||||
        let bluetoothFrame = wrapInFrame(SettingBox::new(&*bluetooth_box));
 | 
			
		||||
| 
						 | 
				
			
			@ -51,7 +51,7 @@ pub const HANDLE_BLUETOOTH_CLICK: fn(Arc<Listeners>, FlowBox) =
 | 
			
		|||
    |listeners: Arc<Listeners>, resetMain: FlowBox| {
 | 
			
		||||
        listeners.stop_network_listener();
 | 
			
		||||
        listeners.stop_audio_listener();
 | 
			
		||||
        let bluetooth_box = Arc::new(BluetoothBox::new());
 | 
			
		||||
        let bluetooth_box = BluetoothBox::new(listeners.clone());
 | 
			
		||||
        start_bluetooth_listener(listeners.clone(), bluetooth_box.clone());
 | 
			
		||||
        populate_conntected_bluetooth_devices(bluetooth_box.clone());
 | 
			
		||||
        let bluetoothFrame = wrapInFrame(SettingBox::new(&*bluetooth_box));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue