snapd icon indicating copy to clipboard operation
snapd copied to clipboard

api-snaps: add refresh-observe access to /v2/snaps/{name}

Open sergio-costas opened this issue 9 months ago • 7 comments

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?

sergio-costas avatar May 02 '24 16:05 sergio-costas

@ZeyadYasser I need access to this API entry for snapd-desktop-integration. Can you review it when you have some spare time, please?

sergio-costas avatar May 02 '24 16:05 sergio-costas

@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 avatar May 03 '24 10:05 sergio-costas

@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 avatar May 03 '24 11:05 ZeyadYasser

@ZeyadYasser Oh... that explains all those test failures 😅

I'll check it.

sergio-costas avatar May 03 '24 11:05 sergio-costas

Ok, it should be fixed...

sergio-costas avatar May 03 '24 14:05 sergio-costas

@sergio-costas Please rebase and squash the commits so that it can be merged, Thanks!

ZeyadYasser avatar May 07 '24 06:05 ZeyadYasser

@ZeyadYasser Rebased and squashed.

sergio-costas avatar May 07 '24 08:05 sergio-costas