/** * gs_plugin_refine_item_commit: */ static gboolean gs_plugin_refine_item_commit (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); g_autoptr(AsProfileTask) ptask = NULL; g_autoptr(XdgAppRemoteRef) xref_remote = NULL; if (gs_app_get_xdgapp_commit (app) != NULL) return TRUE; if (gs_app_get_origin (app) == NULL) { g_debug ("no origin got commit, so refining origin first"); if (!gs_plugin_refine_item_origin (plugin, app, cancellable, error)) return FALSE; } ptask = as_profile_start_literal (gs_plugin_get_profile (plugin), "xdg-app::fetch-remote-ref"); xref_remote = xdg_app_installation_fetch_remote_ref_sync (priv->installation, gs_app_get_origin (app), gs_app_get_xdgapp_kind (app), gs_app_get_xdgapp_name (app), gs_app_get_xdgapp_arch (app), gs_app_get_xdgapp_branch (app), cancellable, error); if (xref_remote == NULL) return FALSE; gs_app_set_xdgapp_commit (app, xdg_app_ref_get_commit (XDG_APP_REF (xref_remote))); return TRUE; }
/** * gs_plugin_xdg_app_set_metadata: */ static void gs_plugin_xdg_app_set_metadata (GsApp *app, XdgAppRef *xref) { gs_app_set_management_plugin (app, "xdg-app"); gs_app_set_xdgapp_kind (app, xdg_app_ref_get_kind (xref)); gs_app_set_xdgapp_name (app, xdg_app_ref_get_name (xref)); gs_app_set_xdgapp_arch (app, xdg_app_ref_get_arch (xref)); gs_app_set_xdgapp_branch (app, xdg_app_ref_get_branch (xref)); gs_app_set_xdgapp_commit (app, xdg_app_ref_get_commit (xref)); }
/** * gs_plugin_add_updates: */ gboolean gs_plugin_add_updates (GsPlugin *plugin, GList **list, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); guint i; g_autoptr(GPtrArray) xrefs = NULL; /* get all the installed apps (no network I/O) */ xrefs = xdg_app_installation_list_installed_refs (priv->installation, cancellable, error); if (xrefs == NULL) return FALSE; for (i = 0; i < xrefs->len; i++) { XdgAppInstalledRef *xref = g_ptr_array_index (xrefs, i); const gchar *commit; const gchar *latest_commit; g_autoptr(GsApp) app = NULL; g_autoptr(GError) error_local = NULL; /* check the application has already been downloaded */ commit = xdg_app_ref_get_commit (XDG_APP_REF (xref)); latest_commit = xdg_app_installed_ref_get_latest_commit (xref); if (g_strcmp0 (commit, latest_commit) == 0) { g_debug ("no downloaded update for %s", xdg_app_ref_get_name (XDG_APP_REF (xref))); continue; } /* we have an update to show */ g_debug ("%s has a downloaded update %s->%s", xdg_app_ref_get_name (XDG_APP_REF (xref)), commit, latest_commit); app = gs_plugin_xdg_app_create_installed (plugin, xref, &error_local); if (app == NULL) { g_warning ("failed to add xdg-app: %s", error_local->message); continue; } if (gs_app_get_state (app) == AS_APP_STATE_INSTALLED) gs_app_set_state (app, AS_APP_STATE_UNKNOWN); gs_app_set_state (app, AS_APP_STATE_UPDATABLE_LIVE); gs_app_list_add (list, app); } return TRUE; }
XdgApplication::XdgApplication(XdgAppInstalledRef *app_ref, SoftwareBackend *backend) : Application(backend) { m_state = Application::Installed; m_id = xdg_app_ref_get_name(XDG_APP_REF(app_ref)); m_branch = xdg_app_ref_get_branch(XDG_APP_REF(app_ref)); m_origin = xdg_app_installed_ref_get_origin(app_ref); m_name = m_id; m_arch = xdg_app_ref_get_arch(XDG_APP_REF(app_ref)); m_currentCommit = xdg_app_ref_get_commit(XDG_APP_REF(app_ref)); m_latestCommit = xdg_app_installed_ref_get_latest_commit(app_ref); if (m_branch.isEmpty()) m_branch = "master"; QString desktopId; switch (xdg_app_ref_get_kind(XDG_APP_REF(app_ref))) { case XDG_APP_REF_KIND_APP: m_type = Application::App; desktopId = m_name + ".desktop"; break; case XDG_APP_REF_KIND_RUNTIME: m_type = Application::Runtime; m_icon = QIcon::fromTheme("package-x-generic"); m_summary = "Framework for applications"; desktopId = m_name + ".runtime"; break; default: // TODO: Handle errors here! break; } QString deployDir = xdg_app_installed_ref_get_deploy_dir(app_ref); QString desktopPath = deployDir + "/files/share/applications"; QString appdataPath = deployDir + "/files/share/appdata"; Appstream::Store store; store.load(desktopPath); store.load(appdataPath); Appstream::Component component = store.componentById(desktopId); if (!component.isNull()) refineFromAppstream(component); }