From 24933e980dbfcebf00d6fb73801d14cc56118478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Bachmann?= Date: Sat, 17 Jan 2026 08:13:22 +0000 Subject: [PATCH] Button --- .../bahmcloud_store/panel/app.js | 76 ++++++++++++++----- 1 file changed, 59 insertions(+), 17 deletions(-) diff --git a/custom_components/bahmcloud_store/panel/app.js b/custom_components/bahmcloud_store/panel/app.js index 588f59e..f625111 100644 --- a/custom_components/bahmcloud_store/panel/app.js +++ b/custom_components/bahmcloud_store/panel/app.js @@ -29,6 +29,7 @@ class BahmcloudStorePanel extends HTMLElement { this._installingRepoId = null; this._updatingRepoId = null; + this._uninstallingRepoId = null; this._restartRequired = false; this._lastActionMsg = null; } @@ -141,6 +142,36 @@ class BahmcloudStorePanel extends HTMLElement { } } + async _uninstallRepo(repoId) { + if (!repoId) return; + if (this._installingRepoId || this._updatingRepoId || this._uninstallingRepoId) return; + + const r = this._repoById(repoId); + const name = this._safeText(r?.name) || repoId; + + const ok = window.confirm(`Uninstall "${name}"?\n\nThis will delete the integration folder(s) from /config/custom_components. A restart will be required.`); + if (!ok) return; + + this._uninstallingRepoId = repoId; + this._lastActionMsg = null; + this.requestUpdate(); + + try { + const resp = await this._hass.callApi("post", `bcs/uninstall?repo_id=${encodeURIComponent(repoId)}`, {}); + if (resp && resp.ok) { + this._restartRequired = !!resp.restart_required; + this._lastActionMsg = "Uninstalled. Restart required."; + } else { + this._lastActionMsg = (resp && resp.message) ? String(resp.message) : "Uninstall failed."; + } + } catch (e) { + this._lastActionMsg = e && e.message ? e.message : "Uninstall failed."; + } finally { + this._uninstallingRepoId = null; + await this._load(); + } + } + async _restartHA() { if (!this._hass) return; try { @@ -436,15 +467,15 @@ class BahmcloudStorePanel extends HTMLElement {
- -
+ +
鈫�
Bahmcloud Store
Store
-
+
鉄�
@@ -506,7 +537,7 @@ class BahmcloudStorePanel extends HTMLElement { : ""; if (this._loading) { - content.innerHTML = `${err}
Loading…
`; + content.innerHTML = `${err}
Loading鈥�
`; fabs.innerHTML = ""; return; } @@ -608,7 +639,7 @@ class BahmcloudStorePanel extends HTMLElement { if (updateAvailable) badges.push("Update"); const badgeHtml = badges.length - ? `
${this._esc(badges.join(" · "))}
` + ? `
${this._esc(badges.join(" 路 "))}
` : `
${this._esc(this._safeText(r?.provider || "repo"))}
`; return ` @@ -628,7 +659,7 @@ class BahmcloudStorePanel extends HTMLElement { return `
- +
-
Version: ${this._esc(this._data.version || "-")} · Repositories: ${repos.length}
+
Version: ${this._esc(this._data.version || "-")} 路 Repositories: ${repos.length}
${cards || `
No repositories found.
`} @@ -713,7 +744,7 @@ class BahmcloudStorePanel extends HTMLElement { ].filter(Boolean); const readmeBlock = this._readmeLoading - ? `
Loading README…
` + ? `
Loading README鈥�
` : this._readmeText ? `
@@ -748,12 +779,14 @@ class BahmcloudStorePanel extends HTMLElement { const busyInstall = this._installingRepoId === repoId; const busyUpdate = this._updatingRepoId === repoId; - const busy = busyInstall || busyUpdate; + const busyUninstall = this._uninstallingRepoId === repoId; + const busy = busyInstall || busyUpdate || busyUninstall; const updateAvailable = installed && !!latestVersion && (!installedVersion || latestVersion !== installedVersion); - const installBtn = ``; - const updateBtn = ``; + const installBtn = ``; + const updateBtn = ``; + const uninstallBtn = ``; const restartHint = this._restartRequired ? ` @@ -777,7 +810,7 @@ class BahmcloudStorePanel extends HTMLElement {
${this._esc(name)}
${this._esc(desc)}
-
${this._esc(infoBits.join(" · "))}
+
${this._esc(infoBits.join(" 路 "))}
@@ -805,6 +838,7 @@ class BahmcloudStorePanel extends HTMLElement {
${installBtn} ${updateBtn} + ${uninstallBtn}
${restartHint} @@ -820,6 +854,7 @@ class BahmcloudStorePanel extends HTMLElement { // Always wire action buttons (even if README is already loaded) const btnInstall = root.getElementById("btnInstall"); const btnUpdate = root.getElementById("btnUpdate"); + const btnUninstall = root.getElementById("btnUninstall"); const btnRestart = root.getElementById("btnRestart"); if (btnInstall) { @@ -836,6 +871,13 @@ class BahmcloudStorePanel extends HTMLElement { }); } + if (btnUninstall) { + btnUninstall.addEventListener("click", () => { + if (btnUninstall.disabled) return; + if (this._detailRepoId) this._uninstallRepo(this._detailRepoId); + }); + } + if (btnRestart) { btnRestart.addEventListener("click", () => this._restartHA()); } @@ -848,7 +890,7 @@ class BahmcloudStorePanel extends HTMLElement { mount.innerHTML = this._readmeHtml; this._postprocessRenderedMarkdown(mount); } else { - mount.innerHTML = `
Rendered HTML not available. Use “Show raw Markdown”.
`; + mount.innerHTML = `
Rendered HTML not available. Use 鈥淪how raw Markdown鈥�.
`; } } else { mount.innerHTML = ""; @@ -883,10 +925,10 @@ class BahmcloudStorePanel extends HTMLElement { return `
- - - - + + + +
`;