Skip to content

Commit

Permalink
overhaul delete plugin code
Browse files Browse the repository at this point in the history
  • Loading branch information
walterbender committed Feb 22, 2021
1 parent e034f59 commit 84adb74
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
55 changes: 44 additions & 11 deletions js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -1477,21 +1477,54 @@ function Activity() {
};

/*
* Removes loaded plugin
* Based on the active palette, remove a plugin palette from local storage.
*/
deletePlugin = function () {
toolbar.closeAuxToolbar(_showHideAuxMenu);
blocks.activeBlock = null;
if (palettes.paletteObject !== null) {
palettes.paletteObject.promptPaletteDelete();
} else {
// look to see if My Blocks palette is visible
if (palettes.buttons["myblocks"].visible) {
// console.debug(palettes.dict["myblocks"].visible);
if (palettes.dict["myblocks"].visible) {
palettes.dict["myblocks"].promptMacrosDelete();
if (palettes.activePalette !== null) {
let obj = JSON.parse(storage.plugins);

if (palettes.activePalette in obj["PALETTEPLUGINS"]) {
delete obj["PALETTEPLUGINS"][palettes.activePalette];
}
if (palettes.activePalette in obj["PALETTEFILLCOLORS"]) {
delete obj["PALETTEFILLCOLORS"][palettes.activePalette];
}
if (palettes.activePalette in obj["PALETTESTROKECOLORS"]) {
delete obj["PALETTESTROKECOLORS"][palettes.activePalette];
}
if (palettes.activePalette in obj["PALETTEHIGHLIGHTCOLORS"]) {
delete obj["PALETTEHIGHLIGHTCOLORS"][palettes.activePalette];
}
for (let i = 0; i < palettes.dict[palettes.activePalette].protoList.length; i++) {
let name = palettes.dict[palettes.activePalette].protoList[i]["name"];
if (name in obj["FLOWPLUGINS"]) {
console.log("deleting " + name);
delete obj["FLOWPLUGINS"][name];
}
if (name in obj["BLOCKPLUGINS"]) {
console.log("deleting " + name);
delete obj["BLOCKPLUGINS"][name];
}
if (name in obj["ARGPLUGINS"]) {
console.log("deleting " + name);
delete obj["ARGPLUGINS"][name];
}
}
if (palettes.activePalette in obj["MACROPLUGINS"]) {
delete obj["MACROPLUGINS"][palettes.activePalette];
}
if (palettes.activePalette in obj["ONLOAD"]) {
delete obj["ONLOAD"][palettes.activePalette];
}
if (palettes.activePalette in obj["ONSTART"]) {
delete obj["ONSTART"][palettes.activePalette];
}
if (palettes.activePalette in obj["ONSTOP"]) {
delete obj["ONSTOP"][palettes.activePalette];
}

storage.plugins = JSON.stringify(obj);
textMsg(palettes.activePalette + " " + _("plugins will be removed upon restart."));
}
};

Expand Down
1 change: 1 addition & 0 deletions js/palette.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ class Palettes {

this.hideSearchWidget(true);
this.dict[name].showMenu(true);
this.activePalette = name; // used to delete plugins
}

_showMenus() {}
Expand Down

0 comments on commit 84adb74

Please sign in to comment.