diff -Nru software-properties-0.96.24.32.20/data/gtkbuilder/dialog-ua-attach.ui software-properties-0.96.24.32.22/data/gtkbuilder/dialog-ua-attach.ui --- software-properties-0.96.24.32.20/data/gtkbuilder/dialog-ua-attach.ui 2023-01-25 17:50:56.000000000 +0000 +++ software-properties-0.96.24.32.22/data/gtkbuilder/dialog-ua-attach.ui 2023-02-16 20:10:38.000000000 +0000 @@ -26,6 +26,10 @@ 130 + + + True + vertical Enter code on ubuntu.com/pro/attach @@ -170,6 +174,30 @@ From your admin, or from <a href="https://ubuntu.com/pro">ubuntu.com/pro</a> + + + + + False + 5 + 18 + 18 + + + True + 5 + gtk-dialog-warning + + + + + True + True + Unable to connect to Ubuntu Pro servers. Check your internet connection. + + + + True @@ -184,6 +212,9 @@ + + True + True Confirm @@ -191,6 +222,8 @@ + + diff -Nru software-properties-0.96.24.32.20/debian/changelog software-properties-0.96.24.32.22/debian/changelog --- software-properties-0.96.24.32.20/debian/changelog 2023-01-25 17:50:56.000000000 +0000 +++ software-properties-0.96.24.32.22/debian/changelog 2023-02-16 20:10:38.000000000 +0000 @@ -1,3 +1,20 @@ +software-properties (0.96.24.32.22) bionic; urgency=medium + + [ Nathan Pratta Teodosio ] + * fix a problem in the fix backported in the previous revision + + -- Sebastien Bacher Thu, 16 Feb 2023 21:10:38 +0100 + +software-properties (0.96.24.32.21) bionic; urgency=medium + + [ Nathan Pratta Teodosio ] + * Disable the Ubuntu Pro UI with an explanation when not connected + (lp: #2004634) + * Catch exceptions to wait (lp: #2003996) + * Initialize pin as empty string (lp: #2004245) + + -- Sebastien Bacher Fri, 03 Feb 2023 12:31:57 +0100 + software-properties (0.96.24.32.20) bionic; urgency=medium * softwareproperties/gtk/DialogUaAttach.py: fix an incomplete backport diff -Nru software-properties-0.96.24.32.20/softwareproperties/gtk/DialogUaAttach.py software-properties-0.96.24.32.22/softwareproperties/gtk/DialogUaAttach.py --- software-properties-0.96.24.32.20/softwareproperties/gtk/DialogUaAttach.py 2023-01-25 17:50:56.000000000 +0000 +++ software-properties-0.96.24.32.22/softwareproperties/gtk/DialogUaAttach.py 2023-02-16 20:10:38.000000000 +0000 @@ -20,7 +20,7 @@ from gettext import gettext as _ import gi gi.require_version("Gtk", "3.0") -from gi.repository import Gtk,GLib +from gi.repository import Gtk,GLib,Gio from softwareproperties.gtk.utils import setup_ui from uaclient.api.u.pro.attach.magic.initiate.v1 import initiate from uaclient.api.u.pro.attach.magic.wait.v1 import MagicAttachWaitOptions, wait @@ -39,8 +39,13 @@ self.contract_token = None self.attaching = False self.poll = None + self.pin = "" - self.start_magic_attach() + self.net_monitor = Gio.network_monitor_get_default() + self.net_monitor.connect("network-changed", self.net_status_changed, 0) + self.net_status_changed( + self.net_monitor, self.net_monitor.get_network_available(), 1 + ) def run(self): self.dialog.run() @@ -145,6 +150,8 @@ GLib.idle_add(self.update_state, 'pin_validated') except MagicAttachTokenError: GLib.idle_add(self.update_state, 'expired') + except Exception as e: + print("Error getting the Ubuntu Pro token: ", e, flush = True) finally: self.poll = None @@ -163,10 +170,11 @@ self.pin = response.user_code self.req_id = response.token except Exception as e: - print(e) + print("Error retrieving magic token: ", e) return self.update_state() - threading.Thread(target=self.poll_for_magic_token, daemon=True).start() + self.poll = threading.Thread(target=self.poll_for_magic_token, daemon=True) + self.poll.start() def on_radio_toggled(self, button): self.update_state() @@ -174,5 +182,20 @@ def on_magic_radio_clicked(self, button): self.start_magic_attach() + # Do not control the radio buttons and confirm button widgets directly, + # since those former are controlled by update_state and this function must + # be logically independent of it. Control the net_control_box'es instead. + def net_status_changed(self, monitor, available, first_run): + self.no_connection.set_visible(not available) + self.radio_net_control_box.set_sensitive(available) + self.confirm_net_control_box.set_sensitive(available) + if available: + if self.pin == "": + self.start_magic_attach() + elif self.poll == None: + # wait() timed out without internet; Restart polling. + self.poll = threading.Thread(target=self.poll_for_magic_token, daemon=True) + self.poll.start() + def finish(self): self.dialog.response(Gtk.ResponseType.OK)