Skip to content

Commit

Permalink
Fix resource cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Jul 9, 2022
1 parent 4de9f32 commit 4ea6507
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/panels/hacs-repository-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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));
}
Expand Down

0 comments on commit 4ea6507

Please sign in to comment.