fix: 🐛 simplify set/get alerts

Now use the builtin toast api
This commit is contained in:
Mel Massadian 2024-12-23 18:24:54 +01:00
parent cdbd38213f
commit 3c6bb87083
No known key found for this signature in database
GPG Key ID: 1DFF0E9F71C7C85A

View File

@ -28,16 +28,17 @@ function setColorAndBgColor(type) {
this.bgcolor = colors.bgcolor; this.bgcolor = colors.bgcolor;
} }
} }
let isAlertShown = false;
let disablePrefix = app.ui.settings.getSettingValue("KJNodes.disablePrefix") let disablePrefix = app.ui.settings.getSettingValue("KJNodes.disablePrefix")
const LGraphNode = LiteGraph.LGraphNode const LGraphNode = LiteGraph.LGraphNode
function showAlertWithThrottle(message, delay) { function showAlert(message) {
if (!isAlertShown) { message = message || "Set node input undefined."
isAlertShown = true; app.extensionManager.toast.add({
alert(message); severity: 'warn',
setTimeout(() => isAlertShown = false, delay); summary: "KJ Get/Set",
} detail: `${message}. Most likely you're missing custom nodes`,
life: 5000,
})
} }
app.registerExtension({ app.registerExtension({
name: "SetNode", name: "SetNode",
@ -122,7 +123,7 @@ app.registerExtension({
setColorAndBgColor.call(this, type); setColorAndBgColor.call(this, type);
} }
} else { } else {
alert("Error: Set node input undefined. Most likely you're missing custom nodes"); showAlert("missing link info")
} }
} }
if (link_info && node.graph && slotType == 2 && isChangeConnect) { if (link_info && node.graph && slotType == 2 && isChangeConnect) {
@ -134,7 +135,7 @@ app.registerExtension({
this.outputs[0].type = type; this.outputs[0].type = type;
this.outputs[0].name = type; this.outputs[0].name = type;
} else { } else {
alert("Error: Get Set node output undefined. Most likely you're missing custom nodes"); showAlert('node output undefined');
} }
} }
@ -485,7 +486,7 @@ app.registerExtension({
return link; return link;
} else { } else {
const errorMessage = "No SetNode found for " + this.widgets[0].value + "(" + this.type + ")"; const errorMessage = "No SetNode found for " + this.widgets[0].value + "(" + this.type + ")";
showAlertWithThrottle(errorMessage, 5000); showAlert(errorMessage);
//throw new Error(errorMessage); //throw new Error(errorMessage);
} }
} }