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: Clear console web history after login (#1319)

Martin Peetersdef8de8ef16c
diff --git a/ui/component/core/src/console.ts b/ui/component/core/src/console.ts
index 20590daac..6fae716ed 100644
--- a/ui/component/core/src/console.ts
+++ b/ui/component/core/src/console.ts
@@ -380,13 +380,30 @@ export class Console {
}
protected _postNativeShellMessage(jsonMessage: any) {
- if (this.shellAndroid) {
- // @ts-ignore
- return window.MobileInterface.postMessage(JSON.stringify(jsonMessage));
+ try {
+ if (this.shellAndroid) {
+ // @ts-ignore
+ return window.MobileInterface.postMessage(JSON.stringify(jsonMessage));
+ }
+ if (this.shellApple) {
+ // @ts-ignore
+ return window.webkit.messageHandlers.int.postMessage(jsonMessage);
+ }
+ } catch (e) {
+ console.error("Failed to send shell message towards console", e);
}
- if (this.shellApple) {
- // @ts-ignore
- return window.webkit.messageHandlers.int.postMessage(jsonMessage);
+ }
+
+ /**
+ * Function that allows sending of custom types and messages towards the console.
+ * TODO: Will be improved in the future, see this GitHub issue; https://github.com/openremote/openremote/issues/1318
+ */
+ public _doSendGenericMessage(type: string, msg: any) {
+ const payload = { type: type, data: msg };
+ if (this.isMobile) {
+ this._postNativeShellMessage(payload);
+ } else {
+ console.warn("Failed to send generic message to console.", payload)
}
}
diff --git a/ui/component/core/src/index.ts b/ui/component/core/src/index.ts
index 73f576e86..8efd2c920 100644
--- a/ui/component/core/src/index.ts
+++ b/ui/component/core/src/index.ts
@@ -373,7 +373,13 @@ export class Manager implements EventProviderFactory {
}
// Don't let console registration error prevent loading
- await this.doConsoleInit();
+ const consoleSuccess = await this.doConsoleInit();
+ if(consoleSuccess) {
+ // Send the console a message to clear the web history, so no pages outside the app can be accessed.
+ // For example, this prevents navigating back to an authentication screen.
+ this._clearWebHistory();
+ }
+
success = await this.doTranslateInit() && success;
if (success) {
@@ -1159,6 +1165,12 @@ export class Manager implements EventProviderFactory {
}
}
}
+
+ /** Function that clears the `WebView` history of a console. It will not delete the history on regular browsers. */
+ protected _clearWebHistory(): void {
+ this.console?._doSendGenericMessage("CLEAR_WEB_HISTORY", undefined);
+ }
+
}
export const manager = new Manager(); // Needed for webpack bundling