fix context menu issues with new plugins being loaded

This commit is contained in:
KingKDot
2026-07-01 09:31:51 -05:00
parent 01ecab779e
commit e0394ea1fa
2 changed files with 32 additions and 0 deletions
+15
View File
@@ -139,6 +139,7 @@ const clearContext = () => {
let _pluginCache = null; let _pluginCache = null;
let _pluginCacheAge = 0; let _pluginCacheAge = 0;
const PLUGIN_CACHE_TTL = 30_000; const PLUGIN_CACHE_TTL = 30_000;
const PLUGIN_CACHE_INVALIDATION_KEY = "overlord_plugin_cache_invalidated_at";
const pluginDashboardBadges = new Map(); const pluginDashboardBadges = new Map();
let pluginDashboardDigest = ""; let pluginDashboardDigest = "";
let pluginDashboardRefreshInFlight = false; let pluginDashboardRefreshInFlight = false;
@@ -153,6 +154,11 @@ async function refreshPluginCache() {
} catch {} } catch {}
} }
function invalidatePluginCache() {
_pluginCache = null;
_pluginCacheAge = 0;
}
function getCachedPlugins() { function getCachedPlugins() {
if (_pluginCache && Date.now() - _pluginCacheAge < PLUGIN_CACHE_TTL) { if (_pluginCache && Date.now() - _pluginCacheAge < PLUGIN_CACHE_TTL) {
return _pluginCache; return _pluginCache;
@@ -935,6 +941,15 @@ async function loadPluginsForClient(clientId) {
} }
} }
window.addEventListener("storage", (event) => {
if (event.key !== PLUGIN_CACHE_INVALIDATION_KEY) return;
invalidatePluginCache();
});
window.addEventListener("overlord:plugins-changed", () => {
invalidatePluginCache();
});
const PREF_LAYOUT_KEY = "overlord_layout"; const PREF_LAYOUT_KEY = "overlord_layout";
let rendererSetLayout = null; let rendererSetLayout = null;
+17
View File
@@ -3,6 +3,14 @@ const fileInput = document.getElementById("file-input");
const pluginList = document.getElementById("plugin-list"); const pluginList = document.getElementById("plugin-list");
const refreshBtn = document.getElementById("refresh-btn"); const refreshBtn = document.getElementById("refresh-btn");
const uploadStatus = document.getElementById("upload-status"); const uploadStatus = document.getElementById("upload-status");
const PLUGIN_CACHE_INVALIDATION_KEY = "overlord_plugin_cache_invalidated_at";
function notifyPluginsChanged() {
try {
localStorage.setItem(PLUGIN_CACHE_INVALIDATION_KEY, String(Date.now()));
} catch {}
window.dispatchEvent(new CustomEvent("overlord:plugins-changed"));
}
async function checkAuth() { async function checkAuth() {
try { try {
@@ -249,6 +257,7 @@ function renderPlugins(plugins) {
setStatus(`Enable failed: ${data?.error || res.statusText}`, true); setStatus(`Enable failed: ${data?.error || res.statusText}`, true);
return; return;
} }
notifyPluginsChanged();
await refresh(); await refresh();
} catch (err) { } catch (err) {
setStatus("Enable failed", true); setStatus("Enable failed", true);
@@ -305,6 +314,7 @@ function renderPlugins(plugins) {
setStatus(`Auto-load toggle failed: ${data?.error || res.statusText}`, true); setStatus(`Auto-load toggle failed: ${data?.error || res.statusText}`, true);
return; return;
} }
notifyPluginsChanged();
await refresh(); await refresh();
}); });
} }
@@ -332,6 +342,7 @@ function renderPlugins(plugins) {
return; return;
} }
setStatus("Plugin removed."); setStatus("Plugin removed.");
notifyPluginsChanged();
await refresh(); await refresh();
}); });
actions.appendChild(toggle); actions.appendChild(toggle);
@@ -405,6 +416,7 @@ function showNeedsApprovalModal(plugin, needs, needsHash, afterApprove) {
} }
overlay.remove(); overlay.remove();
setStatus("Plugin needs approved."); setStatus("Plugin needs approved.");
notifyPluginsChanged();
if (typeof afterApprove === "function") await afterApprove(); if (typeof afterApprove === "function") await afterApprove();
}); });
} }
@@ -463,6 +475,7 @@ function showPluginEnableConfirmModal(plugin, sigInfo) {
okBtn.addEventListener("click", async () => { okBtn.addEventListener("click", async () => {
okBtn.disabled = true; okBtn.disabled = true;
okBtn.textContent = "Enabling..."; okBtn.textContent = "Enabling...";
let enabled = false;
try { try {
const res = await fetch(`/api/plugins/${plugin.id}/enable`, { const res = await fetch(`/api/plugins/${plugin.id}/enable`, {
method: "POST", method: "POST",
@@ -480,11 +493,14 @@ function showPluginEnableConfirmModal(plugin, sigInfo) {
return; return;
} }
setStatus(`Enable failed: ${data?.error || res.statusText}`, true); setStatus(`Enable failed: ${data?.error || res.statusText}`, true);
} else {
enabled = true;
} }
} catch { } catch {
setStatus("Enable failed", true); setStatus("Enable failed", true);
} }
overlay.remove(); overlay.remove();
if (enabled) notifyPluginsChanged();
await refresh(); await refresh();
}); });
@@ -508,6 +524,7 @@ async function uploadFile(file) {
return; return;
} }
setStatus("Upload complete."); setStatus("Upload complete.");
notifyPluginsChanged();
await refresh(); await refresh();
} }