[gnome-games] display-view: Make restart async
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] display-view: Make restart async
- Date: Fri, 16 Oct 2020 15:59:07 +0000 (UTC)
commit 9f97cceb56394c0d64cee94a8ac183dc98f1e68f
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Fri Oct 16 20:28:01 2020 +0500
display-view: Make restart async
Avoid gtk_dialog_run ().
src/ui/display-view.vala | 80 ++++++++++++++++++++++++++++--------------------
1 file changed, 47 insertions(+), 33 deletions(-)
---
diff --git a/src/ui/display-view.vala b/src/ui/display-view.vala
index 1b21e1a3..ef6cd5a8 100644
--- a/src/ui/display-view.vala
+++ b/src/ui/display-view.vala
@@ -674,50 +674,64 @@ private class Games.DisplayView : Gtk.Box, UiView {
}
private void restart () {
- if (runner != null && runner.is_integrated) {
- runner.pause ();
+ restart_internal.begin ();
+ }
- if (runner.try_create_snapshot (true) == null) {
- restart_dialog = new Gtk.MessageDialog (
- window,
- Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
- Gtk.MessageType.QUESTION,
- Gtk.ButtonsType.CANCEL,
- "%s",
- _("Are you sure you want to restart?")
- );
+ private async void restart_internal () {
+ if (runner == null || !runner.is_integrated) {
+ run_game (game);
- restart_dialog.format_secondary_text ("%s", _("All unsaved progress will be
lost."));
+ return;
+ }
- var button = restart_dialog.add_button (_("Restart"),
Gtk.ResponseType.ACCEPT);
- button.get_style_context ().add_class ("destructive-action");
+ runner.pause ();
- var response = restart_dialog.run ();
- restart_dialog.destroy ();
- restart_dialog = null;
+ if (runner.try_create_snapshot (true) == null) {
+ restart_dialog = new Gtk.MessageDialog (
+ window,
+ Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
+ Gtk.MessageType.QUESTION,
+ Gtk.ButtonsType.CANCEL,
+ "%s",
+ _("Are you sure you want to restart?")
+ );
- if (response == Gtk.ResponseType.CANCEL || response ==
Gtk.ResponseType.DELETE_EVENT) {
- runner.resume ();
+ restart_dialog.format_secondary_text ("%s", _("All unsaved progress will be lost."));
- return;
- }
- }
+ var button = restart_dialog.add_button (_("Restart"), Gtk.ResponseType.ACCEPT);
+ button.get_style_context ().add_class ("destructive-action");
- runner.stop ();
- runner = try_get_runner (game);
+ var response = Gtk.ResponseType.CANCEL;
- try {
- runner.start ();
- }
- catch (Error e) {
- critical ("Couldn't restart: %s", e.message);
- }
+ restart_dialog.response.connect (r => {
+ response = (Gtk.ResponseType) r;
- return;
+ restart_internal.callback ();
+ });
+
+ restart_dialog.present ();
+
+ yield;
+
+ restart_dialog.destroy ();
+ restart_dialog = null;
+
+ if (response == Gtk.ResponseType.CANCEL || response == Gtk.ResponseType.DELETE_EVENT)
{
+ runner.resume ();
+
+ return;
+ }
}
- if (game != null)
- run_game (game);
+ runner.stop ();
+ runner = try_get_runner (game);
+
+ try {
+ runner.start ();
+ }
+ catch (Error e) {
+ critical ("Couldn't restart: %s", e.message);
+ }
}
private void set_display (Gtk.Widget display) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]