network: changes to monitoring
This commit is contained in:
parent
1e944726ce
commit
d9eeec3cba
@ -21,7 +21,6 @@ from sdbus import sd_bus_open_system, set_default_bus
|
|||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
|
|
||||||
NM_802_11_AP_SEC_NONE = 0
|
NM_802_11_AP_SEC_NONE = 0
|
||||||
NM_802_11_AP_SEC_PAIR_WEP40 = 1
|
NM_802_11_AP_SEC_PAIR_WEP40 = 1
|
||||||
NM_802_11_AP_SEC_PAIR_WEP104 = 2
|
NM_802_11_AP_SEC_PAIR_WEP104 = 2
|
||||||
@ -93,6 +92,8 @@ class SdbusNm:
|
|||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
self.wifi = self.wlan_device is not None
|
self.wifi = self.wlan_device is not None
|
||||||
|
self.monitor_connection = False
|
||||||
|
self.wifi_state = -1
|
||||||
self.popup = popup_callback
|
self.popup = popup_callback
|
||||||
|
|
||||||
def ensure_nm_running(self):
|
def ensure_nm_running(self):
|
||||||
@ -325,9 +326,7 @@ class SdbusNm:
|
|||||||
if target_connection := self.get_connection_path_by_ssid(ssid):
|
if target_connection := self.get_connection_path_by_ssid(ssid):
|
||||||
self.popup(f"{ssid}\n{_('Starting WiFi Association')}", 1)
|
self.popup(f"{ssid}\n{_('Starting WiFi Association')}", 1)
|
||||||
try:
|
try:
|
||||||
self.wlan_device.disconnect()
|
|
||||||
active_connection = self.nm.activate_connection(target_connection)
|
active_connection = self.nm.activate_connection(target_connection)
|
||||||
self.monitor_connection_status(active_connection)
|
|
||||||
return target_connection
|
return target_connection
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception("Unexpected error")
|
logging.exception("Unexpected error")
|
||||||
@ -338,16 +337,36 @@ class SdbusNm:
|
|||||||
def toggle_wifi(self, enable):
|
def toggle_wifi(self, enable):
|
||||||
self.nm.wireless_enabled = enable
|
self.nm.wireless_enabled = enable
|
||||||
|
|
||||||
def monitor_connection_status(self, active_connection):
|
def monitor_connection_status(self):
|
||||||
def on_state_changed(active_conn_path, state, reason):
|
state = self.wlan_device.state
|
||||||
if active_conn_path == active_connection:
|
if self.wifi_state != state:
|
||||||
if state == enums.NM_ACTIVE_CONNECTION_STATE_ACTIVATED:
|
logging.debug(f"State changed: {state} {self.wlan_device.state_reason}")
|
||||||
self.popup(_("Connection established successfully"))
|
if self.wifi_state == -1:
|
||||||
elif state in [
|
logging.debug("Starting to monitor state")
|
||||||
enums.NM_ACTIVE_CONNECTION_STATE_DEACTIVATING,
|
elif state in [
|
||||||
enums.NM_ACTIVE_CONNECTION_STATE_DEACTIVATED
|
enums.DeviceState.PREPARE,
|
||||||
]:
|
enums.DeviceState.CONFIG,
|
||||||
self.popup(_("Connection disconnected"))
|
]:
|
||||||
elif state == enums.NM_ACTIVE_CONNECTION_STATE_FAILED:
|
self.popup(_("Connecting"), 1)
|
||||||
self.popup(_("Connection failed"))
|
elif state in [
|
||||||
|
enums.DeviceState.IP_CONFIG,
|
||||||
|
enums.DeviceState.IP_CHECK,
|
||||||
|
enums.DeviceState.SECONDARIES,
|
||||||
|
]:
|
||||||
|
self.popup(_("Getting IP address"), 1)
|
||||||
|
elif state in [
|
||||||
|
enums.DeviceState.ACTIVATED,
|
||||||
|
]:
|
||||||
|
self.popup(_("Connection established successfully"), 1)
|
||||||
|
elif state in [
|
||||||
|
enums.DeviceState.DISCONNECTED,
|
||||||
|
enums.DeviceState.DEACTIVATING,
|
||||||
|
]:
|
||||||
|
self.popup(_("Connection disconnected"))
|
||||||
|
elif state == enums.DeviceState.FAILED:
|
||||||
|
self.popup(_("Connection failed"))
|
||||||
|
self.wifi_state = state
|
||||||
|
return self.monitor_connection
|
||||||
|
|
||||||
|
def enable_monitoring(self, enable):
|
||||||
|
self.monitor_connection = enable
|
||||||
|
@ -79,6 +79,8 @@ class Panel(ScreenPanel):
|
|||||||
self.labels['main_box'].pack_start(sbox, False, False, 5)
|
self.labels['main_box'].pack_start(sbox, False, False, 5)
|
||||||
GLib.idle_add(self.load_networks)
|
GLib.idle_add(self.load_networks)
|
||||||
scroll.add(self.network_list)
|
scroll.add(self.network_list)
|
||||||
|
self.sdbus_nm.enable_monitoring(True)
|
||||||
|
self.conn_status = GLib.timeout_add_seconds(1, self.sdbus_nm.monitor_connection_status)
|
||||||
else:
|
else:
|
||||||
self._screen.show_popup_message(_("No wireless interface has been found"), level=2)
|
self._screen.show_popup_message(_("No wireless interface has been found"), level=2)
|
||||||
self.labels['networkinfo'] = Gtk.Label()
|
self.labels['networkinfo'] = Gtk.Label()
|
||||||
@ -355,6 +357,8 @@ class Panel(ScreenPanel):
|
|||||||
if self.update_timeout is not None:
|
if self.update_timeout is not None:
|
||||||
GLib.source_remove(self.update_timeout)
|
GLib.source_remove(self.update_timeout)
|
||||||
self.update_timeout = None
|
self.update_timeout = None
|
||||||
|
if self.sdbus_nm.wifi:
|
||||||
|
self.sdbus_nm.enable_monitoring(False)
|
||||||
|
|
||||||
def toggle_wifi(self, switch, gparams):
|
def toggle_wifi(self, switch, gparams):
|
||||||
enable = switch.get_active()
|
enable = switch.get_active()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user