Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notification: Add the desktop-file-id key for portal backends #1488

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions data/org.freedesktop.impl.portal.Notification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@

The format of the @notification is the same as for
:ref:`org.freedesktop.portal.Notification.AddNotification`.
It additionally can contain the following keys:

* ``desktop-file-id`` (``s``)

The desktop file ID of the app adding the notification. A desktop
file ID is the basename of the desktop file, including the
.desktop extension.

Since version 2, the icon property never uses the ``bytes`` option.
-->
Expand Down
5 changes: 5 additions & 0 deletions src/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,7 @@ handle_add_in_thread_func (GTask *task,
{
CallData *call_data = task_data;
GVariantBuilder builder;
const char *desktop_file_id;
g_autoptr(GError) error = NULL;

CALL_DATA_AUTOLOCK (call_data);
Expand Down Expand Up @@ -1077,6 +1078,10 @@ handle_add_in_thread_func (GTask *task,
return;
}

desktop_file_id = xdp_app_info_get_desktop_file_id (call_data->app_info);
if (desktop_file_id)
g_variant_builder_add (&builder, "{ss}", "desktop-file-id", desktop_file_id);

xdp_dbus_impl_notification_call_add_notification (impl,
xdp_app_info_get_id (call_data->app_info),
call_data->id,
Expand Down
4 changes: 1 addition & 3 deletions src/xdp-app-info-flatpak.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,6 @@ xdp_app_info_flatpak_new (int pid,
g_autofree char *id = NULL;
g_autofree char *instance = NULL;
g_autofree char *desktop_id = NULL;
g_autoptr(GAppInfo) gappinfo = NULL;
g_auto(GStrv) shared = NULL;
gboolean has_network;
xdp_autofd int bwrap_pidfd = -1;
Expand Down Expand Up @@ -692,7 +691,6 @@ xdp_app_info_flatpak_new (int pid,
return NULL;

desktop_id = g_strconcat (id, ".desktop", NULL);
gappinfo = G_APP_INFO (g_desktop_app_info_new (desktop_id));

shared = g_key_file_get_string_list (metadata,
FLATPAK_METADATA_GROUP_CONTEXT,
Expand Down Expand Up @@ -721,7 +719,7 @@ xdp_app_info_flatpak_new (int pid,
app_info_flatpak = g_object_new (XDP_TYPE_APP_INFO_FLATPAK, NULL);
xdp_app_info_initialize (XDP_APP_INFO (app_info_flatpak),
FLATPAK_ENGINE_ID, id, instance,
bwrap_pidfd, gappinfo,
bwrap_pidfd, desktop_id,
TRUE, has_network, TRUE);
app_info_flatpak->flatpak_info = g_steal_pointer (&metadata);

Expand Down
7 changes: 3 additions & 4 deletions src/xdp-app-info-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,17 @@ xdp_app_info_host_new (int pid,
g_autoptr (XdpAppInfoHost) app_info_host = NULL;
g_autofree char *appid = NULL;
g_autofree char *desktop_id = NULL;
g_autoptr(GAppInfo) gappinfo = NULL;

appid = get_appid_from_pid (pid);

desktop_id = g_strconcat (appid, ".desktop", NULL);
gappinfo = G_APP_INFO (g_desktop_app_info_new (desktop_id));
if (g_strcmp0 (appid, "") != 0)
desktop_id = g_strconcat (appid, ".desktop", NULL);

app_info_host = g_object_new (XDP_TYPE_APP_INFO_HOST, NULL);
xdp_app_info_initialize (XDP_APP_INFO (app_info_host),
/* engine, app id, instance */
NULL, appid, NULL,
pidfd, gappinfo,
pidfd, desktop_id,
/* supports_opath */ TRUE,
/* has_network */ TRUE,
/* requires_pid_mapping */ FALSE);
Expand Down
2 changes: 1 addition & 1 deletion src/xdp-app-info-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void xdp_app_info_initialize (XdpAppInfo *app_info,
const char *app_id,
const char *instance,
int pidfd,
GAppInfo *gappinfo,
const char *desktop_file_id,
gboolean supports_opath,
gboolean has_network,
gboolean requires_pid_mapping);
5 changes: 1 addition & 4 deletions src/xdp-app-info-snap.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ xdp_app_info_snap_new (int pid,
g_autofree char *snap_name = NULL;
g_autofree char *snap_id = NULL;
g_autofree char *desktop_id = NULL;
g_autoptr(GAppInfo) gappinfo = NULL;
gboolean has_network;

/* Check the process's cgroup membership to fail quickly for non-snaps */
Expand Down Expand Up @@ -189,8 +188,6 @@ xdp_app_info_snap_new (int pid,
if (desktop_id == NULL)
return NULL;

gappinfo = G_APP_INFO (g_desktop_app_info_new (desktop_id));

has_network = g_key_file_get_boolean (metadata,
SNAP_METADATA_GROUP_INFO,
SNAP_METADATA_KEY_NETWORK,
Expand All @@ -199,7 +196,7 @@ xdp_app_info_snap_new (int pid,
app_info_snap = g_object_new (XDP_TYPE_APP_INFO_SNAP, NULL);
xdp_app_info_initialize (XDP_APP_INFO (app_info_snap),
"io.snapcraft", snap_id, NULL,
pidfd, gappinfo,
pidfd, desktop_id,
FALSE, has_network, TRUE);

return XDP_APP_INFO (g_steal_pointer (&app_info_snap));
Expand Down
29 changes: 27 additions & 2 deletions src/xdp-app-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ typedef struct _XdpAppInfoPrivate
char *id;
char *instance;
int pidfd;
char *desktop_file_id;
GAppInfo *gappinfo;
gboolean supports_opath;
gboolean has_network;
Expand All @@ -80,6 +81,7 @@ xdp_app_info_dispose (GObject *object)
g_clear_pointer (&priv->engine, g_free);
g_clear_pointer (&priv->id, g_free);
g_clear_pointer (&priv->instance, g_free);
g_clear_pointer (&priv->desktop_file_id, g_free);
xdp_close_fd (&priv->pidfd);
g_clear_object (&priv->gappinfo);

Expand Down Expand Up @@ -108,18 +110,29 @@ xdp_app_info_initialize (XdpAppInfo *app_info,
const char *app_id,
const char *instance,
int pidfd,
GAppInfo *gappinfo,
const char *desktop_file_id,
gboolean supports_opath,
gboolean has_network,
gboolean requires_pid_mapping)
{
XdpAppInfoPrivate *priv = xdp_app_info_get_instance_private (app_info);
g_autoptr(GAppInfo) gappinfo = NULL;

if (desktop_file_id != NULL)
{
g_autoptr(GDesktopAppInfo) desktop_appinfo = NULL;

desktop_appinfo = g_desktop_app_info_new (desktop_file_id);
if (desktop_appinfo)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we actually need this dance of assigning the value first to desktop_appinfo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The casts don't like getting NULL and there is no guarantee that we'll be able to find the desktop file that we "detected" so I don't see how.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, i didn't know that.

gappinfo = G_APP_INFO (g_steal_pointer (&desktop_appinfo));
}

priv->engine = g_strdup (engine);
priv->id = g_strdup (app_id);
priv->instance = g_strdup (instance);
priv->pidfd = dup (pidfd);
g_set_object (&priv->gappinfo, gappinfo);
priv->desktop_file_id = g_strdup (desktop_file_id);
g_set_object (&priv->gappinfo, g_steal_pointer (&gappinfo));
priv->supports_opath = supports_opath;
priv->has_network = has_network;
priv->requires_pid_mapping = requires_pid_mapping;
Expand Down Expand Up @@ -155,6 +168,18 @@ xdp_app_info_get_instance (XdpAppInfo *app_info)
return priv->instance;
}

const char *
xdp_app_info_get_desktop_file_id (XdpAppInfo *app_info)
{
XdpAppInfoPrivate *priv;

g_return_val_if_fail (app_info != NULL, NULL);

priv = xdp_app_info_get_instance_private (app_info);

return priv->desktop_file_id;
}

GAppInfo *
xdp_app_info_get_gappinfo (XdpAppInfo *app_info)
{
Expand Down
2 changes: 2 additions & 0 deletions src/xdp-app-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const char * xdp_app_info_get_id (XdpAppInfo *app_info);

const char * xdp_app_info_get_instance (XdpAppInfo *app_info);

const char * xdp_app_info_get_desktop_file_id (XdpAppInfo *app_info);

GAppInfo * xdp_app_info_get_gappinfo (XdpAppInfo *app_info);

gboolean xdp_app_info_is_valid_sub_app_id (XdpAppInfo *app_info,
Expand Down
Loading