Skip to content

Commit 2509c44

Browse files
authored
Dropdown-Maker.js -- fix block deletion when ScratchBlocks isnt availiable
1 parent 4eb4117 commit 2509c44

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

extension-code/Dropdown-Maker.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,15 +483,27 @@
483483
}
484484
customMenus = menus;
485485
refreshMagic();
486-
if (typeof scaffolding === "undefined") {
487-
// Remove Menu Blocks that no Longer Exist
488-
const allBlocks = ScratchBlocks.mainWorkspace.blockDB_;
489-
const menuNames = Object.keys(customMenus);
490-
for (const [key, block] of Object.entries(allBlocks)) {
486+
487+
// Remove Menu Blocks that no Longer Exist
488+
const menuNames = Object.keys(customMenus);
489+
if (Scratch.gui) Scratch.gui.getBlockly().then(SB => {
490+
const allBlocks = SB.mainWorkspace.blockDB_;
491+
for (const block of Object.values(allBlocks)) {
491492
if (block.type.startsWith("SP0zMenuMaker_menu_")) {
492493
if (menuNames.indexOf(block.type.replace("SP0zMenuMaker_menu_", "")) === -1) block.dispose();
493494
}
494495
}
496+
});
497+
if (typeof scaffolding === "undefined") {
498+
for (const target of runtime.targets) {
499+
const blockCache = target.blocks;
500+
for (const block of Object.values(blockCache._blocks)) {
501+
if (
502+
block.opcode.startsWith("SP0zMenuMaker_menu_") &&
503+
menuNames.indexOf(block.opcode.replace("SP0zMenuMaker_menu_", "")) === -1
504+
) blockCache.deleteBlock(block.id, true);
505+
}
506+
}
495507
}
496508
} catch { alert("Couldnt Parse Imported Custom Menu JSON") }
497509
}

0 commit comments

Comments
 (0)