mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
[GApplication] Add working directory to platform data
https://bugzilla.gnome.org/show_bug.cgi?id=621838
This commit is contained in:
parent
6ff13071ae
commit
8f5bde679e
@ -131,11 +131,12 @@
|
|||||||
* application instance when a second instance fails to take the bus name.
|
* application instance when a second instance fails to take the bus name.
|
||||||
* @arguments contains the commandline arguments given to the second instance
|
* @arguments contains the commandline arguments given to the second instance
|
||||||
* and @data contains platform-specific additional data.
|
* and @data contains platform-specific additional data.
|
||||||
*
|
*
|
||||||
* On all platforms, @data is guaranteed to have a key "cwd" of type
|
* On all platforms, @data will have a key "cwd" of type signature
|
||||||
* signature "ay" which contains the working directory of the invoked
|
* "ay" which contains the working directory of the invoked
|
||||||
* executable.
|
* executable; this data is defined to be in the default GLib
|
||||||
*
|
* filesystem encoding for the platform. See g_filename_to_utf8().
|
||||||
|
*
|
||||||
* </para>
|
* </para>
|
||||||
* <para>
|
* <para>
|
||||||
* The <methodname>InvokeAction</methodname> function can be called to
|
* The <methodname>InvokeAction</methodname> function can be called to
|
||||||
@ -318,6 +319,38 @@ g_application_default_run (GApplication *application)
|
|||||||
g_main_loop_run (application->priv->mainloop);
|
g_main_loop_run (application->priv->mainloop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GVariant *
|
||||||
|
append_cwd_to_platform_data (GVariant *platform_data)
|
||||||
|
{
|
||||||
|
GVariantBuilder builder;
|
||||||
|
gchar *cwd;
|
||||||
|
GVariant *result;
|
||||||
|
|
||||||
|
cwd = g_get_current_dir ();
|
||||||
|
|
||||||
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
|
||||||
|
if (cwd)
|
||||||
|
g_variant_builder_add (&builder, "{sv}",
|
||||||
|
"cwd",
|
||||||
|
g_variant_new_byte_array (cwd, -1));
|
||||||
|
g_free (cwd);
|
||||||
|
|
||||||
|
if (platform_data)
|
||||||
|
{
|
||||||
|
GVariantIter iter;
|
||||||
|
GVariant *item;
|
||||||
|
|
||||||
|
g_variant_iter_init (&iter, platform_data);
|
||||||
|
while (g_variant_iter_next (&iter, "@{sv}", &item))
|
||||||
|
{
|
||||||
|
g_variant_builder_add_value (&builder, item);
|
||||||
|
g_variant_unref (item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = g_variant_builder_end (&builder);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static GVariant *
|
static GVariant *
|
||||||
variant_from_argv (int argc,
|
variant_from_argv (int argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
@ -976,6 +1009,7 @@ g_application_init (GApplication *app)
|
|||||||
app->priv->default_quit = TRUE;
|
app->priv->default_quit = TRUE;
|
||||||
app->priv->do_register = TRUE;
|
app->priv->do_register = TRUE;
|
||||||
app->priv->is_remote = TRUE;
|
app->priv->is_remote = TRUE;
|
||||||
|
app->priv->platform_data = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1045,7 +1079,12 @@ g_application_set_property (GObject *object,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_PLATFORM_DATA:
|
case PROP_PLATFORM_DATA:
|
||||||
app->priv->platform_data = g_value_dup_variant (value);
|
{
|
||||||
|
GVariant *platform_data = g_value_get_variant (value);
|
||||||
|
if (app->priv->platform_data)
|
||||||
|
g_variant_unref (app->priv->platform_data);
|
||||||
|
app->priv->platform_data = g_variant_ref_sink (append_cwd_to_platform_data (platform_data));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -346,16 +346,8 @@ _g_application_platform_register (GApplication *app,
|
|||||||
GVariant *result;
|
GVariant *result;
|
||||||
|
|
||||||
g_variant_builder_init (&builder, G_VARIANT_TYPE ("(aaya{sv})"));
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("(aaya{sv})"));
|
||||||
g_variant_builder_add (&builder, "@aay", app->priv->argv);
|
g_variant_builder_add_value (&builder, app->priv->argv);
|
||||||
|
g_variant_builder_add_value (&builder, app->priv->platform_data);
|
||||||
if (app->priv->platform_data)
|
|
||||||
g_variant_builder_add (&builder, "@a{sv}", app->priv->platform_data);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{sv}"));
|
|
||||||
g_variant_builder_close (&builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
message = g_variant_builder_end (&builder);
|
message = g_variant_builder_end (&builder);
|
||||||
|
|
||||||
result = g_dbus_connection_call_sync (app->priv->session_bus,
|
result = g_dbus_connection_call_sync (app->priv->session_bus,
|
||||||
|
@ -31,6 +31,26 @@ on_app_activated (GApplication *application,
|
|||||||
GVariant *args,
|
GVariant *args,
|
||||||
GVariant *platform_data)
|
GVariant *platform_data)
|
||||||
{
|
{
|
||||||
|
GVariantIter iter;
|
||||||
|
const char *key;
|
||||||
|
GVariant *value;
|
||||||
|
char *cwd;
|
||||||
|
|
||||||
|
cwd = g_get_current_dir ();
|
||||||
|
g_variant_iter_init (&iter, platform_data);
|
||||||
|
while (g_variant_iter_next (&iter, "{&sv}", &key, &value))
|
||||||
|
{
|
||||||
|
const char *activate_cwd;
|
||||||
|
gsize *len;
|
||||||
|
if (strcmp (key, "cwd") != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
activate_cwd = g_variant_get_byte_array (value, &len);
|
||||||
|
g_assert_cmpstr (cwd, ==, activate_cwd);
|
||||||
|
g_variant_unref (value);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free (cwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
Loading…
Reference in New Issue
Block a user