Skip to content

Commit

Permalink
app-info: Pass a desktop file to XdpAppInfo and add a getter for it
Browse files Browse the repository at this point in the history
This allows clients to access either the GAppInfo or the desktop file
when needed.
  • Loading branch information
swick committed Oct 25, 2024
1 parent ddef51e commit fb4b7a5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
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)
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

0 comments on commit fb4b7a5

Please sign in to comment.