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

Proposed by Nathan Teodosio
Status: Merged
Approved by: Sebastien Bacher
Approved revision: 8a2567c2311be1c32a81ea2c85ed6972ef9d454a
Merged at revision: 8a2567c2311be1c32a81ea2c85ed6972ef9d454a
Proposed branch: ~nteodosio/software-properties:valid-magic-wait-contract
Merge into: software-properties:ubuntu/master
Diff against target: 51 lines (+8/-6)
2 files modified
data/gtkbuilder/dialog-ua-attach.ui (+0/-1)
softwareproperties/gtk/DialogUaAttach.py (+8/-5)
Reviewer Review Type Date Requested Status
Sebastien Bacher Approve
Review via email: mp+438394@code.launchpad.net

This proposal supersedes a proposal from 2023-03-03.

Description of the change

This is an alternative to the superseded request.

We already have contract_token to mean "user validated PIN", so simply use it.

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

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 : Posted in a previous version of this proposal

> 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 : Posted in a previous version of this proposal

> 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

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

Thanks, seems easier and should do the job!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/data/gtkbuilder/dialog-ua-attach.ui b/data/gtkbuilder/dialog-ua-attach.ui
2index 6e255a8..1445b82 100644
3--- a/data/gtkbuilder/dialog-ua-attach.ui
4+++ b/data/gtkbuilder/dialog-ua-attach.ui
5@@ -39,7 +39,6 @@
6 <property name="margin-top">30</property>
7 <property name="xalign">0</property>
8 <property name="group">magic_radio</property>
9- <signal name="toggled" handler="on_radio_toggled" swapped="no"/>
10 <signal name="clicked" handler="on_magic_radio_clicked" swapped="no"/>
11 </object>
12 </child>
13diff --git a/softwareproperties/gtk/DialogUaAttach.py b/softwareproperties/gtk/DialogUaAttach.py
14index 5de167c..d029e64 100644
15--- a/softwareproperties/gtk/DialogUaAttach.py
16+++ b/softwareproperties/gtk/DialogUaAttach.py
17@@ -148,9 +148,11 @@ class DialogUaAttach:
18 try:
19 response = wait(options)
20 self.contract_token = response.contract_token
21- GLib.idle_add(self.update_state, 'pin_validated')
22+ if self.magic_radio.get_active():
23+ GLib.idle_add(self.update_state, "pin_validated")
24 except MagicAttachTokenError:
25- GLib.idle_add(self.update_state, 'expired')
26+ if self.magic_radio.get_active():
27+ GLib.idle_add(self.update_state, "expired")
28 except Exception as e:
29 print("Error getting the Ubuntu Pro token: ", e, flush = True)
30 finally:
31@@ -161,8 +163,6 @@ class DialogUaAttach:
32 if self.poll != None or self.contract_token != None:
33 return
34
35- self.contract_token = None
36-
37 # Request a magic attachment and parse relevants fields from response.
38 # userCode: The pin the user has to type in <ubuntu.com/pro/attach>;
39 # token: Identifies the request (used for polling for it).
40@@ -177,7 +177,10 @@ class DialogUaAttach:
41 self.poll = GLib.Thread.new("poll", self.poll_for_magic_token)
42
43 def on_radio_toggled(self, button):
44- self.update_state()
45+ if self.magic_radio.get_active() and self.contract_token:
46+ self.update_state("pin_validated")
47+ else:
48+ self.update_state()
49
50 def on_magic_radio_clicked(self, button):
51 self.start_magic_attach()

Subscribers

People subscribed via source and target branches