Skip to content

Commit

Permalink
fix[close #3544]: Clicking on a snapshot instantly starts the restore…
Browse files Browse the repository at this point in the history
… process (and is not abortable)
  • Loading branch information
mirkobrombin committed Dec 12, 2024
1 parent 61c1710 commit 5c4e2b4
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions bottles/frontend/widgets/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,39 @@ def set_state(self, widget):
"""
Set the bottle state to this one.
"""
self.queue.add_task()
self.parent.set_sensitive(False)
self.spinner.show()
self.spinner.start()

def _after():
self.window.page_details.view_versioning.update(
None, self.config
) # update states
self.manager.update_bottles() # update bottles

RunAsync(
task_func=self.versioning_manager.set_state,
callback=self.set_completed,
config=self.config,
state_id=self.state[0],
after=_after,

def handle_response(dialog, response_id):
if response_id == "ok":
self.queue.add_task()
self.parent.set_sensitive(False)
self.spinner.show()
self.spinner.start()

def _after():
self.window.page_details.view_versioning.update(None, self.config)
self.manager.update_bottles()

RunAsync(
task_func=self.versioning_manager.set_state,
callback=self.set_completed,
config=self.config,
state_id=self.state[0],
after=_after,
)
dialog.destroy()

dialog = Adw.MessageDialog.new(
self.window,
_("Are you sure you want to restore this state?"),
_(
"Restoring this state will overwrite the current configuration and cannot be undone."
),
)
dialog.add_response("cancel", _("_Cancel"))
dialog.add_response("ok", _("_Restore"))
dialog.set_response_appearance("ok", Adw.ResponseAppearance.SUGGESTED)
dialog.connect("response", handle_response)
dialog.present()

@GtkUtils.run_in_main_loop
def set_completed(self, result, error=False):
Expand Down

0 comments on commit 5c4e2b4

Please sign in to comment.