[glib/wip/hadess/gapp-restart-data] GApplication: Add RestartData property, and setter
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/hadess/gapp-restart-data] GApplication: Add RestartData property, and setter
- Date: Wed, 20 Feb 2019 00:52:48 +0000 (UTC)
commit e18007fa2fb19ded7a0a29f0f5cac22ff788145d
Author: Bastien Nocera <hadess hadess net>
Date: Wed Feb 20 01:39:10 2019 +0100
GApplication: Add RestartData property, and setter
The RestartData property on the org.gtk.Application interface can be
used by session services to save some data to disk should the
application disappear.
The application would call g_application_set_restart_data() when the
state of the application changes, with enough information for the
application to restart itself in the same "position".
FIXME:
[ ] API docs
[ ] note about restart data size
[ ] have one example implementation of the session side
One idea would be for xdg-desktop-portal to save a stringified
RestartData to ~/.var/app/$ID/config/state.gvariant if none empty when
the application disappears from the bus.
Questions:
- Can we enforce to only do this for unique applications?
- Can we detect applications leaving the bus suddenly, or do we
want to rely on them clearing RestartData if they're "done" (or should
they always save state, *some* state)
- Should we implement this via org.gnome.SessionManager.Client and the
app calling out to gnome-session instead?
- Or is this API fine, and gnome-session can do what xdg-desktop-portal
does above?
gio/gapplication.c | 18 ++++++++++++++++++
gio/gapplication.h | 4 ++++
gio/gapplicationimpl-dbus.c | 20 +++++++++++++++++---
gio/gapplicationimpl.h | 2 ++
4 files changed, 41 insertions(+), 3 deletions(-)
---
diff --git a/gio/gapplication.c b/gio/gapplication.c
index 2d2ab48e3..6cb378d7a 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -3069,5 +3069,23 @@ g_application_unbind_busy_property (GApplication *application,
g_signal_handler_disconnect (object, handler_id);
}
+/* Session handling {{{1 */
+
+/**
+ * g_application_set_restart_data:
+ * @application:
+ * @data:
+ *
+ */
+void
+g_application_set_restart_data (GApplication *application,
+ GVariant *data)
+{
+ g_return_if_fail (G_IS_APPLICATION (application));
+ g_return_if_fail (!(application->priv->flags & G_APPLICATION_NON_UNIQUE));
+
+ g_application_impl_set_restart_data (application->priv->impl, data);
+}
+
/* Epilogue {{{1 */
/* vim:set foldmethod=marker: */
diff --git a/gio/gapplication.h b/gio/gapplication.h
index adc32ed44..489c9125e 100644
--- a/gio/gapplication.h
+++ b/gio/gapplication.h
@@ -229,6 +229,10 @@ void g_application_unmark_busy (GApplic
GLIB_AVAILABLE_IN_2_44
gboolean g_application_get_is_busy (GApplication
*application);
+GLIB_AVAILABLE_IN_2_60
+void g_application_set_restart_data (GApplication
*application,
+ GVariant *data);
+
GLIB_AVAILABLE_IN_2_40
void g_application_send_notification (GApplication
*application,
const gchar *id,
diff --git a/gio/gapplicationimpl-dbus.c b/gio/gapplicationimpl-dbus.c
index 76d67eec8..40a61888a 100644
--- a/gio/gapplicationimpl-dbus.c
+++ b/gio/gapplicationimpl-dbus.c
@@ -66,6 +66,7 @@ static const gchar org_gtk_Application_xml[] =
"<arg type='i' name='exit-status' direction='out'/>"
"</method>"
"<property name='Busy' type='b' access='read'/>"
+ "<property name='RestartData' type='v' access='read'/>"
"</interface>"
"</node>";
@@ -121,6 +122,7 @@ struct _GApplicationImpl
gboolean properties_live;
gboolean primary;
gboolean busy;
+ GVariant *restart_data;
gboolean registered;
GApplication *app;
};
@@ -149,14 +151,16 @@ g_application_impl_get_property (GDBusConnection *connection,
}
static void
-send_property_change (GApplicationImpl *impl)
+send_property_change (GApplicationImpl *impl,
+ const char *property_name,
+ GVariant *value)
{
GVariantBuilder builder;
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
g_variant_builder_add (&builder,
"{sv}",
- "Busy", g_variant_new_boolean (impl->busy));
+ property_name, value);
g_dbus_connection_emit_signal (impl->session_bus,
NULL,
@@ -558,10 +562,20 @@ g_application_impl_set_busy_state (GApplicationImpl *impl,
if (impl->busy != busy)
{
impl->busy = busy;
- send_property_change (impl);
+ send_property_change (impl, "Busy", g_variant_new_boolean (impl->busy));
}
}
+void
+g_application_impl_set_restart_data (GApplicationImpl *impl,
+ GVariant *variant)
+{
+ g_clear_pointer (&impl->restart_data, g_variant_unref);
+ if (variant)
+ impl->restart_data = g_variant_ref (variant);
+ send_property_change (impl, "RestartData", impl->restart_data);
+}
+
void
g_application_impl_destroy (GApplicationImpl *impl)
{
diff --git a/gio/gapplicationimpl.h b/gio/gapplicationimpl.h
index 1e6a718db..80e93d58a 100644
--- a/gio/gapplicationimpl.h
+++ b/gio/gapplicationimpl.h
@@ -42,3 +42,5 @@ const gchar * g_application_impl_get_dbus_object_path (GApplic
void g_application_impl_set_busy_state (GApplicationImpl *impl,
gboolean busy);
+void g_application_impl_set_restart_data (GApplicationImpl *impl,
+ GVariant *variant);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]