[grilo/wip/hadess/fix-test-ui-flatpak] grilo-test-ui: Fix tool not working in Flatpak




commit be9d57bc285efc28470e201a4401707755ffd4d6
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Aug 26 12:55:41 2020 +0200

    grilo-test-ui: Fix tool not working in Flatpak
    
    Since commit adc11e54537aff804c6dcd8d26ade0114632157b, it's
    impossible to use grilo-test-ui in the Flatpak for another
    application, as it tries to request a D-Bus name that it cannot own.
    Instead of using our own app-id/D-Bus name, try to own a variant of the
    real app's name.

 tools/grilo-test-ui/main.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
---
diff --git a/tools/grilo-test-ui/main.c b/tools/grilo-test-ui/main.c
index 1fabf76..a0616f1 100644
--- a/tools/grilo-test-ui/main.c
+++ b/tools/grilo-test-ui/main.c
@@ -2472,16 +2472,41 @@ activate (GApplication *app,
   load_plugins ();
 }
 
+static char *
+get_app_id (void)
+{
+  g_autoptr(GKeyFile) keyfile = NULL;
+  const char *app_id;
+
+  if (!g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS))
+    goto bail;
+
+  keyfile = g_key_file_new ();
+  if (!g_key_file_load_from_file (keyfile, "/.flatpak-info", G_KEY_FILE_NONE, NULL))
+    goto bail;
+
+  app_id = g_key_file_get_string (keyfile, "Application", "Name", NULL);
+  if (!app_id)
+    goto bail;
+
+  return g_strdup_printf ("%s.grilotestui", app_id);
+
+bail:
+  return g_strdup ("org.gnome.grilotestui");
+}
+
 int
 main (int argc, char **argv)
 {
   GtkApplication *app;
   int status;
+  g_autofree char *app_id = NULL;
 
   grl_init (&argc, &argv);
   GRL_LOG_DOMAIN_INIT (test_ui_log_domain, "test-ui");
 
-  app = gtk_application_new ("org.gnome.grilotestui", G_APPLICATION_FLAGS_NONE);
+  app_id = get_app_id ();
+  app = gtk_application_new (app_id, G_APPLICATION_FLAGS_NONE);
   g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
   status = g_application_run (G_APPLICATION (app), argc, argv);
   g_object_unref (app);


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