From 4ea6507bd52854cfc2cbab2db86cae1912e9830a Mon Sep 17 00:00:00 2001 From: ludeeus Date: Sat, 9 Jul 2022 11:43:37 +0000 Subject: [PATCH] Fix resource cleanup --- src/panels/hacs-repository-panel.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/panels/hacs-repository-panel.ts b/src/panels/hacs-repository-panel.ts index 5d00a45a..967e5566 100644 --- a/src/panels/hacs-repository-panel.ts +++ b/src/panels/hacs-repository-panel.ts @@ -34,6 +34,8 @@ import "../components/hacs-repository-card"; import { Hacs } from "../data/hacs"; import { fetchRepositoryInformation, RepositoryBase, RepositoryInfo } from "../data/repository"; import { + deleteResource, + fetchResources, getRepositories, repositoryAdd, repositoryUninstall, @@ -358,8 +360,7 @@ export class HacsRepositoryPanel extends LitElement { confirmText: this.hacs.localize("dialog.remove.title"), content: this.hacs.localize("dialog.remove.message", { name: this._repository!.name }), confirm: async () => { - await repositoryUninstall(this.hass, String(this._repository!.id)); - history.back(); + await this._repositoryRemove(); }, }, bubbles: true, @@ -368,6 +369,23 @@ export class HacsRepositoryPanel extends LitElement { ); } + private async _repositoryRemove() { + if (this._repository!.category === "plugin" && this.hacs.info?.lovelace_mode !== "yaml") { + const resources = await fetchResources(this.hass); + resources + .filter((resource) => + resource.url.startsWith( + `/hacsfiles/${this._repository!.full_name.split("/")[1]}/${this._repository!.file_name}` + ) + ) + .forEach(async (resource) => { + await deleteResource(this.hass, String(resource.id)); + }); + } + await repositoryUninstall(this.hass, String(this._repository!.id)); + history.back(); + } + private async _refreshReopsitoryInfo() { await repositoryUpdate(this.hass, String(this._repository!.id)); }