Skip to content

Commit

Permalink
switch theme driven by the iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz committed Dec 2, 2024
1 parent 4860602 commit 449853e
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,41 @@ qx.Class.define("osparc.widget.PersistentIframe", {
this.postThemeSwitch(msg.getData());
};
qx.event.message.Bus.getInstance().subscribe("themeSwitch", this.themeSwitchHandler);

// listen to messages
this.__iframe.addListener("load", () => {
const iframe = this._getIframeElement();
if (iframe) {
const iframeDomEl = iframe.getDomElement();
if (iframeDomEl) {
const iframeWindow = iframe.getDomElement().contentWindow;
window.addEventListener('message', message => {
if (message.source === iframeWindow) {
const data = message.data;
if (data) {
this.__handleIframeMessage(data);
}
}
});
}
}
}, this);
},

__handleIframeMessage: function(data) {
// switch theme driven by the iframe
if (data["type"] && data["type"] === "theme") {
const message = data["message"];
console.log(message);
if (message.includes("osparc;theme=")) {
const themeName = message.replace("osparc;theme=", "");
const validThemes = osparc.ui.switch.ThemeSwitcher.getValidThemes();
const themeFound = validThemes.find(theme => theme.basename === themeName);
if (themeFound) {
qx.theme.manager.Meta.getInstance().setTheme(themeFound);
}
}
}
},

// override
Expand Down

0 comments on commit 449853e

Please sign in to comment.