[gnome-games] application-window: Handle resume dialog response properly



commit 1382689b06c9fbddd4f6ca65a0cf0017633475cd
Author: Yetizone <andreii lisita gmail com>
Date:   Wed Jan 30 15:18:16 2019 +0200

    application-window: Handle resume dialog response properly

 src/ui/application-window.vala | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)
---
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index 8819a249..e0ac74ec 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -359,12 +359,16 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
                is_fullscreen = settings.get_boolean ("fullscreen") && runner.can_fullscreen;
 
-               bool resume = false;
+               var response = Gtk.ResponseType.NONE;
                if (runner.can_resume)
-                       resume = prompt_resume_with_cancellable (cancellable);
+                       response = prompt_resume_with_cancellable (cancellable);
 
-               if (!try_run_with_cancellable (runner, resume, cancellable))
-                       prompt_resume_fail_with_cancellable (runner, cancellable);
+               if (response != Gtk.ResponseType.NONE) {
+                       var resume = (response == Gtk.ResponseType.ACCEPT);
+
+                       if (!try_run_with_cancellable (runner, resume, cancellable))
+                               prompt_resume_fail_with_cancellable (runner, cancellable);
+               }
        }
 
        private Runner? try_get_runner (Game game) {
@@ -388,9 +392,9 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                }
        }
 
-       private bool prompt_resume_with_cancellable (Cancellable cancellable) {
+       private Gtk.ResponseType prompt_resume_with_cancellable (Cancellable cancellable) {
                if (resume_dialog != null)
-                       return false;
+                       return Gtk.ResponseType.NONE;
 
                resume_dialog = new ResumeDialog ();
                resume_dialog.transient_for = this;
@@ -401,16 +405,15 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                });
 
                var response = resume_dialog.run ();
-               resume_dialog.destroy ();
-               resume_dialog = null;
-
-               if (cancellable.is_cancelled ())
-                       response = Gtk.ResponseType.CANCEL;
 
-               if (response == Gtk.ResponseType.CANCEL)
-                       return false;
+               // The null check is necessary because the dialog could already
+               // be canceled by this point
+               if (resume_dialog != null) {
+                       resume_dialog.destroy ();
+                       resume_dialog = null;
+               }
 
-               return true;
+               return (Gtk.ResponseType) response;
        }
 
        private bool try_run_with_cancellable (Runner runner, bool resume, Cancellable cancellable) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]