Skip to content

Commit

Permalink
Make canceling from the pkexec dialog more robust.
Browse files Browse the repository at this point in the history
If the user aborts a format or write operation by clicking cancel
in the pkexec dialog, just close that dialog, but keep the mintstick
window usable so the user can try again without having to restart
the program.
  • Loading branch information
mtwebster committed Oct 6, 2023
1 parent e02930c commit b5db0b1
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions lib/mintstick.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,18 +308,22 @@ def raw_format(self, usb_path_arg, fstype, label):
GLib.timeout_add(500, self.check_format_job)

def format_job_done(self, rc):
self.set_progress(1.0)
if rc == 0:
self.show_format_result("dialog-information", _('The USB stick was formatted successfully.'))
return False
elif rc == 5:
message = _("An error occured while creating a partition on %s.") % usb_path
elif rc == 127:
message = _('Authentication Error.')
elif rc == 126: # Cancelled by the user.
self.clear_progress()
message = None
else:
message = _('An error occurred.')
self.show_format_result("dialog-error", message)
self.set_format_sensitive()

if message is not None:
self.show_format_result("dialog-error", message)
self.set_format_sensitive(False)
self.udisks_client.handler_unblock(self.udisk_listener_id)
return False

Expand All @@ -339,6 +343,7 @@ def do_write(self, widget):

self.udisks_client.handler_block(self.udisk_listener_id)
self.go_button.set_sensitive(False)
self.verify_button.set_sensitive(False)
self.devicelist.set_sensitive(False)
self.chooser.set_sensitive(False)
self.progressbar.show()
Expand All @@ -352,6 +357,10 @@ def set_progress(self, size):
XApp.set_window_progress_pulse(self.window, False)
XApp.set_window_progress(self.window, int_progress)

def clear_progress(self):
self.progressbar.hide()
XApp.set_window_progress_pulse(self.window, False)

def pulse_progress(self):
self.progressbar.pulse()
XApp.set_window_progress_pulse(self.window, True)
Expand Down Expand Up @@ -416,9 +425,15 @@ def write_job_done(self, rc):
message = _('An error occured while copying the image.')
elif rc == 127:
message = _('Authentication Error.')
elif rc == 126: # Cancelled by the user.
self.clear_progress()
self.set_iso_sensitive()
message = None
else:
message = _('An error occurred.')
self.show_result("dialog-error", message)
if message is not None:
self.show_format_result("dialog-error", message)

return False

def show_format_result(self, icon_name, text):
Expand All @@ -431,11 +446,6 @@ def show_result(self, icon_name, text):
self.wTree.get_object("result_image").set_from_icon_name(icon_name, Gtk.IconSize.DIALOG)
self.wTree.get_object("result_label").set_text(text)

def final_unsensitive(self):
self.chooser.set_sensitive(False)
self.devicelist.set_sensitive(False)
self.go_button.set_sensitive(False)

def close(self, widget):
if self.process is not None:
try:
Expand All @@ -454,9 +464,11 @@ def set_iso_sensitive(self):
self.chooser.set_sensitive(True)
self.devicelist.set_sensitive(True)
self.go_button.set_sensitive(True)
self.verify_button.set_sensitive(True)

def set_format_sensitive(self):
self.get_devices()
def set_format_sensitive(self, reset=True):
if reset:
self.get_devices()
self.filesystemlist.set_sensitive(True)
self.devicelist.set_sensitive(True)
self.go_button.set_sensitive(True)
Expand Down

0 comments on commit b5db0b1

Please sign in to comment.