From 242966a8031a75cecdd4ee11e2175f6daa91b545 Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Fri, 20 Mar 2026 15:46:01 -0400 Subject: [PATCH] CommandPalette: Fix starting everything even when its not enabled --- .../characterCounter/index.tsx | 1 + .../commandPalette/registry.tsx | 76 ++++++++++++++----- 2 files changed, 58 insertions(+), 19 deletions(-) diff --git a/src/equicordplugins/characterCounter/index.tsx b/src/equicordplugins/characterCounter/index.tsx index 9a24931db..3f2fb0a10 100644 --- a/src/equicordplugins/characterCounter/index.tsx +++ b/src/equicordplugins/characterCounter/index.tsx @@ -60,6 +60,7 @@ export default definePlugin({ else color = "var(--red-360)"; } + if (!length) return null; return (
{length}/ diff --git a/src/equicordplugins/commandPalette/registry.tsx b/src/equicordplugins/commandPalette/registry.tsx index 079f9c54e..ea1616940 100644 --- a/src/equicordplugins/commandPalette/registry.tsx +++ b/src/equicordplugins/commandPalette/registry.tsx @@ -30,7 +30,8 @@ import { type CustomCommandIconId, getCustomCommandIconById, isCustomCommandIconId, - resolveCustomCommandDefaultIconId } from "./customCommandIcons"; + resolveCustomCommandDefaultIconId +} from "./customCommandIcons"; import { createExtensionsState, EXTENSIONS_CATALOG_CATEGORY_ID, @@ -232,15 +233,6 @@ interface WindowWithDiscordNative extends Window { DiscordNative?: DiscordNativeLike; } -interface ChannelClosePayloadLike { - channel?: unknown; - channel_id?: string; - recipients?: unknown; - rawRecipients?: unknown; - type?: unknown; - id?: unknown; -} - interface ChannelStoreAccessorMixins { getDMFromUserId?: (id: string) => string | null; getSortedPrivateChannels?: () => Array; @@ -254,13 +246,6 @@ const CHATBAR_DATA_ATTRIBUTE = "data-vc-command-palette-id"; const categories = new Map(); const registry = new Map(); -const registryStore = createRegistryStore(); -const recentsStore = createRecentsStore(() => registryStore.bumpRegistryVersion()); -const pinsStore = createPinsStore(); -const extensionsState = createExtensionsState( - id => refreshContextProvider(id), - () => registryStore.bumpRegistryVersion() -); const StatusSetting = getUserSettingLazy("status", "status"); const COMMAND_PALETTE_PLUGIN_NAME = "CommandPalette"; const logger = new Logger(COMMAND_PALETTE_PLUGIN_NAME); @@ -1266,6 +1251,7 @@ function ensureSessionHooks() { } export function cleanupCommandPaletteRuntime() { + const registryStore = createRegistryStore(); clearScheduledStatusReset(false); while (sessionCleanupCallbacks.length) { const callback = sessionCleanupCallbacks.pop(); @@ -1316,10 +1302,14 @@ export function getCategoryGroupLabel(categoryId?: string): string { } export function getRecentRank(commandId: string): number { + const registryStore = createRegistryStore(); + const recentsStore = createRecentsStore(() => registryStore.bumpRegistryVersion()); return recentsStore.list().indexOf(commandId); } function refreshContextProvider(id: string) { + const pinsStore = createPinsStore(); + const record = contextProviders.get(id); if (!record) return; @@ -1394,6 +1384,8 @@ type RemoveCommandOptions = { }; function removeCommand(commandId: string, options?: RemoveCommandOptions) { + const registryStore = createRegistryStore(); + const pinsStore = createPinsStore(); const existing = registry.get(commandId); if (!existing) return; @@ -1424,18 +1416,38 @@ export function getCommandById(commandId: string): CommandEntry | undefined { } export function listExtensions(): ExtensionDefinition[] { + const registryStore = createRegistryStore(); + const extensionsState = createExtensionsState( + id => refreshContextProvider(id), + () => registryStore.bumpRegistryVersion() + ); return extensionsState.listExtensions().map(extension => ({ ...extension })); } export function isExtensionInstalled(extensionId: string): boolean { + const registryStore = createRegistryStore(); + const extensionsState = createExtensionsState( + id => refreshContextProvider(id), + () => registryStore.bumpRegistryVersion() + ); return extensionsState.isInstalled(extensionId); } export async function installExtension(extensionId: string): Promise { + const registryStore = createRegistryStore(); + const extensionsState = createExtensionsState( + id => refreshContextProvider(id), + () => registryStore.bumpRegistryVersion() + ); return extensionsState.install(extensionId); } export async function uninstallExtension(extensionId: string): Promise { + const registryStore = createRegistryStore(); + const extensionsState = createExtensionsState( + id => refreshContextProvider(id), + () => registryStore.bumpRegistryVersion() + ); return extensionsState.uninstall(extensionId); } @@ -1449,6 +1461,8 @@ function computeSearchText(entry: CommandEntry) { } function recordRecent(commandId: string) { + const registryStore = createRegistryStore(); + const recentsStore = createRecentsStore(() => registryStore.bumpRegistryVersion()); void recentsStore.record(commandId); } @@ -1458,6 +1472,8 @@ export function markCommandAsRecent(commandId: string) { } export function getRecentCommands(): CommandEntry[] { + const registryStore = createRegistryStore(); + const recentsStore = createRecentsStore(() => registryStore.bumpRegistryVersion()); const results: CommandEntry[] = []; for (const id of recentsStore.list()) { const entry = registry.get(id); @@ -1467,6 +1483,8 @@ export function getRecentCommands(): CommandEntry[] { } function getNewestRecentCommand(excludeId?: string): CommandEntry | undefined { + const registryStore = createRegistryStore(); + const recentsStore = createRecentsStore(() => registryStore.bumpRegistryVersion()); const id = recentsStore.newest(excludeId); if (!id) return undefined; const entry = registry.get(id); @@ -1475,6 +1493,7 @@ function getNewestRecentCommand(excludeId?: string): CommandEntry | undefined { } async function prunePinned() { + const pinsStore = createPinsStore(); let changed = false; for (const id of pinsStore.values()) { if (!registry.has(id)) { @@ -1488,8 +1507,6 @@ async function prunePinned() { return changed; } -void pinsStore.ready.then(() => pinsStore.emit()); - const BUILT_IN_COMMANDS: CommandEntry[] = [ { id: "open-equicord-settings", @@ -1534,6 +1551,7 @@ const settingsCommandsByRoute = new Map { + const pinsStore = createPinsStore(); await pinsStore.ready; if (!commandId) return null; @@ -1684,6 +1708,7 @@ export async function togglePinned(commandId: string): Promise { } export function subscribePinned(listener: (pins: Set) => void) { + const pinsStore = createPinsStore(); return pinsStore.subscribe(listener); } @@ -1708,6 +1733,7 @@ function collectCategoryTreeIds(rootId: string): Set { } export function listCommandsInTree(categoryId: string): CommandEntry[] { + const registryStore = createRegistryStore(); const treeCommandCache = registryStore.getTreeCommandCache(); const cached = treeCommandCache.get(categoryId); if (cached) return cached; @@ -1719,10 +1745,12 @@ export function listCommandsInTree(categoryId: string): CommandEntry[] { } export function getCommandSearchText(commandId: string): string { + const registryStore = createRegistryStore(); return registryStore.getCommandSearchText(commandId); } export function getRegistryVersion(): number { + const registryStore = createRegistryStore(); return registryStore.getRegistryVersion(); } @@ -1740,6 +1768,7 @@ export function getCommandTagIds(commandId: string): string[] { } export function subscribeRegistry(listener: (version: number) => void) { + const registryStore = createRegistryStore(); return registryStore.subscribeRegistry(listener); } @@ -1796,6 +1825,9 @@ export async function executeCommandAction(entry: CommandEntry, actionKey: strin : resolvedAction?.action.handler; if (!action) return false; + const registryStore = createRegistryStore(); + const recentsStore = createRecentsStore(() => registryStore.bumpRegistryVersion()); + try { await action(); await recentsStore.record(entry.id); @@ -3760,6 +3792,12 @@ function registerCustomizationCommands() { export function registerBuiltInCommands() { if (builtInsRegistered) return; + const registryStore = createRegistryStore(); + const pinsStore = createPinsStore(); + const extensionsState = createExtensionsState( + id => refreshContextProvider(id), + () => registryStore.bumpRegistryVersion() + ); for (const category of BUILT_IN_CATEGORIES) { registerCategory(category);