From 39c66749c22907d54b30621e676c4e4ac31389cf Mon Sep 17 00:00:00 2001 From: rgthree Date: Thu, 30 Nov 2023 23:41:46 -0500 Subject: [PATCH] Make showing the UI for corrupt links optional and off by default. It can be a power-user thing. --- rgthree_config.json.default | 3 +- ts/rgthree.ts | 69 ++++++++++++++++++++---------------- web/rgthree.js | 70 +++++++++++++++++++++---------------- 3 files changed, 81 insertions(+), 61 deletions(-) diff --git a/rgthree_config.json.default b/rgthree_config.json.default index c2d7137..f01a71d 100644 --- a/rgthree_config.json.default +++ b/rgthree_config.json.default @@ -1,7 +1,8 @@ // COPY THIS FILE BEFORE MAKING CHANGES TO: rgthree_config.json { "patch_recursive_execution": true, - "monitor_bad_links": false, + "show_corrupt_link_alerts": false, + "monitor_for_corrupt_links": false, "nodes": { "reroute": { "default_width": 40, diff --git a/ts/rgthree.ts b/ts/rgthree.ts index 6f8a957..47454bc 100644 --- a/ts/rgthree.ts +++ b/ts/rgthree.ts @@ -233,39 +233,48 @@ class Rgthree { const graphToUse = wasLoadingAborted ? (graphCopy || graph) : app.graph const fixBadLinksResult = fixBadLinks(graphToUse); if (fixBadLinksResult.hasBadLinks) { - that.showMessage({ - id: 'bad-links', - type: 'warn', - message: 'The workflow you\'ve loaded may have connection/linking data that could be fixed.', - actions: [ - { - label: 'Open fixer', - href: '/extensions/rgthree-comfy/html/links.html', - }, - { - label: 'Fix in place', - href: '/extensions/rgthree-comfy/html/links.html', - callback: (event) => { - event.stopPropagation(); - event.preventDefault(); - if (confirm('This will attempt to fix in place. Please make sure to have a saved copy of your workflow.')) { - const fixBadLinksResult = fixBadLinks(graphToUse, true); - if (!fixBadLinksResult.hasBadLinks) { - that.hideMessage('bad-links'); - alert('Success! It\'s possible some valid links may have been affected. Please check and verify your workflow.'); - wasLoadingAborted && app.loadGraphData(fixBadLinksResult.graph); - if (rgthreeConfig['monitor_bad_links']) { - that.monitorLinkTimeout = setTimeout(() => { - that.monitorBadLinks(); - }, 5000); + that.log(LogLevel.WARN, `The workflow you've loaded has corrupt linking data. Open ${new URL(location.href).origin}/extensions/rgthree-comfy/html/links.html to try to fix.`); + if (rgthreeConfig['show_corrupt_link_alerts']) { + that.showMessage({ + id: 'bad-links', + type: 'warn', + message: 'The workflow you\'ve loaded has corrupt linking data that may be able to be fixed.', + actions: [ + { + label: 'Open fixer', + href: '/extensions/rgthree-comfy/html/links.html', + }, + { + label: 'Fix in place', + href: '/extensions/rgthree-comfy/html/links.html', + callback: (event) => { + event.stopPropagation(); + event.preventDefault(); + if (confirm('This will attempt to fix in place. Please make sure to have a saved copy of your workflow.')) { + try { + const fixBadLinksResult = fixBadLinks(graphToUse, true); + if (!fixBadLinksResult.hasBadLinks) { + that.hideMessage('bad-links'); + alert('Success! It\'s possible some valid links may have been affected. Please check and verify your workflow.'); + wasLoadingAborted && app.loadGraphData(fixBadLinksResult.graph); + if (rgthreeConfig['monitor_for_corrupt_links'] || rgthreeConfig['monitor_bad_links']) { + that.monitorLinkTimeout = setTimeout(() => { + that.monitorBadLinks(); + }, 5000); + } + } + } catch(e) { + console.error(e); + alert('Unsuccessful at fixing corrupt data. :('); + that.hideMessage('bad-links'); } } } - } - }, - ] - }); - } else if (rgthreeConfig['monitor_bad_links']) { + }, + ] + }); + } + } else if (rgthreeConfig['monitor_for_corrupt_links'] || rgthreeConfig['monitor_bad_links']) { that.monitorLinkTimeout = setTimeout(() => { that.monitorBadLinks(); }, 5000); diff --git a/web/rgthree.js b/web/rgthree.js index 178b7eb..9af0dc5 100644 --- a/web/rgthree.js +++ b/web/rgthree.js @@ -179,40 +179,50 @@ class Rgthree { const graphToUse = wasLoadingAborted ? (graphCopy || graph) : app.graph; const fixBadLinksResult = fixBadLinks(graphToUse); if (fixBadLinksResult.hasBadLinks) { - that.showMessage({ - id: 'bad-links', - type: 'warn', - message: 'The workflow you\'ve loaded may have connection/linking data that could be fixed.', - actions: [ - { - label: 'Open fixer', - href: '/extensions/rgthree-comfy/html/links.html', - }, - { - label: 'Fix in place', - href: '/extensions/rgthree-comfy/html/links.html', - callback: (event) => { - event.stopPropagation(); - event.preventDefault(); - if (confirm('This will attempt to fix in place. Please make sure to have a saved copy of your workflow.')) { - const fixBadLinksResult = fixBadLinks(graphToUse, true); - if (!fixBadLinksResult.hasBadLinks) { - that.hideMessage('bad-links'); - alert('Success! It\'s possible some valid links may have been affected. Please check and verify your workflow.'); - wasLoadingAborted && app.loadGraphData(fixBadLinksResult.graph); - if (rgthreeConfig['monitor_bad_links']) { - that.monitorLinkTimeout = setTimeout(() => { - that.monitorBadLinks(); - }, 5000); + that.log(LogLevel.WARN, `The workflow you've loaded has corrupt linking data. Open ${new URL(location.href).origin}/extensions/rgthree-comfy/html/links.html to try to fix.`); + if (rgthreeConfig['show_corrupt_link_alerts']) { + that.showMessage({ + id: 'bad-links', + type: 'warn', + message: 'The workflow you\'ve loaded has corrupt linking data that may be able to be fixed.', + actions: [ + { + label: 'Open fixer', + href: '/extensions/rgthree-comfy/html/links.html', + }, + { + label: 'Fix in place', + href: '/extensions/rgthree-comfy/html/links.html', + callback: (event) => { + event.stopPropagation(); + event.preventDefault(); + if (confirm('This will attempt to fix in place. Please make sure to have a saved copy of your workflow.')) { + try { + const fixBadLinksResult = fixBadLinks(graphToUse, true); + if (!fixBadLinksResult.hasBadLinks) { + that.hideMessage('bad-links'); + alert('Success! It\'s possible some valid links may have been affected. Please check and verify your workflow.'); + wasLoadingAborted && app.loadGraphData(fixBadLinksResult.graph); + if (rgthreeConfig['monitor_for_corrupt_links'] || rgthreeConfig['monitor_bad_links']) { + that.monitorLinkTimeout = setTimeout(() => { + that.monitorBadLinks(); + }, 5000); + } + } + } + catch (e) { + console.error(e); + alert('Unsuccessful at fixing corrupt data. :('); + that.hideMessage('bad-links'); } } } - } - }, - ] - }); + }, + ] + }); + } } - else if (rgthreeConfig['monitor_bad_links']) { + else if (rgthreeConfig['monitor_for_corrupt_links'] || rgthreeConfig['monitor_bad_links']) { that.monitorLinkTimeout = setTimeout(() => { that.monitorBadLinks(); }, 5000);