diff --git a/static/scripts/config-parser.ts b/static/scripts/config-parser.ts index 8820503..8f3ac27 100644 --- a/static/scripts/config-parser.ts +++ b/static/scripts/config-parser.ts @@ -115,9 +115,7 @@ export class ConfigParser { return YAML.parse(`${this.newConfigYml}`); } - async updateConfig(org: string, octokit: Octokit, option: "add" | "remove", path = CONFIG_FULL_PATH, repo = CONFIG_ORG_REPO) { - this.repoConfig = this.newConfigYml; - this.saveConfig(); + async updateConfig(org: string, octokit: Octokit, path = CONFIG_FULL_PATH, repo = CONFIG_ORG_REPO) { return this.createOrUpdateFileContents(org, repo, path, octokit); } @@ -151,8 +149,7 @@ export class ConfigParser { } addPlugin(plugin: Plugin) { - const config = this.loadConfig(); - const parsedConfig = this.parseConfig(config); + const parsedConfig = this.parseConfig(this.repoConfig); parsedConfig.plugins ??= []; const existingPlugin = parsedConfig.plugins.find((p) => p.uses[0].plugin === plugin.uses[0].plugin); @@ -163,12 +160,12 @@ export class ConfigParser { } this.newConfigYml = YAML.stringify(parsedConfig); + this.repoConfig = this.newConfigYml; this.saveConfig(); } removePlugin(plugin: Plugin) { - const config = this.loadConfig(); - const parsedConfig = this.parseConfig(config); + const parsedConfig = this.parseConfig(this.repoConfig); if (!parsedConfig.plugins) { toastNotification("No plugins found in config", { type: "error" }); return; @@ -176,6 +173,7 @@ export class ConfigParser { parsedConfig.plugins = parsedConfig.plugins.filter((p: Plugin) => p.uses[0].plugin !== plugin.uses[0].plugin); this.newConfigYml = YAML.stringify(parsedConfig); + this.repoConfig = this.newConfigYml; this.saveConfig(); } diff --git a/static/scripts/rendering/plugin-select.ts b/static/scripts/rendering/plugin-select.ts index c8ce75b..a7ee070 100644 --- a/static/scripts/rendering/plugin-select.ts +++ b/static/scripts/rendering/plugin-select.ts @@ -5,7 +5,7 @@ import { STRINGS } from "../../utils/strings"; import { ManifestRenderer } from "../render-manifest"; import { renderConfigEditor } from "./config-editor"; import { controlButtons } from "./control-buttons"; -import { closeAllSelect, updateGuiTitle } from "./utils"; +import { closeAllSelect, normalizePluginName, updateGuiTitle } from "./utils"; /** * Renders a dropdown of plugins taken from the marketplace with an installed indicator. @@ -62,9 +62,8 @@ export function renderPluginSelector(renderer: ManifestRenderer): void { if (!cleanManifestCache[url]?.name) { return; } - - const [, repo] = url.replace("https://raw.githubusercontent.com/", "").split("/"); - const reg = new RegExp(`${repo}`, "gi"); + const normalizedName = normalizePluginName(cleanManifestCache[url].name); + const reg = new RegExp(normalizedName, "i"); const installedPlugin: Plugin | undefined = installedPlugins.find((plugin) => plugin.uses[0].plugin.match(reg)); const defaultForInstalled: ManifestPreDecode | null = cleanManifestCache[url]; const optionText = defaultForInstalled.name; diff --git a/static/scripts/rendering/utils.ts b/static/scripts/rendering/utils.ts index 9789aa9..39604a7 100644 --- a/static/scripts/rendering/utils.ts +++ b/static/scripts/rendering/utils.ts @@ -52,8 +52,5 @@ export function removeTrackedEventListener(target: EventTarget, type: string, li } export function getTrackedEventListeners(target: EventTarget, type: string): EventListener[] { - if (eventListenersMap.has(target)) { - return eventListenersMap.get(target)?.get(type) || []; - } - return []; + return eventListenersMap.get(target)?.get(type) || []; } diff --git a/static/scripts/rendering/write-add-remove.ts b/static/scripts/rendering/write-add-remove.ts index 5abe271..b338a6c 100644 --- a/static/scripts/rendering/write-add-remove.ts +++ b/static/scripts/rendering/write-add-remove.ts @@ -93,7 +93,7 @@ function handleAddPlugin(renderer: ManifestRenderer, plugin: Plugin, pluginManif } try { - await renderer.configParser.updateConfig(org, octokit, "add"); + await renderer.configParser.updateConfig(org, octokit); } catch (error) { console.error("Error pushing config to GitHub:", error); toastNotification("An error occurred while pushing the configuration to GitHub.", { @@ -129,7 +129,7 @@ function handleRemovePlugin(renderer: ManifestRenderer, plugin: Plugin, pluginMa } try { - await renderer.configParser.updateConfig(org, octokit, "remove"); + await renderer.configParser.updateConfig(org, octokit); } catch (error) { console.error("Error pushing config to GitHub:", error); toastNotification("An error occurred while pushing the configuration to GitHub.", {