Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

1.4 KB
Raw Blame
import type { FrontendPluginDefinition } from "@/lib/plugins/frontendPlugin";

const PINNED_PLUGINS_STORAGE_KEY = "dbx-plugin-pinned-ids";

export function loadPinnedPluginIds(): string[] {
  try {
    if (typeof localStorage === "undefined") return [];
    const saved = localStorage.getItem(PINNED_PLUGINS_STORAGE_KEY);
    const ids = saved ? JSON.parse(saved) : [];
    return Array.isArray(ids) ? ids.filter((id): id is string => typeof id === "string") : [];
  } catch {
    return [];
  }
}

export function savePinnedPluginIds(ids: string[]): void {
  try {
    if (typeof localStorage === "undefined") return;
    localStorage.setItem(PINNED_PLUGINS_STORAGE_KEY, JSON.stringify(ids));
  } catch {
    // Storage may be unavailable (private mode); pinning just won't persist.
  }
}

/** Stable partition: pinned plugins keep their relative order first, then
 *  the rest follow in their original order. Unknown ids in the pinned list
 *  are ignored so uninstalling a plugin leaves no phantom pins. */
export function sortPluginsPinnedFirst<T extends FrontendPluginDefinition>(definitions: T[], pinnedIds: string[]): T[] {
  const pinned = new Set(pinnedIds);
  const pinnedPart = definitions.filter((definition) => pinned.has(definition.plugin.manifest.id));
  if (pinnedPart.length === 0) return definitions;
  return [...pinnedPart, ...definitions.filter((definition) => !pinned.has(definition.plugin.manifest.id))];
}