[gnome-shell/T29763: 33/249] shell-app-system: Report an event when an application opens/closes



commit dfa64aada4dfeb2afe2e1dddb1e57a3e6b6a6277
Author: Mario Sanchez Prada <mario endlessm com>
Date:   Mon Jun 5 17:02:49 2017 +0100

    shell-app-system: Report an event when an application opens/closes
    
    This uses EOS metrics recorder daemon, so add the dependency too.

 meson.build            |  3 +++
 src/meson.build        |  3 ++-
 src/shell-app-system.c | 30 +++++++++++++++++++++++++++++-
 3 files changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/meson.build b/meson.build
index 7dc73a22dc..3e4472704d 100644
--- a/meson.build
+++ b/meson.build
@@ -110,6 +110,9 @@ if enable_recorder
   recorder_deps += [gst_dep, gst_base_dep, gtk_dep, x11_dep]
 endif
 
+# Endless-specific: Metrics
+eosmetrics_dep = dependency('eosmetrics-0')
+
 nm_deps = []
 if get_option('networkmanager')
   nm_deps += dependency('libnm', version: nm_req)
diff --git a/src/meson.build b/src/meson.build
index 46680d5b42..82faa6081d 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -57,7 +57,8 @@ gnome_shell_deps = [
   gi_dep,
   polkit_dep,
   gcr_dep,
-  libsystemd_dep
+  libsystemd_dep,
+  eosmetrics_dep,
 ]
 
 gnome_shell_deps += nm_deps
diff --git a/src/shell-app-system.c b/src/shell-app-system.c
index 828fa726a5..08db745e93 100644
--- a/src/shell-app-system.c
+++ b/src/shell-app-system.c
@@ -8,6 +8,7 @@
 
 #include <gio/gio.h>
 #include <glib/gi18n.h>
+#include <eosmetrics/eosmetrics.h>
 
 #include "shell-app-cache-private.h"
 #include "shell-app-private.h"
@@ -24,6 +25,14 @@
 #define RESCAN_TIMEOUT_MS 2500
 #define MAX_RESCAN_RETRIES 6
 
+/* Occurs when an application visible to the shell is opened or closed. The
+ * payload varies depending on whether it is given as an opening event or a
+ * closed event. If it is an opening event, the payload is a human-readable
+ * application name. If it is a closing event, the payload is empty. The key
+ * used is a pointer to the corresponding ShellApp.
+ */
+#define SHELL_APP_IS_OPEN_EVENT "b5e11a3d-13f8-4219-84fd-c9ba0bf3d1f0"
+
 /* Vendor prefixes are something that can be preprended to a .desktop
  * file name.  Undo this.
  */
@@ -418,15 +427,34 @@ _shell_app_system_notify_app_state_changed (ShellAppSystem *self,
 {
   ShellAppState state = shell_app_get_state (app);
 
+  g_autofree gchar *app_address = g_strdup_printf ("%p", app);
+  GDesktopAppInfo *app_info = shell_app_get_app_info (app);
+  const gchar *app_info_id = NULL;
+  if (app_info != NULL)
+    app_info_id = g_app_info_get_id (G_APP_INFO (app_info));
+
   switch (state)
     {
     case SHELL_APP_STATE_RUNNING:
+      if (app_info_id != NULL)
+        {
+          emtr_event_recorder_record_start (emtr_event_recorder_get_default (),
+                                            SHELL_APP_IS_OPEN_EVENT,
+                                            g_variant_new_string (app_address),
+                                            g_variant_new_string (app_info_id));
+        }
       g_hash_table_insert (self->priv->running_apps, g_object_ref (app), NULL);
       break;
     case SHELL_APP_STATE_STARTING:
       break;
     case SHELL_APP_STATE_STOPPED:
-      g_hash_table_remove (self->priv->running_apps, app);
+      if (g_hash_table_remove (self->priv->running_apps, app) && app_info_id != NULL)
+        {
+          emtr_event_recorder_record_stop (emtr_event_recorder_get_default (),
+                                           SHELL_APP_IS_OPEN_EVENT,
+                                           g_variant_new_string (app_address),
+                                           NULL);
+        }
       break;
     default:
       g_warn_if_reached();


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