From 5cda9c740afe7c42a5c9c57a94eeae4a753a466b Mon Sep 17 00:00:00 2001 From: ludeeus Date: Tue, 4 Jun 2024 11:44:58 +0000 Subject: [PATCH] Remove resource handling --- .../dialogs/hacs-download-dialog.ts | 10 +--- .../hacs-repository-owerflow-menu.ts | 18 +------ src/tools/frontend-resource.ts | 50 +------------------ 3 files changed, 4 insertions(+), 74 deletions(-) diff --git a/src/components/dialogs/hacs-download-dialog.ts b/src/components/dialogs/hacs-download-dialog.ts index 69b4573c..b0d038a9 100644 --- a/src/components/dialogs/hacs-download-dialog.ts +++ b/src/components/dialogs/hacs-download-dialog.ts @@ -23,7 +23,7 @@ import { } from "../../data/repository"; import { repositoryBeta, websocketSubscription } from "../../data/websocket"; import { HacsStyles } from "../../styles/hacs-common-style"; -import { generateFrontendResourceURL, updateFrontendResource } from "../../tools/frontend-resource"; +import { generateFrontendResourceURL } from "../../tools/frontend-resource"; import type { HacsDownloadDialogParams } from "./show-hacs-dialog"; import { documentationUrl } from "../../tools/documentation"; @@ -177,7 +177,7 @@ export class HacsDonwloadDialog extends LitElement { ? html`

${this._dialogParams.hacs.localize(`dialog_download.lovelace_instruction`)}

-                url: ${generateFrontendResourceURL({ repository: this._repository, skipTag: true })}
+                url: ${generateFrontendResourceURL({ repository: this._repository })}
                 type: module
                 
@@ -281,12 +281,6 @@ export class HacsDonwloadDialog extends LitElement { this._dialogParams!.hacs.info.lovelace_mode, "_installRepository", ); - if ( - this._repository.category === "plugin" && - this._dialogParams!.hacs.info.lovelace_mode === "storage" - ) { - await updateFrontendResource(this.hass, this._repository, selectedVersion); - } this._installing = false; if (this._repository.category === "plugin") { diff --git a/src/components/hacs-repository-owerflow-menu.ts b/src/components/hacs-repository-owerflow-menu.ts index 914a1fd2..7728c920 100644 --- a/src/components/hacs-repository-owerflow-menu.ts +++ b/src/components/hacs-repository-owerflow-menu.ts @@ -13,10 +13,6 @@ import memoizeOne from "memoize-one"; import { mainWindow } from "../../homeassistant-frontend/src/common/dom/get_main_window"; import { navigate } from "../../homeassistant-frontend/src/common/navigate"; import { getConfigEntries } from "../../homeassistant-frontend/src/data/config_entries"; -import { - deleteResource, - fetchResources, -} from "../../homeassistant-frontend/src/data/lovelace/resource"; import { showConfirmationDialog } from "../../homeassistant-frontend/src/dialogs/generic/show-dialog-box"; import type { RepositoryBase } from "../data/repository"; import { @@ -79,7 +75,7 @@ export const repositoryMenuItems = memoizeOne( label: element.hacs.localize("repository_card.open_source"), action: () => mainWindow.open( - `/hacsfiles/${repository.local_path.split("/").pop()}/${repository.file_name}`, + `/hacsfiles/${repository.local_path.split("/").pop()}/${repository.file_name}?cachebuster=${Date.now()}`, "_blank", "noreferrer=true", ), @@ -159,18 +155,6 @@ const _repositoryRemove = async ( element: HacsRepositoryDashboard | HacsDashboard, repository: RepositoryBase, ) => { - if (repository.category === "plugin" && element.hacs.info?.lovelace_mode !== "yaml") { - const resources = await fetchResources(element.hass.connection); - resources - .filter((resource) => - resource.url.startsWith( - `/hacsfiles/${repository.full_name.split("/")[1]}/${repository.file_name}`, - ), - ) - .forEach(async (resource) => { - await deleteResource(element.hass, String(resource.id)); - }); - } await repositoryUninstall(element.hass, String(repository.id)); if (element.nodeName === "HACS-REPOSITORY-PANEL") { history.back(); diff --git a/src/tools/frontend-resource.ts b/src/tools/frontend-resource.ts index 2ad2dda5..f9651a68 100644 --- a/src/tools/frontend-resource.ts +++ b/src/tools/frontend-resource.ts @@ -1,55 +1,7 @@ -import { - createResource, - fetchResources, - updateResource, -} from "../../homeassistant-frontend/src/data/lovelace/resource"; -import type { HomeAssistant } from "../../homeassistant-frontend/src/types"; import type { RepositoryInfo } from "../data/repository"; -import { HacsLogger } from "./hacs-logger"; - -const generateUniqueTag = (repository: RepositoryInfo, version?: string): string => - String( - `${repository.id}${( - version || - repository.installed_version || - repository.selected_tag || - repository.available_version - ).replace(/\D+/g, "")}`, - ); - -export async function updateFrontendResource( - hass: HomeAssistant, - repository: RepositoryInfo, - version?: string, -): Promise { - const logger = new HacsLogger("updateLovelaceResources"); - const resources = await fetchResources(hass.connection); - const namespace = `/hacsfiles/${repository.full_name.split("/")[1]}`; - const url = generateFrontendResourceURL({ repository, version }); - const exsisting = resources.find((resource) => resource.url.includes(namespace)); - - logger.debug({ namespace, url, exsisting }); - - if (exsisting && exsisting.url !== url) { - logger.debug(`Updating exsusting resource for ${namespace}`); - await updateResource(hass, exsisting.id, { - url, - res_type: exsisting.type, - }); - } else if (!resources.map((resource) => resource.url).includes(url)) { - logger.debug(`Adding ${url} to Lovelace resources`); - await createResource(hass, { - url, - res_type: "module", - }); - } -} export const generateFrontendResourceURL = (options: { repository: RepositoryInfo; version?: string; - skipTag?: boolean; }): string => - `/hacsfiles/${options.repository.full_name.split("/")[1]}/${options.repository.file_name}${ - !options.skipTag ? `?hacstag=${generateUniqueTag(options.repository, options.version)}` : "" - }`; + `/hacsfiles/${options.repository.full_name.split("/")[1]}/${options.repository.file_name}`;