Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

UI updates: Window title on realm change Fixes #490

Rich Turner993e1b001486
diff --git a/ui/component/or-app/src/index.ts b/ui/component/or-app/src/index.ts
index 8df3efaee..e3a8732ec 100644
--- a/ui/component/or-app/src/index.ts
+++ b/ui/component/or-app/src/index.ts
@@ -8,7 +8,7 @@ import {
} from "lit";
import {customElement, property, query} from "lit/decorators.js";
import {unsafeHTML} from "lit/directives/unsafe-html";
-import {AppConfig, RealmAppConfig, router} from "./types";
+import {AppConfig, Page, RealmAppConfig, router} from "./types";
import "@openremote/or-translate";
import "@openremote/or-mwc-components/or-mwc-menu";
import "@openremote/or-mwc-components/or-mwc-snackbar";
@@ -323,9 +323,6 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
}
if (changedProps.has("_page")) {
- const appTitle = this._config.appTitle || "";
- let pageTitle = (i18next.isInitialized ? i18next.t(appTitle) : appTitle);
-
if (this._mainElem) {
if (this._mainElem.firstElementChild) {
this._mainElem.firstElementChild.remove();
@@ -335,18 +332,32 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
if (pageProvider) {
const pageElem = pageProvider.pageCreator();
this._mainElem.appendChild(pageElem);
- pageTitle += (i18next.isInitialized ? " - " + i18next.t(pageElem.name) : " - " + pageElem.name);
}
}
}
- updateMetadata({
- title: pageTitle,
- description: pageTitle
- });
+ this.updateWindowTitle();
}
}
+ protected updateWindowTitle() {
+ if (!this._initialised) {
+ return;
+ }
+
+ const appTitle = this._config.appTitle || "";
+ let pageTitle = (i18next.isInitialized ? i18next.t(appTitle) : appTitle);
+ const pageElem = (this._mainElem ? this._mainElem.firstElementChild : undefined) as Page<any>;
+ if (pageElem) {
+ pageTitle += (i18next.isInitialized ? " - " + i18next.t(pageElem.name) : " - " + pageElem.name);
+ }
+
+ updateMetadata({
+ title: pageTitle,
+ description: pageTitle
+ });
+ }
+
protected shouldUpdate(changedProps: PropertyValues): boolean {
if (changedProps.has("_config") && this._config) {
@@ -369,6 +380,7 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
link.href = favIcon;
}
+ this.updateWindowTitle();
return super.shouldUpdate(changedProps);
}