Better notification to extensions for isVisible

Add notification to extension: isConnected to track WS status and inform extensions
Bump version
This commit is contained in:
Luc
2024-11-23 15:52:27 +08:00
parent 0b0116f04e
commit cabfd29e3e
11 changed files with 25 additions and 7 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -17,7 +17,7 @@
*/
import { h } from "preact"
import { webUIbuild } from "../../targets"
export const webUIversion = "3.0.0-a78"
export const webUIversion = "3.0.0-a79"
export const Esp3dVersion = () => (
<span>
{webUIversion}.{webUIbuild}

View File

@@ -19,7 +19,7 @@
*/
import { Fragment, h } from "preact"
import { useState, useEffect, useCallback, useRef, useMemo } from "preact/hooks"
import { espHttpURL } from "../Helpers"
import { espHttpURL, dispatchToExtensions } from "../Helpers"
import { useHttpFn } from "../../hooks"
import { ButtonImg, ContainerHelper } from "../Controls"
import { T } from "../Translations"
@@ -47,15 +47,23 @@ const ExtraContentItem = ({
const { createNewRequest } = useHttpFn
const element_id = id.replace("extra_content_", type)
const refreshIntervalRef = useRef(null)
console.log(`Rendering ExtraContentItem ${id} at ${Date.now()}`);
//console.log(`Rendering ExtraContentItem ${id} at ${Date.now()}`);
if (visibilityState[id] === undefined) {
visibilityState[id] = target=="panel" ? isVisibleOnStart : true;
visibilityState[id] = false;
if (type=="extension" && isLoadedState[id]){
const iframeElement = element.querySelector('iframe.extensionContainer');
if (iframeElement){
iframeElement.contentWindow.postMessage(
{ type: "notification", content: {isVisible: msg.isVisible}, id },
"*"
)
}
}
}
if (isLoadedState[id] === undefined) {
isLoadedState[id] = false;
}
const handleContentSuccess = useCallback((result) => {
let blob
switch (type) {
@@ -133,7 +141,6 @@ const ExtraContentItem = ({
loadContent()
}
if ('isVisible' in msg) {
if (element) {
//console.log("Updating visibility for element " + id + " to " + msg.isVisible)
element.style.display = msg.isVisible ? 'block' : 'none';
@@ -220,6 +227,12 @@ const ExtraContentItem = ({
css.forEach((csstag) => {
doc.head.appendChild(csstag.cloneNode(true))
})
if (iframeElement){
iframeElement.contentWindow.postMessage(
{ type: "notification", content: {isConnected: true, isVisible: visibilityState[id]}, id },
"*"
)
}
}
}

View File

@@ -25,9 +25,10 @@ import {
useHttpQueueContext,
} from "../contexts"
import { useHttpFn } from "../hooks"
import { getCookie, splitArrayByLines } from "../components/Helpers"
import { getCookie, splitArrayByLines, dispatchToExtensions } from "../components/Helpers"
import { T } from "../components/Translations"
/*
* Local const
*
@@ -160,10 +161,14 @@ const WsContextProvider = ({ children }) => {
//Clear all opened modals
modals.clearModals()
//TODO: Stop polling
//Notify extensions
dispatchToExtensions("notification", { isConnected: false }, "all")
}
const onOpenCB = (e) => {
reconnectCounter.current = 0
//Notify extensions
dispatchToExtensions("notification", { isConnected: true }, "all")
ping(true)
}