Merge ~nteodosio/software-properties:valid-magic-wait-event into software-properties:ubuntu/master

Proposed by Nathan Teodosio
Status: Superseded
Proposed branch: ~nteodosio/software-properties:valid-magic-wait-event
Merge into: software-properties:ubuntu/master
Diff against target: 43 lines (+9/-0)
1 file modified
softwareproperties/gtk/DialogUaAttach.py (+9/-0)
Reviewer Review Type Date Requested Status
Sebastien Bacher Needs Information
Review via email: mp+438313@code.launchpad.net

This proposal supersedes a proposal from 2023-02-10.

This proposal has been superseded by a proposal from 2023-03-06.

Description of the change

This is an alternative to the superseded request.

Instead of sleeping, use Event to detect when the radio button is changed.

To post a comment you must log in.
Revision history for this message
Sebastien Bacher (seb128) wrote :

Thanks, that should work but is there any reason we keep pooling for tokens when the option is not selected? Also wouldn't it be simpler to make the status update conditional to the selected widget option rather than using events?

review: Needs Information
Revision history for this message
Nathan Teodosio (nteodosio) wrote :

> is there any reason we keep pooling for tokens when the option is not selected?

Since wait() blocks, interrupting that thread when the user selects the other radio button is a bit involved, as far as I know. But I'll investigate this option further.

> wouldn't it be simpler to make the status update conditional to the selected widget option rather than using events?

Do you mean something like: Once wait() returns,

- If magic button selected, call update_state as we do now.
- If token button selected, set a flag, and make on_radio_toggled consider that flag and call update_state if set.

? That seems good.

Revision history for this message
Sebastien Bacher (seb128) wrote :

> Since wait() blocks, interrupting that thread when the user selects the other radio button is a bit involved, as far as I know. But I'll investigate this option further.

right, that might be annoying, don't worry about it if we can go with the other option

> Do you mean something like: Once wait() returns,

> - If magic button selected, call update_state as we do now.
> - If token button selected, set a flag, and make on_radio_toggled consider that flag and call update_state if set.

> ? That seems good.

yes, something around those lines

Unmerged commits

7298048... by Nathan Teodosio

Make PIN validation wait to update UI until magic radio is selected.

https://launchpad.net/bugs/2006940

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/softwareproperties/gtk/DialogUaAttach.py b/softwareproperties/gtk/DialogUaAttach.py
2index 5de167c..175173f 100644
3--- a/softwareproperties/gtk/DialogUaAttach.py
4+++ b/softwareproperties/gtk/DialogUaAttach.py
5@@ -25,6 +25,7 @@ from softwareproperties.gtk.utils import setup_ui
6 from uaclient.api.u.pro.attach.magic.initiate.v1 import initiate
7 from uaclient.api.u.pro.attach.magic.wait.v1 import MagicAttachWaitOptions, wait
8 from uaclient.exceptions import MagicAttachTokenError
9+from threading import Event
10
11 class DialogUaAttach:
12 def __init__(self, parent, datadir, ua_object):
13@@ -39,6 +40,8 @@ class DialogUaAttach:
14 self.attaching = False
15 self.poll = None
16 self.pin = ""
17+ self.magic_radio_active_event = Event()
18+ self.magic_radio_active_event.set()
19
20 self.net_monitor = Gio.network_monitor_get_default()
21 self.net_monitor.connect("network-changed", self.net_status_changed, 0)
22@@ -148,8 +151,10 @@ class DialogUaAttach:
23 try:
24 response = wait(options)
25 self.contract_token = response.contract_token
26+ self.magic_radio_active_event.wait()
27 GLib.idle_add(self.update_state, 'pin_validated')
28 except MagicAttachTokenError:
29+ self.magic_radio_active_event.wait()
30 GLib.idle_add(self.update_state, 'expired')
31 except Exception as e:
32 print("Error getting the Ubuntu Pro token: ", e, flush = True)
33@@ -177,6 +182,10 @@ class DialogUaAttach:
34 self.poll = GLib.Thread.new("poll", self.poll_for_magic_token)
35
36 def on_radio_toggled(self, button):
37+ if self.token_radio.get_active():
38+ self.magic_radio_active_event.clear()
39+ else:
40+ self.magic_radio_active_event.set()
41 self.update_state()
42
43 def on_magic_radio_clicked(self, button):

Subscribers

People subscribed via source and target branches