CommandPalette: Fix starting everything even when its not enabled

This commit is contained in:
thororen1234 2026-03-20 15:46:01 -04:00
parent e393dcf49b
commit 242966a803
No known key found for this signature in database
2 changed files with 58 additions and 19 deletions

View file

@ -60,6 +60,7 @@ export default definePlugin({
else color = "var(--red-360)";
}
if (!length) return null;
return (
<div className={cl("counter")} style={{ color }}>
<span className={cl("count")} >{length}</span>/

View file

@ -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<string | { id?: string; channelId?: string; }>;
@ -254,13 +246,6 @@ const CHATBAR_DATA_ATTRIBUTE = "data-vc-command-palette-id";
const categories = new Map<string, CommandCategory>();
const registry = new Map<string, CommandEntry>();
const registryStore = createRegistryStore();
const recentsStore = createRecentsStore(() => registryStore.bumpRegistryVersion());
const pinsStore = createPinsStore();
const extensionsState = createExtensionsState(
id => refreshContextProvider(id),
() => registryStore.bumpRegistryVersion()
);
const StatusSetting = getUserSettingLazy<string>("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<boolean> {
const registryStore = createRegistryStore();
const extensionsState = createExtensionsState(
id => refreshContextProvider(id),
() => registryStore.bumpRegistryVersion()
);
return extensionsState.install(extensionId);
}
export async function uninstallExtension(extensionId: string): Promise<boolean> {
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<string, typeof DISCORD_SETTINGS_COMMANDS
let builtInsRegistered = false;
export function registerCategory(category: CommandCategory) {
const registryStore = createRegistryStore();
const parentId = category.parentId ?? null;
const normalized = { ...category, parentId } satisfies CommandCategory;
const existing = categories.get(category.id);
@ -1575,6 +1593,8 @@ export function getCategoryPath(categoryId?: string): CommandCategory[] {
}
export function registerCommand(entry: CommandEntry) {
const registryStore = createRegistryStore();
const pinsStore = createPinsStore();
const preservePin = pinsStore.has(entry.id);
if (registry.has(entry.id)) {
removeCommand(entry.id, preservePin ? { preservePin: true } : undefined);
@ -1635,6 +1655,7 @@ export function registerCommand(entry: CommandEntry) {
}
export function listCommands(): CommandEntry[] {
const registryStore = createRegistryStore();
const cached = registryStore.getCachedSortedCommands();
if (cached) {
return cached;
@ -1646,6 +1667,7 @@ export function listCommands(): CommandEntry[] {
}
export function listCommandsByCategory(categoryId: string): CommandEntry[] {
const registryStore = createRegistryStore();
const categoryCommandCache = registryStore.getCategoryCommandCache();
const cached = categoryCommandCache.get(categoryId);
if (cached) return cached;
@ -1656,10 +1678,12 @@ export function listCommandsByCategory(categoryId: string): CommandEntry[] {
}
export function isCommandPinned(commandId: string): boolean {
const pinsStore = createPinsStore();
return pinsStore.has(commandId);
}
export async function togglePinned(commandId: string): Promise<boolean | null> {
const pinsStore = createPinsStore();
await pinsStore.ready;
if (!commandId) return null;
@ -1684,6 +1708,7 @@ export async function togglePinned(commandId: string): Promise<boolean | null> {
}
export function subscribePinned(listener: (pins: Set<string>) => void) {
const pinsStore = createPinsStore();
return pinsStore.subscribe(listener);
}
@ -1708,6 +1733,7 @@ function collectCategoryTreeIds(rootId: string): Set<string> {
}
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);