From 637bccdb9f8c686506e24d635ff7bede72886b0d Mon Sep 17 00:00:00 2001 From: leomoty Date: Mon, 4 Sep 2023 08:48:36 -0300 Subject: [PATCH] Application list may install appstream if missing --- pkg/apps/application-list.jsx | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/pkg/apps/application-list.jsx b/pkg/apps/application-list.jsx index 7afd38483f5c..eaf1310578a6 100644 --- a/pkg/apps/application-list.jsx +++ b/pkg/apps/application-list.jsx @@ -27,11 +27,14 @@ import { Flex, FlexItem } from "@patternfly/react-core/dist/esm/layouts/Flex/ind import { Page, PageSection, PageSectionVariants } from "@patternfly/react-core/dist/esm/components/Page/index.js"; import { RebootingIcon } from "@patternfly/react-icons"; +import { check_missing_packages } from "packagekit.js"; import * as PackageKit from "./packagekit.js"; import { read_os_release } from "os-release.js"; import { icon_url, show_error, launch, ProgressBar, CancelButton } from "./utils.jsx"; import { ActionButton } from "./application.jsx"; import { EmptyStatePanel } from "cockpit-components-empty-state.jsx"; +import { install_dialog } from "cockpit-components-install-dialog.jsx"; +import { useInit } from "../lib/hooks.js"; const _ = cockpit.gettext; @@ -93,6 +96,7 @@ const ApplicationRow = ({ comp, progress, progress_title, action }) => { export const ApplicationList = ({ metainfo_db, appProgress, appProgressTitle, action }) => { const [progress, setProgress] = useState(false); + const [dataPackagesInstalled, setDataPackagesInstalled] = useState(null); const comps = []; for (const id in metainfo_db.components) comps.push(metainfo_db.components[id]); @@ -109,14 +113,22 @@ export const ApplicationList = ({ metainfo_db, appProgress, appProgressTitle, ac } } + useInit(() => check_missing_packages(['appstream']).then(data => setDataPackagesInstalled(data.missing_names.length === 0))); + function refresh() { - read_os_release().then(os_release => - PackageKit.refresh(metainfo_db.origin_files, - get_config('appstream_config_packages', os_release.ID, []), - get_config('appstream_data_packages', os_release.ID, []), - setProgress)) - .finally(() => setProgress(false)) - .catch(show_error); + if (dataPackagesInstalled) { + read_os_release().then(os_release => + PackageKit.refresh(metainfo_db.origin_files, + get_config('appstream_config_packages', os_release.ID, []), + get_config('appstream_data_packages', os_release.ID, []), + setProgress)) + .finally(() => setProgress(false)) + .catch(show_error); + } else { + install_dialog('appstream') + .then(() => setDataPackagesInstalled(true)) + .catch(() => null); // ignore cancel + } } let refresh_progress, refresh_button, tbody; @@ -159,6 +171,9 @@ export const ApplicationList = ({ metainfo_db, appProgress, appProgressTitle, ac {comps.length == 0 ? : + {dataPackagesInstalled == false && } { tbody }