From 667d39bdcf35735f044d47a516f41169b2de7a8c Mon Sep 17 00:00:00 2001 From: ludeeus Date: Wed, 1 Jan 2020 11:25:23 +0000 Subject: [PATCH] Add reload window to menu --- src/HacsFrontend.ts | 11 ++++++++--- src/localize/languages/en.json | 1 + src/misc/HacsMenu.ts | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/HacsFrontend.ts b/src/HacsFrontend.ts index 3346b1958..d683a2571 100644 --- a/src/HacsFrontend.ts +++ b/src/HacsFrontend.ts @@ -9,7 +9,7 @@ import { property, TemplateResult } from "lit-element"; -import { HACS, Hacs } from "./Hacs"; +import { HACS } from "./Hacs"; import { HacsStyle } from "./style/hacs-style"; import { @@ -52,7 +52,9 @@ class HacsFrontendBase extends LitElement { if (this.hacs.isnullorempty(repositories)) repositories = this.hacs.repositories; if (this.hacs.isnullorempty(status)) status = this.hacs.status; - this.hacs = new Hacs(configuration, repositories, status); + this.hacs.configuration = configuration; + this.hacs.repositories = repositories; + this.hacs.status = status; this.requestUpdate(); } @@ -144,6 +146,7 @@ class HacsFrontendBase extends LitElement { this.addEventListener("hacs-location-change", this.locationChanged); this.addEventListener("hacs-onboarding-done", this.onboardingDone); this.addEventListener("hacs-recreate", this._recreatehacs); + this.addEventListener("hacs-force-reload", this._reload); window.onpopstate = function() { window.location.reload(); }; @@ -184,7 +187,9 @@ class HacsFrontendBase extends LitElement { } _reload(e: any) { - window.location.reload(e.data.force); + const force = + (e.data && e.data.force) || (e.detail && e.detail.force) || false; + window.location.reload(force); } protected render(): TemplateResult | void { diff --git a/src/localize/languages/en.json b/src/localize/languages/en.json index 21f25d770..cac0c17ea 100644 --- a/src/localize/languages/en.json +++ b/src/localize/languages/en.json @@ -100,6 +100,7 @@ "missing_category": "You need to select a category", "open_repository": "Open repository", "reload_data": "Reload data", + "reload_window": "Reload window", "repository_configuration": "Repository configuration", "save": "Save", "table_view": "Table view", diff --git a/src/misc/HacsMenu.ts b/src/misc/HacsMenu.ts index 90d91c71b..c301ea895 100644 --- a/src/misc/HacsMenu.ts +++ b/src/misc/HacsMenu.ts @@ -53,6 +53,10 @@ export class HacsMenu extends LitElement { ${this.hacs.localize("settings.reload_data")} + + ${this.hacs.localize("settings.reload_window")} + + ${this.location.includes("installed") ? html` @@ -126,6 +130,16 @@ export class HacsMenu extends LitElement { }); } + ReloadWindow() { + this.dispatchEvent( + new CustomEvent("hacs-force-reload", { + detail: { force: true }, + bubbles: true, + composed: true + }) + ); + } + ReloadData() { if (this.status.background_task) { this.disabledAction();