snapd
snapd copied to clipboard
api-snaps: add refresh-observe access to /v2/snaps/{name}
Access to /v2/snaps/{name} is required for snap-refresh-observe because it is needed to get the path for the XXXXX.desktop file, which is needed for the icon and the visible name.
It should not be a problem because /v2/snaps is already enabled.
Thanks for helping us make a better snapd! Have you signed the license agreement and read the contribution guide?
@ZeyadYasser I need access to this API entry for snapd-desktop-integration. Can you review it when you have some spare time, please?
@ZeyadYasser I need it to get the .desktop file associated to a snap, to extract from it the visible name (and thus show "Telegram desktop" instead of "telegram-desktop") and the icon.
I use this code for that:
GAppInfo *sdi_get_desktop_file_from_snap(SnapdSnap *snap) {
GPtrArray *apps = snapd_snap_get_apps(snap);
if ((apps == NULL) || (apps->len == 0)) {
return NULL;
}
if (apps->len > 1) {
const gchar *name = snapd_snap_get_name(snap);
// get the entry that has the same app name than the snap
for (int i = 0; i < apps->len; i++) {
SnapdApp *app = apps->pdata[i];
if (g_str_equal(name, snapd_app_get_name(app))) {
const gchar *desktop_file = snapd_app_get_desktop_file(app);
return G_APP_INFO(g_desktop_app_info_new_from_filename(desktop_file));
}
}
// if it doesn't exist, get the first entry with an icon
for (int i = 0; i < apps->len; i++) {
SnapdApp *app = apps->pdata[i];
const gchar *desktop_file = snapd_app_get_desktop_file(app);
g_autoptr(GAppInfo) app_info =
G_APP_INFO(g_desktop_app_info_new_from_filename(desktop_file));
if (app_info != NULL) {
GIcon *icon = g_app_info_get_icon(app_info);
if (icon != NULL) {
return g_steal_pointer(&app_info);
}
}
}
} else {
const gchar *desktop_file = snapd_app_get_desktop_file(apps->pdata[0]);
return G_APP_INFO(g_desktop_app_info_new_from_filename(desktop_file));
}
return NULL;
}
@sergio-costas It seems that tests/main/interfaces-snap-refresh-observe
needs to be updated for the changes introduced.
https://github.com/snapcore/snapd/blob/e3a857689fb9f23bda66d7a6b8291f3f00a5a804/tests/main/interfaces-snap-refresh-observe/task.yaml#L38-L39
@ZeyadYasser Oh... that explains all those test failures 😅
I'll check it.
Ok, it should be fixed...
@sergio-costas Please rebase and squash the commits so that it can be merged, Thanks!
@ZeyadYasser Rebased and squashed.