network: do not close the psk entry if the password is invalid
also not it differentiates invalid property from other errors
This commit is contained in:
parent
36b6ce3092
commit
b9f51d39db
@ -15,6 +15,7 @@ from sdbus_block.networkmanager import (
|
||||
IPv4Config,
|
||||
ActiveConnection,
|
||||
enums,
|
||||
exceptions,
|
||||
)
|
||||
from sdbus import sd_bus_open_system, set_default_bus
|
||||
from gi.repository import GLib
|
||||
@ -81,9 +82,6 @@ class SdbusNm:
|
||||
self.system_bus = sd_bus_open_system() # We need system bus
|
||||
set_default_bus(self.system_bus)
|
||||
self.nm = NetworkManager()
|
||||
self._callbacks = {
|
||||
"popup": [],
|
||||
}
|
||||
if self.get_wireless_interfaces():
|
||||
self.wlan_device = self.get_wireless_interfaces()[0]
|
||||
self.wifi = True
|
||||
@ -177,8 +175,7 @@ class SdbusNm:
|
||||
return self.get_connected_ap().hw_address if self.get_connected_ap() is not None else None
|
||||
|
||||
def add_network(self, ssid, psk):
|
||||
existing_network = NetworkManagerSettings().get_connections_by_id(ssid)
|
||||
if existing_network:
|
||||
if existing_network := NetworkManagerSettings().get_connections_by_id(ssid):
|
||||
for network in existing_network:
|
||||
self.delete_connection_path(network)
|
||||
|
||||
@ -204,14 +201,14 @@ class SdbusNm:
|
||||
}
|
||||
|
||||
try:
|
||||
msg = f"{ssid}\n" + _("Starting WiFi Association")
|
||||
self.callback("popup", msg, 1)
|
||||
NetworkManagerSettings().add_connection(properties)
|
||||
return True
|
||||
return {"status": "success"}
|
||||
except exceptions.NmConnectionInvalidPropertyError:
|
||||
logging.exception("Invalid property")
|
||||
return {"error": "psk_invalid", "message": _("Invalid password")}
|
||||
except Exception as e:
|
||||
logging.error(f"{e}")
|
||||
self.callback("popup", f"Error: {e}")
|
||||
return False
|
||||
logging.exception("Couldn't add network")
|
||||
return {"error": "unknown", "message": _("Couldn't add network") + f"\n{e}"}
|
||||
|
||||
def disconnect_network(self):
|
||||
self.wlan_device.disconnect()
|
||||
@ -230,21 +227,9 @@ class SdbusNm:
|
||||
|
||||
def connect(self, ssid):
|
||||
connection = NetworkManagerSettings().get_connections_by_id(ssid)
|
||||
if not connection:
|
||||
self.callback("popup", f"{ssid} {connection}")
|
||||
return
|
||||
msg = f"{ssid}:\n" + _("Starting WiFi Association")
|
||||
self.callback("popup", msg, 1)
|
||||
self.nm.activate_connection(connection[0])
|
||||
|
||||
def add_callback(self, name, callback):
|
||||
if name in self._callbacks and callback not in self._callbacks[name]:
|
||||
self._callbacks[name].append(callback)
|
||||
|
||||
def callback(self, cb_type, *args):
|
||||
if cb_type in self._callbacks:
|
||||
for cb in self._callbacks[cb_type]:
|
||||
GLib.idle_add(cb, *args)
|
||||
if connection:
|
||||
self.nm.activate_connection(connection[0])
|
||||
return connection
|
||||
|
||||
def toggle_wifi(self, enable):
|
||||
self.nm.wireless_enabled = enable
|
||||
|
@ -66,8 +66,6 @@ class Panel(ScreenPanel):
|
||||
self.labels['main_box'].pack_start(sbox, False, False, 5)
|
||||
GLib.idle_add(self.load_networks)
|
||||
scroll.add(self.network_list)
|
||||
|
||||
self.sdbus_nm.add_callback("popup", self.popup_callback)
|
||||
else:
|
||||
self._screen.show_popup_message(_("No wireless interface has been found"), level=2)
|
||||
self.labels['networkinfo'] = Gtk.Label()
|
||||
@ -89,7 +87,6 @@ class Panel(ScreenPanel):
|
||||
|
||||
def add_network(self, bssid):
|
||||
if bssid in self.network_rows:
|
||||
logging.info(f"{bssid} already in list")
|
||||
return
|
||||
|
||||
net = next(net for net in self.sdbus_nm.get_networks() if bssid == net['BSSID'])
|
||||
@ -169,11 +166,13 @@ class Panel(ScreenPanel):
|
||||
def add_new_network(self, widget, ssid):
|
||||
self._screen.remove_keyboard()
|
||||
result = self.sdbus_nm.add_network(ssid, self.labels['network_psk'].get_text())
|
||||
self.close_add_network()
|
||||
if result:
|
||||
self.connect_network(widget, ssid, showadd=False)
|
||||
if "error" in result:
|
||||
self._screen.show_popup_message(result["message"])
|
||||
if result["error"] == "psk_invalid":
|
||||
return
|
||||
else:
|
||||
self._screen.show_popup_message(_("Invalid password"))
|
||||
self.connect_network(widget, ssid, showadd=False)
|
||||
self.close_add_network()
|
||||
|
||||
def back(self):
|
||||
if self.show_add:
|
||||
@ -203,7 +202,10 @@ class Panel(ScreenPanel):
|
||||
bssid = self.sdbus_nm.get_bssid_from_ssid(ssid)
|
||||
if bssid and bssid in self.network_rows:
|
||||
self.remove_network_from_list(bssid)
|
||||
self.sdbus_nm.connect(ssid)
|
||||
msg = f"{ssid}\n" + _("Starting WiFi Association")
|
||||
self._screen.show_popup_message(msg, 1)
|
||||
result = self.sdbus_nm.connect(ssid)
|
||||
logging.debug(result)
|
||||
self.update_all_networks()
|
||||
self.activate()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user