Skip to content

Commit b9236d7

Browse files
committed
Get it to hide links when someone clicks on the new "eye" button on the new ComfyUI layout.
1 parent d35220d commit b9236d7

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

js/CircuitBoardLines.js

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ function clipT(num, denom, c) {
3939
return 1;
4040
}
4141
/**
42-
* @param {Point} a
43-
* @param {Point} b
44-
* @param {BoundingBox} box [xmin, ymin, xmax, ymax]
45-
* @param {Point?} [da]
46-
* @param {Point?} [db]
42+
* @param {Point} a
43+
* @param {Point} b
44+
* @param {BoundingBox} box [xmin, ymin, xmax, ymax]
45+
* @param {Point?} [da]
46+
* @param {Point?} [db]
4747
* @return {number}
4848
*/
4949
function liangBarsky(a, b, box, da, db) {
@@ -714,16 +714,60 @@ class MapLinks {
714714
}
715715
}
716716

717+
class EyeButton {
718+
constructor() {
719+
this.hidden = null;
720+
}
721+
722+
static getEyeButton() {
723+
const eyeButtons = document.querySelectorAll('.pi-eye,.pi-eye-slash');
724+
if (eyeButtons.length > 1) {
725+
console.log('found too many eye buttons', eyeButtons); // eslint-disable-line no-console
726+
}
727+
return eyeButtons[0];
728+
}
729+
730+
check() {
731+
const eyeButton = EyeButton.getEyeButton();
732+
if (!eyeButton) {
733+
return;
734+
}
735+
const hidden = eyeButton.classList.contains('pi-eye-slash');
736+
if (this.hidden !== hidden) {
737+
this.hidden = hidden;
738+
if (this.onChange) {
739+
this.onChange(hidden);
740+
}
741+
}
742+
}
743+
744+
listenEyeButton(onChange) {
745+
this.onChange = onChange;
746+
const eyeButton = EyeButton.getEyeButton();
747+
if (!eyeButton) {
748+
setTimeout(() => this.listenEyeButton(onChange), 1000);
749+
return;
750+
}
751+
const eyeDom = eyeButton.parentNode;
752+
eyeDom.addEventListener('click', () => this.check());
753+
eyeDom.addEventListener('keyup', () => this.check());
754+
eyeDom.addEventListener('mouseup', () => this.check());
755+
}
756+
}
757+
717758
export class CircuitBoardLines {
718759
constructor() {
719760
this.canvas = null;
720761
this.mapLinks = null;
721762
this.enabled = true;
763+
this.eyeHidden = false;
722764
this.maxDirectLineDistance = Number.MAX_SAFE_INTEGER;
723765
}
724766

725767
setEnabled(e) { this.enabled = e; }
726768

769+
isShow() { return this.enabled && !this.eyeHidden; }
770+
727771
recalcMapLinksTimeout() {
728772
// calculate paths when user is idle...
729773
if (!this.skipNextRecalcTimeout) {
@@ -798,13 +842,17 @@ export class CircuitBoardLines {
798842
LGraphCanvas.prototype.drawConnections = function drawConnections(
799843
ctx,
800844
) {
801-
if (t.canvas && t.enabled) {
845+
if (t.canvas && t.isShow()) {
802846
return t.drawConnections(
803847
ctx,
804848
);
805849
}
806850
return oldDrawConnections.apply(this, arguments);
807851
};
852+
this.eyeButton = new EyeButton();
853+
this.eyeButton.listenEyeButton((hidden) => {
854+
this.eyeHidden = hidden;
855+
});
808856
}
809857

810858
initOverrides(canvas) {

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "quick-connections"
33
description = "Quick connections, Circuit board connections"
4-
version = "1.0.14"
4+
version = "1.0.15"
55
license = {text = "MIT License"}
66

77
[project.urls]

0 commit comments

Comments
 (0)