Update external resource create
Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
parent
3afb35e5ee
commit
fe4c94e895
1 changed files with 19 additions and 5 deletions
24
js/webui.js
24
js/webui.js
|
@ -50,7 +50,7 @@
|
||||||
if (data) {
|
if (data) {
|
||||||
let parentWindow = null;
|
let parentWindow = null;
|
||||||
|
|
||||||
if (!data.trusted) console.debug(`[webui] Loaded key '${key}'`);
|
if (!data.trusted) console.debug(`[webui] Loaded key`);
|
||||||
|
|
||||||
window.addEventListener("message", ({data, origin, source}) => {
|
window.addEventListener("message", ({data, origin, source}) => {
|
||||||
if (!data.trusted && data.key !== key) {
|
if (!data.trusted && data.key !== key) {
|
||||||
|
@ -61,17 +61,24 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!parentWindow && !data.type === "init") {
|
||||||
|
console.warn(`[webui] Communication has not been initialized`);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case "init":
|
case "openoutpaint/init":
|
||||||
parentWindow = source;
|
parentWindow = source;
|
||||||
|
console.debug(
|
||||||
|
`[webui] Communication with '${origin}' has been initialized`
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "add-resource":
|
case "openoutpaint/add-resource":
|
||||||
{
|
{
|
||||||
const image = document.createElement("img");
|
const image = document.createElement("img");
|
||||||
image.src = data.image.dataURL;
|
image.src = data.image.dataURL;
|
||||||
image.onload = () => {
|
image.onload = async () => {
|
||||||
tools.stamp.state.addResource(
|
await tools.stamp.state.addResource(
|
||||||
data.image.resourceName || "External Resource",
|
data.image.resourceName || "External Resource",
|
||||||
image
|
image
|
||||||
);
|
);
|
||||||
|
@ -83,6 +90,13 @@
|
||||||
console.warn(`[webui] Unsupported message type: ${data.type}`);
|
console.warn(`[webui] Unsupported message type: ${data.type}`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send acknowledgement
|
||||||
|
parentWindow &&
|
||||||
|
parentWindow.postMessage({
|
||||||
|
type: "ack",
|
||||||
|
message: data,
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(
|
console.warn(
|
||||||
`[webui] Message of type '${data.type}' has invalid format`
|
`[webui] Message of type '${data.type}' has invalid format`
|
||||||
|
|
Loading…
Reference in a new issue