Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [close #223] Make wifi refresh thread-safe #224

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions vanilla_first_setup/defaults/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def __init__(self, window, distro_info, key, step, **kwargs):
# there's a high change that it coincides with a periodic
# refresh operation.
self.__wifi_lock = Lock()
self.__scan_lock = Lock()

# Since we have a dedicated page for checking connectivity,
# we only need to make sure the user has some type of
Expand Down Expand Up @@ -351,7 +352,7 @@ def __refresh(self):
device_type = device.get_device_type()
if device_type == NM.DeviceType.ETHERNET:
self.__add_ethernet_connection(device)
if device_type == NM.DeviceType.WIFI:
elif device_type == NM.DeviceType.WIFI:
self.__scan_wifi(device)

self.set_btn_next(self.has_eth_connection or self.has_wifi_connection)
Expand Down Expand Up @@ -412,10 +413,15 @@ def __add_ethernet_connection(self, conn: NM.DeviceEthernet):
self.wired_group.add(eth_conn)
self.__wired_children.append(eth_conn)

def __refresh_wifi_list(self, conn: NM.DeviceWifi):
def __poll_wifi_scan(self, conn: NM.DeviceWifi):
self.__scan_lock.acquire()
while conn.get_last_scan() == self.__last_wifi_scan:
time.sleep(0.25)
self.__scan_lock.release()

GLib.idle_add(self.__refresh_wifi_list, conn)

def __refresh_wifi_list(self, conn: NM.DeviceWifi):
networks = {}
for ap in conn.get_access_points():
ssid = ap.get_ssid()
Expand Down Expand Up @@ -472,10 +478,12 @@ def __refresh_wifi_list(self, conn: NM.DeviceWifi):
self.__wifi_lock.release()

def __scan_wifi(self, conn: NM.DeviceWifi):
self.__scan_lock.acquire()
self.__last_wifi_scan = conn.get_last_scan()
self.__scan_lock.release()
conn.request_scan_async()

t = Timer(1.5, self.__refresh_wifi_list, [conn])
t = Timer(1.5, self.__poll_wifi_scan, [conn])
t.start()

@property
Expand All @@ -492,3 +500,4 @@ def multisort(xs, specs):
[it[0] for it in list(self.__wireless_children.values())],
(("connected", True), ("signal_strength", True), ("ssid", True)),
)