✨ feat(controlcenter): integrate network and bluetooth indicators with control center

This commit is contained in:
sankalp committed 2025-08-05 08:57:44 +05:45
1 parent 6530df911e
commit 25d12a838b
6 files changed
+732 -1016

No files matched your search

+12 -7
View File
@@ -54,7 +54,7 @@ class BluetoothDeviceSlot(CenterBox):
class BluetoothConnections(Box):
def __init__(self, parent, show_hidden_devices: bool = False, **kwargs):
def __init__(self, parent, show_hidden_devices: bool = False, show_back_button=True, **kwargs):
super().__init__(
spacing=4,
orientation="vertical",
@@ -67,15 +67,20 @@ class BluetoothConnections(Box):
self.client = BluetoothClient(on_device_added=self.on_device_added)
self.title = Box(
orientation="h",
children=[
# Create title with optional back button
title_children = []
if show_back_button:
title_children.append(
Button(
image=Image(icon_name="back", size=10),
on_clicked=lambda *_: self.parent.close_bluetooth(),
),
Label("Bluetooth"),
],
)
)
title_children.append(Label("Bluetooth"))
self.title = Box(
orientation="h",
children=title_children,
)
self.toggle_button = Gtk.Switch(visible=True, name="toggle-button")
+1
View File
@@ -104,6 +104,7 @@ class ModusControlCenter(Window):
# Disable brightness scale if no backlight device available
self.brightness_scale.set_sensitive(False)
# Create music widget with ultra-lazy player container
self.music_widget = Box(
name="music-widget",
children=[PlayerBoxStack(MprisPlayerManager())],
+76 -129
View File
@@ -6,31 +6,25 @@ from fabric.widgets.centerbox import CenterBox
from fabric.widgets.image import Image
from fabric.widgets.label import Label
from fabric.widgets.scrolledwindow import ScrolledWindow
from services.network import NetworkService
from services.network import NetworkClient
from widgets.wifi_password_dialog import WiFiPasswordDialog
class WifiNetworkSlot(CenterBox):
def __init__(self, network_data: dict, wifi_service, parent=None, **kwargs):
def __init__(self, access_point, wifi_service, parent=None, **kwargs):
super().__init__(**kwargs)
self.network_data = network_data
self.access_point = access_point
self.wifi_service = wifi_service
self.parent = parent # Reference to control center
# Get network info
self.ssid = network_data.get("ssid", "Unknown")
self.bssid = network_data.get("bssid", "")
self.strength = network_data.get("strength", 0)
self.icon_name = network_data.get(
"icon-name", "network-wireless-signal-none-symbolic"
)
# Get network info from AccessPoint object
self.ssid = access_point.ssid
self.bssid = access_point.bssid
self.strength = access_point.strength
self.icon_name = access_point.icon
# The network service puts the same active-ap reference in all networks
# We need to check if THIS specific network's BSSID matches the active AP's BSSID
self.is_connected = False
if self.wifi_service and self.wifi_service._ap:
active_bssid = self.wifi_service._ap.get_bssid()
self.is_connected = active_bssid == self.bssid
# Check if this network is currently connected
self.is_connected = access_point.is_active
# Initialize styles based on connection state
self.styles = [
@@ -61,11 +55,8 @@ class WifiNetworkSlot(CenterBox):
def toggle_connecting(self):
"""Toggle WiFi network connection"""
# Check if this network is currently connected by comparing BSSIDs
is_currently_connected = False
if self.wifi_service and self.wifi_service._ap:
active_bssid = self.wifi_service._ap.get_bssid()
is_currently_connected = active_bssid == self.bssid
# Check if this network is currently connected
is_currently_connected = self.access_point.is_active
if is_currently_connected:
# Show disconnecting state
@@ -73,32 +64,34 @@ class WifiNetworkSlot(CenterBox):
self.dimage.add_style_class("disconnecting")
# Disconnect from network
success = self.wifi_service.disconnect_network(self.ssid)
if success:
self.is_connected = False
# Remove disconnecting state after a short delay to show feedback
from gi.repository import GLib
self.wifi_service.disconnect_wifi()
self.is_connected = False
# Remove disconnecting state after a short delay to show feedback
from gi.repository import GLib
GLib.timeout_add(500, lambda: self._reset_disconnect_state())
else:
# Reset state if disconnect failed
self._reset_disconnect_state()
GLib.timeout_add(500, lambda: self._reset_disconnect_state())
else:
# Try to connect without password first (for open networks or saved connections)
self.dimage.set_property("icon-name", "network-wireless-acquiring-symbolic")
self.dimage.add_style_class("connecting")
success = self.wifi_service.connect_network(self.ssid)
if success:
self.is_connected = True
# Remove connecting state after a short delay
from gi.repository import GLib
GLib.timeout_add(500, lambda: self._reset_connect_state())
else:
# Connection failed, likely needs password - show password dialog
self._reset_connect_state()
# Try to connect - check if password is required
if self.access_point.requires_password:
# Show password dialog immediately
self._show_password_dialog()
else:
# Try to connect without password (for open networks)
self.dimage.set_property(
"icon-name", "network-wireless-acquiring-symbolic"
)
self.dimage.add_style_class("connecting")
success = self.wifi_service.connect_to_wifi(self.access_point)
if success:
self.is_connected = True
# Remove connecting state after a short delay
from gi.repository import GLib
GLib.timeout_add(500, lambda: self._reset_connect_state())
else:
# Connection failed
self._reset_connect_state()
# Update display after connection attempt
self.on_changed()
@@ -119,19 +112,8 @@ class WifiNetworkSlot(CenterBox):
def on_changed(self, *_):
"""Update display when connection state changes"""
# Check if this network is currently connected by comparing BSSIDs
is_currently_connected = False
if self.wifi_service and self.wifi_service._ap:
# Also check the internet connection state to ensure we're actually connected
internet_state = self.wifi_service.internet
if internet_state == "activated":
active_bssid = self.wifi_service._ap.get_bssid()
is_currently_connected = active_bssid == self.bssid
# If deactivating or deactivated, definitely not connected
elif internet_state in ["deactivating", "deactivated", "disconnected"]:
is_currently_connected = False
self.is_connected = is_currently_connected
# Check if this network is currently connected using the access point's is_active property
self.is_connected = self.access_point.is_active
self.styles = [
"connected" if self.is_connected else "",
]
@@ -165,7 +147,7 @@ class WifiNetworkSlot(CenterBox):
# Try to connect with password
try:
success = self.wifi_service.connect_network(ssid, password)
success = self.wifi_service.connect_to_wifi(self.access_point, password)
if success:
self.is_connected = True
# Remove connecting state after a short delay
@@ -201,7 +183,7 @@ class WifiNetworkSlot(CenterBox):
class WifiConnections(Box):
def __init__(self, parent, **kwargs):
def __init__(self, parent, show_back_button=True, **kwargs):
super().__init__(
spacing=4,
orientation="vertical",
@@ -210,12 +192,12 @@ class WifiConnections(Box):
)
self.parent = parent
self.network_service = NetworkService()
self.network_service = NetworkClient()
self.wifi_service = None
self.is_scanning = False # Track scanning state
# Wait for network service to be ready
self.network_service.connect("device-ready", self.on_network_ready)
self.network_service.connect("wifi-device-added", self.on_network_ready)
# Create pull-to-refresh indicator
self.refresh_indicator = Label(
@@ -226,15 +208,20 @@ class WifiConnections(Box):
style="color: #fff; font-size: 12px; padding: 5px;",
)
self.title = Box(
orientation="h",
children=[
# Create title with optional back button
title_children = []
if show_back_button:
title_children.append(
Button(
image=Image(icon_name="back", size=10),
on_clicked=lambda *_: self.parent.close_wifi(),
),
Label("WiFi"),
],
)
)
title_children.append(Label("WiFi"))
self.title = Box(
orientation="h",
children=title_children,
)
self.toggle_button = Gtk.Switch(visible=True, name="toggle-button")
@@ -276,43 +263,31 @@ class WifiConnections(Box):
self.wifi_service = self.network_service.wifi_device
if self.wifi_service:
# Set up WiFi toggle
self.toggle_button.set_active(self.wifi_service.enabled)
self.toggle_button.set_active(self.wifi_service.wireless_enabled)
self.toggle_button.connect(
"notify::active",
lambda *_: setattr(
self.wifi_service, "enabled", self.toggle_button.get_active()
self.wifi_service,
"wireless_enabled",
self.toggle_button.get_active(),
),
)
# Connect to WiFi service signals
self.wifi_service.connect("notify::enabled", self.on_wifi_enabled_changed)
self.wifi_service.connect("notify::scanning", self.on_scanning_changed)
self.wifi_service.connect("changed", self.update_networks)
# Also connect to access point changes to update connection states
self.wifi_service.connect(
"notify::access-points", self.refresh_network_states
"notify::wireless-enabled", self.on_wifi_enabled_changed
)
# Connect to internet state changes to handle disconnections
self.wifi_service.connect("notify::internet", self.refresh_network_states)
self.wifi_service.connect("notify::ssid", self.refresh_network_states)
self.wifi_service.connect("changed", self.update_networks)
self.wifi_service.connect("ap-added", self.update_networks)
self.wifi_service.connect("ap-removed", self.update_networks)
# Initial network update
self.update_networks()
# Initialize scanning state
self.wifi_service.notify("scanning")
def on_wifi_enabled_changed(self, *_):
"""Handle WiFi enabled state changes"""
if self.wifi_service:
self.toggle_button.set_active(self.wifi_service.enabled)
def on_scanning_changed(self, *_):
"""Handle scanning state changes"""
if self.wifi_service:
is_scanning = self.wifi_service.scanning
self.is_scanning = is_scanning # Update our tracking state
self.update_scan_label()
self.toggle_button.set_active(self.wifi_service.wireless_enabled)
def update_networks(self, *_):
"""Update the list of available networks"""
@@ -325,10 +300,10 @@ class WifiConnections(Box):
# Add current networks
access_points = self.wifi_service.access_points
for ap_data in access_points:
if ap_data.get("ssid") and ap_data.get("ssid") != "Unknown":
for access_point in access_points:
if access_point.ssid and access_point.ssid != "Unknown":
network_slot = WifiNetworkSlot(
ap_data, self.wifi_service, parent=self.parent
access_point, self.wifi_service, parent=self.parent
)
self.available_networks.add(network_slot)
@@ -377,8 +352,8 @@ class WifiConnections(Box):
# Only handle pull-to-refresh when at the top
if self.vadjustment.get_value() <= 0:
if event.direction == Gdk.ScrollDirection.UP:
# Scrolling up at the top - start scan (only if not already scanning)
if self.wifi_service and not self.is_scanning:
# Scrolling up at the top - start scan
if self.wifi_service:
self.wifi_service.scan()
# Trigger smooth bounce animation for scroll
self.start_bounce_animation()
@@ -397,8 +372,8 @@ class WifiConnections(Box):
if self.is_pulling:
pull_distance = event.y - self.pull_start_y
if pull_distance > self.pull_threshold:
# Start scan (only if not already scanning)
if self.wifi_service and not self.is_scanning:
# Start scan
if self.wifi_service:
self.wifi_service.scan()
# Trigger elastic animation for pull gesture (most satisfying)
self.start_elastic_animation()
@@ -419,36 +394,15 @@ class WifiConnections(Box):
# Show refresh indicator when pulling down
self.refresh_indicator.set_visible(True)
if pull_distance >= self.pull_threshold:
if self.is_scanning:
self.refresh_indicator.set_label("↑ Already scanning...")
else:
self.refresh_indicator.set_label("↑ Release to scan")
self.refresh_indicator.set_label("↑ Release to scan")
self.refresh_indicator.add_style_class("ready-to-refresh")
else:
if self.is_scanning:
self.refresh_indicator.set_label("↓ Scanning in progress...")
else:
self.refresh_indicator.set_label("↓ Pull to scan for networks")
self.refresh_indicator.set_label("↓ Pull to scan for networks")
self.refresh_indicator.remove_style_class("ready-to-refresh")
else:
self.refresh_indicator.set_visible(False)
return False
def update_scan_label(self):
"""Update scanning state appearance"""
if self.wifi_service and self.wifi_service.scanning:
# Show scanning feedback in refresh indicator
self.refresh_indicator.set_label("Scanning for networks...")
self.refresh_indicator.set_visible(True)
self.refresh_indicator.add_style_class("scanning")
self.refresh_indicator.show_all()
else:
# Hide scanning feedback only if not animating and not pulling
if not self.is_pulling and not self.bounce_timeout_id:
self.refresh_indicator.set_visible(False)
self.refresh_indicator.remove_style_class("scanning")
def ease_out_bounce(self, t):
"""Smooth bounce easing function (0 to 1)"""
if t < 1 / 2.75:
@@ -489,11 +443,8 @@ class WifiConnections(Box):
# Animation finished
self.refresh_indicator.set_margin_top(0)
self.bounce_timeout_id = None
# Hide indicator after animation if not scanning and not pulling
if (
not (self.wifi_service and self.wifi_service.scanning)
and not self.is_pulling
):
# Hide indicator after animation if not pulling
if not self.is_pulling:
self.refresh_indicator.set_visible(False)
return False
@@ -527,11 +478,8 @@ class WifiConnections(Box):
# Animation finished
self.refresh_indicator.set_margin_top(0)
self.bounce_timeout_id = None
# Hide indicator after animation if not scanning and not pulling
if (
not (self.wifi_service and self.wifi_service.scanning)
and not self.is_pulling
):
# Hide indicator after animation if not pulling
if not self.is_pulling:
self.refresh_indicator.set_visible(False)
return False
@@ -558,4 +506,3 @@ class WifiConnections(Box):
def on_destroy(self, widget):
"""Cleanup animations when widget is destroyed"""
self.stop_bounce_animation()