[gnome-games/wip/aplazas/run-uri: 20/21] ui: Handle opening game URIs



commit 72025a6f32322daef83931cd1163d34e251b1433
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu Apr 13 16:16:29 2017 +0200

    ui: Handle opening game URIs
    
    Allow to directly run games by passing their URI to the command line.

 src/ui/application.vala |   45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 44 insertions(+), 1 deletions(-)
---
diff --git a/src/ui/application.vala b/src/ui/application.vala
index 85db677..423209b 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -9,7 +9,7 @@ public class Games.Application : Gtk.Application {
 
        internal Application () {
                Object (application_id: "org.gnome.Games",
-                       flags: ApplicationFlags.FLAGS_NONE);
+                       flags: ApplicationFlags.HANDLES_OPEN);
        }
 
        construct {
@@ -106,6 +106,26 @@ public class Games.Application : Gtk.Application {
                return @"$data_dir/medias";
        }
 
+       protected override void open (File[] files, string hint) {
+               open_async.begin (files, hint);
+       }
+
+       private async void open_async (File[] files, string hint) {
+               if (window == null)
+                       activate ();
+
+               if (files.length == 0)
+                       return;
+
+               var uri = files[0].get_uri ();
+               var game = yield game_for_uri (uri);
+
+               if (game != null)
+                       window.run_game (game);
+               // else
+                       // TODO Display an error
+       }
+
        protected override void activate () {
                Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = true;
 
@@ -133,6 +153,29 @@ public class Games.Application : Gtk.Application {
                return false;
        }
 
+       private async Game? game_for_uri (string uri) {
+               Game? game = null;
+
+               var register = PluginRegister.get_register ();
+               foreach (var plugin_registrar in register) {
+                       if (game != null)
+                               continue;
+
+                       try {
+                               var plugin = plugin_registrar.get_plugin ();
+                               var source = plugin.get_game_source ();
+                               if (source == null)
+                                       continue;
+
+                               game = yield source.game_for_uri (uri);
+                       }
+                       catch (Error e) {
+                       }
+               }
+
+               return game;
+       }
+
        internal async void load_game_list () {
                GameSource[] sources = {};
 


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