Skip to content

Commit

Permalink
Merge pull request #130 from cgiesche/streamdeck-homeassistant-128
Browse files Browse the repository at this point in the history
Fixed #128: Memory leak
  • Loading branch information
cgiesche committed Jan 27, 2023
2 parents 254575c + bc0f759 commit c2899f5
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/modules/plugin/svgUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ export class SvgUtils {
"stroke": "#000",
"strokeWidth": 4,
}

this.snap = Snap(this.buttonRes, this.buttonRes);
}

generateButtonSVG(labels, iconSVG, iconColor, isAction = false, isMultiAction = false) {

const s = Snap(this.buttonRes, this.buttonRes);

const text = (text, lineNr) => {
s.text(0, 26 + lineNr * 36, text)
this.snap.text(0, 26 + lineNr * 36, text)
.attr(this.lineAttr)
.transform(`translateX(${this.halfRes})`);
}

s.rect(0, 0, this.buttonRes, this.buttonRes).attr({fill: this.buttonBgColor})
this.snap.rect(0, 0, this.buttonRes, this.buttonRes).attr({fill: this.buttonBgColor})

if (iconSVG) {
const icon = s.path(iconSVG)
const icon = this.snap.path(iconSVG)
icon.attr("fill", iconColor);
const iconBBox = icon.getBBox();
const iconHeight = iconBBox.height;
Expand All @@ -43,7 +43,7 @@ export class SvgUtils {

if (isAction) {
const color = isMultiAction ? "#3e89ff" : "#62ff65"
s.circle(this.buttonRes - 1, 0, 15).attr("fill", color)
this.snap.circle(this.buttonRes - 1, 0, 15).attr("fill", color)
}

for (let i = 0; i < labels.length; i++) {
Expand All @@ -58,7 +58,9 @@ export class SvgUtils {
// s.line(0, this.halfRes / 2, this.buttonRes, this.halfRes / 2).attr("stroke", "#FFFFFF")
// s.line(0, this.halfRes * 1.5, this.buttonRes, this.halfRes * 1.5).attr("stroke", "#FFFFFF")

return s.outerSVG()
let outerSVG = this.snap.outerSVG();
this.snap.clear();
return outerSVG
}

}

0 comments on commit c2899f5

Please sign in to comment.