Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 43 additions & 11 deletions js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -1919,8 +1919,9 @@ class Activity {
// Queue and take first step.
if (!this.turtles.running()) {
this.logo.runLogoCommands();
document.getElementById("stop").style.color =
this.toolbar.stopIconColorWhenPlaying;
document.getElementById(
"stop"
).style.color = this.toolbar.stopIconColorWhenPlaying;
}
this.logo.step();
} else {
Expand Down Expand Up @@ -2245,8 +2246,9 @@ class Activity {
i < this.palettes.dict[this.palettes.activePalette].protoList.length;
i++
) {
const name =
this.palettes.dict[this.palettes.activePalette].protoList[i]["name"];
const name = this.palettes.dict[this.palettes.activePalette].protoList[i][
"name"
];
if (name in obj["FLOWPLUGINS"]) {
// eslint-disable-next-line no-console
console.log("deleting " + name);
Expand Down Expand Up @@ -2758,6 +2760,11 @@ class Activity {
let lastActivity = Date.now();
let isIdle = false;

// Prevent duplicate intervals
if (this._idleWatcherIntervalId) {
clearInterval(this._idleWatcherIntervalId);
}

// Wake up function - restores full framerate
const resetIdleTimer = () => {
lastActivity = Date.now();
Expand All @@ -2769,6 +2776,9 @@ class Activity {
}
};

// Store reset handler for cleanup
this._resetIdleTimer = resetIdleTimer;

// Track user activity
window.addEventListener("mousemove", resetIdleTimer);
window.addEventListener("mousedown", resetIdleTimer);
Expand All @@ -2777,7 +2787,7 @@ class Activity {
window.addEventListener("wheel", resetIdleTimer);

// Periodic check for idle state
setInterval(() => {
this._idleWatcherIntervalId = setInterval(() => {
// Check if music/code is playing
const isMusicPlaying = this.logo?._alreadyRunning || false;

Expand All @@ -2799,6 +2809,26 @@ class Activity {
}
};

/**
* Cleans up the Idle Watcher resources.
* Clears the interval and removes event listeners to prevent memory leaks.
* This method can be called when the activity is being destroyed or reset.
*/
this.cleanupIdleWatcher = function () {
if (this._idleWatcherIntervalId) {
clearInterval(this._idleWatcherIntervalId);
this._idleWatcherIntervalId = null;
}

if (this._resetIdleTimer) {
window.removeEventListener("mousemove", this._resetIdleTimer);
window.removeEventListener("mousedown", this._resetIdleTimer);
window.removeEventListener("keydown", this._resetIdleTimer);
window.removeEventListener("touchstart", this._resetIdleTimer);
window.removeEventListener("wheel", this._resetIdleTimer);
}
};

/*
* Creates and renders error message containers with appropriate artwork.
* Some error messages have special artwork.
Expand Down Expand Up @@ -5204,8 +5234,9 @@ class Activity {
}
}
staffBlocksMap[staffIndex].baseBlocks[0][0][firstnammedo][4][0] = blockId;
staffBlocksMap[staffIndex].baseBlocks[repeatId.end][0][endnammedo][4][1] =
null;
staffBlocksMap[staffIndex].baseBlocks[repeatId.end][0][
endnammedo
][4][1] = null;

blockId += 2;
} else {
Expand Down Expand Up @@ -5273,8 +5304,9 @@ class Activity {
prevnameddo
][4][1] = blockId;
} else {
staffBlocksMap[staffIndex].repeatBlock[prevrepeatnameddo][4][3] =
blockId;
staffBlocksMap[staffIndex].repeatBlock[
prevrepeatnameddo
][4][3] = blockId;
}
if (afternamedo !== -1) {
staffBlocksMap[staffIndex].baseBlocks[repeatId.end][0][
Expand Down Expand Up @@ -6149,8 +6181,8 @@ class Activity {
let customName = "custom";
if (myBlock.connections[1] !== null) {
// eslint-disable-next-line max-len
customName =
this.blocks.blockList[myBlock.connections[1]].value;
customName = this.blocks.blockList[myBlock.connections[1]]
.value;
}
// eslint-disable-next-line no-console
console.log(customName);
Expand Down
Loading