Skip to content

Commit

Permalink
Better notification to extensions for isVisible
Browse files Browse the repository at this point in the history
Add notification to extension: isConnected to track WS status and inform extensions
Bump version
  • Loading branch information
luc-github committed Nov 23, 2024
1 parent 0b0116f commit cabfd29
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 7 deletions.
Binary file modified dist/CNC/GRBL/index.html.gz
Binary file not shown.
Binary file modified dist/CNC/GRBLHal/index.html.gz
Binary file not shown.
Binary file modified dist/Plotter/HP-GL/index.html.gz
Binary file not shown.
Binary file modified dist/Printer3D/Marlin-embedded/index.html.gz
Binary file not shown.
Binary file modified dist/Printer3D/Marlin/index.html.gz
Binary file not shown.
Binary file modified dist/Printer3D/Repetier/index.html.gz
Binary file not shown.
Binary file modified dist/Printer3D/Smoothieware/index.html.gz
Binary file not shown.
Binary file modified dist/SandTable/GRBL/index.html.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion src/components/App/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
23 changes: 18 additions & 5 deletions src/components/ExtraContent/extraContentItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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 },
"*"
)
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/contexts/WsContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit cabfd29

Please sign in to comment.