fix(updates): sync update center state after manual component changes

This commit is contained in:
zipg authored and GitHub committed 2026-09-20 18:43:02 +08:00
1 parent 1ef865008a
commit 4d150fc909
13 files changed
+143 -11

No files matched your search

+11 -2
View File
@@ -27,7 +27,7 @@ import { useTheme } from "@/composables/useTheme";
import { canDownloadAndInstallUpdate, useAppUpdater } from "@/composables/useAppUpdater"; import { canDownloadAndInstallUpdate, useAppUpdater } from "@/composables/useAppUpdater";
import { useMcpUpdateBadge } from "@/composables/useMcpUpdateBadge"; import { useMcpUpdateBadge } from "@/composables/useMcpUpdateBadge";
import { useComponentUpdates, type ComponentUpdateCategory } from "@/composables/useComponentUpdates"; import { useComponentUpdates, type ComponentUpdateCategory } from "@/composables/useComponentUpdates";
import { notifyComponentPluginsUpdated } from "@/lib/updates/componentUpdateEvents"; import { COMPONENT_UPDATES_CHANGED_EVENT, notifyComponentPluginsUpdated, notifyComponentUpdatesChanged } from "@/lib/updates/componentUpdateEvents";
import { driverStoreUpdateBadgeCount, showMcpUpdateBadge } from "@/lib/updates/updateBadges"; import { driverStoreUpdateBadgeCount, showMcpUpdateBadge } from "@/lib/updates/updateBadges";
import { markPendingComponentUpdatesAfterAppUpdate, resolveUpdateAllAction, runPendingComponentUpdatePlan, shouldCloseUpdateCenterAfterComponentUpdate, takePendingComponentUpdatesAfterAppRestart, type PendingComponentUpdatePlan } from "@/lib/updates/componentUpdateOrchestration"; import { markPendingComponentUpdatesAfterAppUpdate, resolveUpdateAllAction, runPendingComponentUpdatePlan, shouldCloseUpdateCenterAfterComponentUpdate, takePendingComponentUpdatesAfterAppRestart, type PendingComponentUpdatePlan } from "@/lib/updates/componentUpdateOrchestration";
import { isUpdatePreviewMockEnabled } from "@/lib/updates/updatePreviewMock"; import { isUpdatePreviewMockEnabled } from "@/lib/updates/updatePreviewMock";
@@ -200,13 +200,14 @@ const savedSqlStore = useSavedSqlStore();
const promptTemplateStore = usePromptTemplateStore(); const promptTemplateStore = usePromptTemplateStore();
const recentConnectionIds = ref<readonly string[]>(parseRecentConnectionIds(safeLocalStorageGet(RECENT_CONNECTION_IDS_STORAGE_KEY))); const recentConnectionIds = ref<readonly string[]>(parseRecentConnectionIds(safeLocalStorageGet(RECENT_CONNECTION_IDS_STORAGE_KEY)));
connectionStore.setBeforeConnectHandler(async (config) => { connectionStore.setBeforeConnectHandler(async (config) => {
await ensureJdbcxRuntimeDrivers(config, api); const jdbcxRuntime = await ensureJdbcxRuntimeDrivers(config, api);
const jdbcProductRuntimeBefore = JSON.stringify({ const jdbcProductRuntimeBefore = JSON.stringify({
connectionString: config.connection_string ?? null, connectionString: config.connection_string ?? null,
driverClass: config.jdbc_driver_class ?? null, driverClass: config.jdbc_driver_class ?? null,
driverPaths: config.jdbc_driver_paths ?? [], driverPaths: config.jdbc_driver_paths ?? [],
}); });
const jdbcProductRuntime = await ensureRegisteredJdbcProductRuntimeDrivers(config, api); const jdbcProductRuntime = await ensureRegisteredJdbcProductRuntimeDrivers(config, api);
if (jdbcxRuntime || jdbcProductRuntime) notifyComponentUpdatesChanged();
const jdbcProductRuntimeAfter = JSON.stringify({ const jdbcProductRuntimeAfter = JSON.stringify({
connectionString: config.connection_string ?? null, connectionString: config.connection_string ?? null,
driverClass: config.jdbc_driver_class ?? null, driverClass: config.jdbc_driver_class ?? null,
@@ -1234,6 +1235,12 @@ function syncToolbarComponentUpdateState() {
applyMcpStatus(componentUpdates.mcpUpdateAvailable.value); applyMcpStatus(componentUpdates.mcpUpdateAvailable.value);
} }
function handleComponentUpdatesChanged() {
void componentUpdates.refresh({ force: true }).then((refreshed) => {
if (refreshed) syncToolbarComponentUpdateState();
});
}
function reportComponentUpdateResult(result: Awaited<ReturnType<typeof componentUpdates.installCategory>>) { function reportComponentUpdateResult(result: Awaited<ReturnType<typeof componentUpdates.installCategory>>) {
const updatedComponents = [result.drivers > 0 ? t("settings.updateDrivers") : "", result.jdbc ? t("settings.updateJdbc") : "", result.mcp ? t("settings.updateMcp") : "", result.plugins > 0 ? t("settings.updatePlugins") : ""].filter(Boolean); const updatedComponents = [result.drivers > 0 ? t("settings.updateDrivers") : "", result.jdbc ? t("settings.updateJdbc") : "", result.mcp ? t("settings.updateMcp") : "", result.plugins > 0 ? t("settings.updatePlugins") : ""].filter(Boolean);
// Only a clean refresh is authoritative; a failed registry check must not clear stale toolbar state. // Only a clean refresh is authoritative; a failed registry check must not clear stale toolbar state.
@@ -3840,6 +3847,7 @@ onMounted(async () => {
window.addEventListener("blur", handleTabSwitcherWindowBlur); window.addEventListener("blur", handleTabSwitcherWindowBlur);
document.addEventListener("visibilitychange", handleTabSwitcherVisibilityChange); document.addEventListener("visibilitychange", handleTabSwitcherVisibilityChange);
window.addEventListener("dbx-open-driver-store", openDriverStoreFromEvent); window.addEventListener("dbx-open-driver-store", openDriverStoreFromEvent);
window.addEventListener(COMPONENT_UPDATES_CHANGED_EVENT, handleComponentUpdatesChanged);
window.addEventListener("dbx:activate-query-surface", activateQuerySurface); window.addEventListener("dbx:activate-query-surface", activateQuerySurface);
window.addEventListener(OBJECT_BROWSER_SEARCH_FOCUS_EVENT, focusRequestedObjectBrowserSearch); window.addEventListener(OBJECT_BROWSER_SEARCH_FOCUS_EVENT, focusRequestedObjectBrowserSearch);
window.addEventListener("dbx-mcp-status-changed", handleMcpStatusChanged); window.addEventListener("dbx-mcp-status-changed", handleMcpStatusChanged);
@@ -3925,6 +3933,7 @@ onUnmounted(() => {
document.removeEventListener("visibilitychange", handleTabSwitcherVisibilityChange); document.removeEventListener("visibilitychange", handleTabSwitcherVisibilityChange);
tabSwitcherKeyboard.reset(); tabSwitcherKeyboard.reset();
window.removeEventListener("dbx-open-driver-store", openDriverStoreFromEvent); window.removeEventListener("dbx-open-driver-store", openDriverStoreFromEvent);
window.removeEventListener(COMPONENT_UPDATES_CHANGED_EVENT, handleComponentUpdatesChanged);
window.removeEventListener("dbx:activate-query-surface", activateQuerySurface); window.removeEventListener("dbx:activate-query-surface", activateQuerySurface);
window.removeEventListener(OBJECT_BROWSER_SEARCH_FOCUS_EVENT, focusRequestedObjectBrowserSearch); window.removeEventListener(OBJECT_BROWSER_SEARCH_FOCUS_EVENT, focusRequestedObjectBrowserSearch);
window.removeEventListener("dbx-mcp-status-changed", handleMcpStatusChanged); window.removeEventListener("dbx-mcp-status-changed", handleMcpStatusChanged);
@@ -40,6 +40,7 @@ import { translateBackendError } from "@/i18n/backend-errors";
import { runAgentOfflineExportAction } from "@/lib/driverStore/agentOfflineExportFlow"; import { runAgentOfflineExportAction } from "@/lib/driverStore/agentOfflineExportFlow";
import { DRIVER_CATEGORIES, getCategoryForAgentDriver, assertAgentDriverCategoriesComplete } from "@/lib/connection/driver-category-definitions"; import { DRIVER_CATEGORIES, getCategoryForAgentDriver, assertAgentDriverCategoriesComplete } from "@/lib/connection/driver-category-definitions";
import { hasAnyUpdatableDriverMatching, countInstalledDrivers, countAvailableDrivers, partitionDriversByInstallStatus, upgradeAllDriverTypes, upgradeAllMatchesFullUpdateSet, type DriverInstallStatusFilter } from "@/lib/connection/driverListFilter"; import { hasAnyUpdatableDriverMatching, countInstalledDrivers, countAvailableDrivers, partitionDriversByInstallStatus, upgradeAllDriverTypes, upgradeAllMatchesFullUpdateSet, type DriverInstallStatusFilter } from "@/lib/connection/driverListFilter";
import { notifyComponentUpdatesChanged } from "@/lib/updates/componentUpdateEvents";
const { t } = useI18n(); const { t } = useI18n();
const { toast } = useToast(); const { toast } = useToast();
@@ -497,6 +498,7 @@ async function runDriverInstall(dbType: string) {
if (managedResult.drivers) jdbcDrivers.value = managedResult.drivers; if (managedResult.drivers) jdbcDrivers.value = managedResult.drivers;
jdbcMavenBundles.value = managedResult.bundles; jdbcMavenBundles.value = managedResult.bundles;
void loadDriverStoreUsage(); void loadDriverStoreUsage();
notifyComponentUpdatesChanged();
toast(t("driverStore.driverInstallSuccess", { label })); toast(t("driverStore.driverInstallSuccess", { label }));
return; return;
} }
@@ -509,6 +511,7 @@ async function runDriverInstall(dbType: string) {
activeAgentOperationId.value = operationId; activeAgentOperationId.value = operationId;
cancellableAgentInstallDbType.value = dbType; cancellableAgentInstallDbType.value = dbType;
await api.installAgent(dbType, operationId); await api.installAgent(dbType, operationId);
notifyComponentUpdatesChanged();
await refreshAgents(); await refreshAgents();
toast(t("driverStore.driverInstallSuccess", { label })); toast(t("driverStore.driverInstallSuccess", { label }));
} catch (e: any) { } catch (e: any) {
@@ -557,6 +560,7 @@ async function upgradeAll() {
queuedDriverInstalls.value = []; queuedDriverInstalls.value = [];
resetAgentInstallProgress(); resetAgentInstallProgress();
const result = await api.upgradeAllAgents(activeAgentOperationId.value); const result = await api.upgradeAllAgents(activeAgentOperationId.value);
notifyComponentUpdatesChanged();
await refreshAgents(); await refreshAgents();
if (result.cancelled > 0 && result.failed.length === 0) { if (result.cancelled > 0 && result.failed.length === 0) {
toast(t("driverStore.upgradeAllCancelled", { count: result.cancelled })); toast(t("driverStore.upgradeAllCancelled", { count: result.cancelled }));
@@ -613,6 +617,7 @@ async function uninstallDriver(dbType: string) {
if (managedResult.drivers) jdbcDrivers.value = managedResult.drivers; if (managedResult.drivers) jdbcDrivers.value = managedResult.drivers;
jdbcMavenBundles.value = managedResult.bundles; jdbcMavenBundles.value = managedResult.bundles;
void loadDriverStoreUsage(); void loadDriverStoreUsage();
notifyComponentUpdatesChanged();
toast(t("driverStore.driverUninstallSuccess", { label })); toast(t("driverStore.driverUninstallSuccess", { label }));
return; return;
} }
@@ -622,6 +627,7 @@ async function uninstallDriver(dbType: string) {
return; return;
} }
await api.uninstallAgent(dbType); await api.uninstallAgent(dbType);
notifyComponentUpdatesChanged();
await refreshAgents(); await refreshAgents();
toast(t("driverStore.driverUninstallSuccess", { label })); toast(t("driverStore.driverUninstallSuccess", { label }));
} catch (e: any) { } catch (e: any) {
@@ -744,6 +750,7 @@ async function importOfflineZip() {
resetAgentInstallProgress(); resetAgentInstallProgress();
try { try {
const result = await api.importAgentsFromZip(selected, activeAgentOperationId.value); const result = await api.importAgentsFromZip(selected, activeAgentOperationId.value);
notifyComponentUpdatesChanged();
await Promise.all([refreshAgents(), loadJdbcDrivers(), loadJdbcPluginStatus()]); await Promise.all([refreshAgents(), loadJdbcDrivers(), loadJdbcPluginStatus()]);
toastOfflineImportResult(result); toastOfflineImportResult(result);
} catch (e: any) { } catch (e: any) {
@@ -796,6 +803,7 @@ async function importDriverFile(driver: AgentDriverInfo) {
resetAgentInstallProgress(); resetAgentInstallProgress();
try { try {
const result = await api.importAgentsFromZip(selected, activeAgentOperationId.value); const result = await api.importAgentsFromZip(selected, activeAgentOperationId.value);
notifyComponentUpdatesChanged();
await Promise.all([refreshAgents(), loadJdbcDrivers(), loadJdbcPluginStatus()]); await Promise.all([refreshAgents(), loadJdbcDrivers(), loadJdbcPluginStatus()]);
toastOfflineImportResult(result); toastOfflineImportResult(result);
} finally { } finally {
@@ -805,6 +813,7 @@ async function importDriverFile(driver: AgentDriverInfo) {
} else { } else {
await api.importAgentDriver(dbType, selected); await api.importAgentDriver(dbType, selected);
await refreshAgents(); await refreshAgents();
notifyComponentUpdatesChanged();
toast(t("driverStore.driverImportSuccess", { label })); toast(t("driverStore.driverImportSuccess", { label }));
} }
}; };
@@ -1288,6 +1297,7 @@ async function installJdbcPlugin() {
try { try {
jdbcPluginStatus.value = await api.installJdbcPlugin(); jdbcPluginStatus.value = await api.installJdbcPlugin();
emitDriverUpdateCount(); emitDriverUpdateCount();
notifyComponentUpdatesChanged();
toast(t("settings.jdbcPluginInstallSuccess")); toast(t("settings.jdbcPluginInstallSuccess"));
await loadJdbcDrivers(); await loadJdbcDrivers();
} catch (e: any) { } catch (e: any) {
@@ -1318,6 +1328,7 @@ async function installJdbcPluginLocal() {
try { try {
jdbcPluginStatus.value = await api.installJdbcPluginLocal(selected); jdbcPluginStatus.value = await api.installJdbcPluginLocal(selected);
emitDriverUpdateCount(); emitDriverUpdateCount();
notifyComponentUpdatesChanged();
toast(t("settings.jdbcPluginInstallSuccess")); toast(t("settings.jdbcPluginInstallSuccess"));
await loadJdbcDrivers(); await loadJdbcDrivers();
} catch (e: any) { } catch (e: any) {
@@ -1334,6 +1345,7 @@ async function uninstallJdbcPlugin() {
try { try {
jdbcPluginStatus.value = await api.uninstallJdbcPlugin(); jdbcPluginStatus.value = await api.uninstallJdbcPlugin();
emitDriverUpdateCount(); emitDriverUpdateCount();
notifyComponentUpdatesChanged();
toast(t("settings.jdbcPluginUninstallSuccess")); toast(t("settings.jdbcPluginUninstallSuccess"));
await loadJdbcDrivers(); await loadJdbcDrivers();
} catch (e: any) { } catch (e: any) {
@@ -92,6 +92,7 @@ import { configuredDatabaseProductName, connectionConfigFingerprint, databaseInf
import { agentDriverInstallKey, appendAgentDriverUpdateHint, connectionUsesSsh, hasAgentDriverUpdate, showAgentDriverInstallHint, type AgentDriverInstallState, type DriverStoreFocus } from "@/lib/connection/agentDriverInstallHint"; import { agentDriverInstallKey, appendAgentDriverUpdateHint, connectionUsesSsh, hasAgentDriverUpdate, showAgentDriverInstallHint, type AgentDriverInstallState, type DriverStoreFocus } from "@/lib/connection/agentDriverInstallHint";
import { prestoSqlBuiltinDriverPaths } from "@/lib/database/prestoSqlBuiltinDriver"; import { prestoSqlBuiltinDriverPaths } from "@/lib/database/prestoSqlBuiltinDriver";
import { JDBCX_DEFAULT_URL, JDBCX_DRIVER_PROFILE, JDBCX_JDBC_DRIVER_CLASS, ensureJdbcxRuntimeDrivers, isJdbcxRuntimeBundle, isJdbcxRuntimePath, jdbcxHighPrivilegeExtensionsEnabled, setJdbcxHighPrivilegeExtensionsEnabled } from "@/lib/database/jdbcxBuiltinDriver"; import { JDBCX_DEFAULT_URL, JDBCX_DRIVER_PROFILE, JDBCX_JDBC_DRIVER_CLASS, ensureJdbcxRuntimeDrivers, isJdbcxRuntimeBundle, isJdbcxRuntimePath, jdbcxHighPrivilegeExtensionsEnabled, setJdbcxHighPrivilegeExtensionsEnabled } from "@/lib/database/jdbcxBuiltinDriver";
import { notifyComponentUpdatesChanged } from "@/lib/updates/componentUpdateEvents";
import { SQLITE_DATABASE_FILE_EXTENSIONS } from "@/lib/database/databaseFileDetection"; import { SQLITE_DATABASE_FILE_EXTENSIONS } from "@/lib/database/databaseFileDetection";
import { connectionAttemptOriginalErrorMessage, connectionAttemptTimeoutMessage, connectionAttemptTimeoutMs } from "@/lib/connection/connectionAttemptTimeout"; import { connectionAttemptOriginalErrorMessage, connectionAttemptTimeoutMessage, connectionAttemptTimeoutMs } from "@/lib/connection/connectionAttemptTimeout";
import { consulAgentAddressesMatch } from "@/lib/consul/agentTarget"; import { consulAgentAddressesMatch } from "@/lib/consul/agentTarget";
@@ -1964,6 +1965,7 @@ async function ensureRequiredAgentDriverInstalled(config: ConnectionConfig): Pro
const operationId = beginAgentDriverInstall(driverKey, label); const operationId = beginAgentDriverInstall(driverKey, label);
try { try {
await api.installAgent(driverKey, operationId); await api.installAgent(driverKey, operationId);
notifyComponentUpdatesChanged();
await refreshLocalAgentDrivers(); await refreshLocalAgentDrivers();
// A stale promise (cancelled then retried) must not close the retry's dialog. // A stale promise (cancelled then retried) must not close the retry's dialog.
if (agentInstallOperationId.value === operationId) finishAgentDriverInstall(operationId); if (agentInstallOperationId.value === operationId) finishAgentDriverInstall(operationId);
@@ -1999,6 +2001,7 @@ async function ensureRequiredJdbcxDriverInstalled(config: ConnectionConfig): Pro
testResult.value = { ok: true, message: "Installing JDBC plugin..." }; testResult.value = { ok: true, message: "Installing JDBC plugin..." };
}); });
if (!result) return; if (!result) return;
notifyComponentUpdatesChanged();
jdbcMavenBundles.value = result.bundles; jdbcMavenBundles.value = result.bundles;
addJdbcDriverPaths(result.paths); addJdbcDriverPaths(result.paths);
@@ -2012,6 +2015,7 @@ async function ensureRequiredJdbcxDriverInstalled(config: ConnectionConfig): Pro
async function ensureRequiredJdbcProductRuntimeInstalled(config: ConnectionConfig): Promise<void> { async function ensureRequiredJdbcProductRuntimeInstalled(config: ConnectionConfig): Promise<void> {
const result = await ensureRegisteredJdbcProductRuntimeDrivers(config, api); const result = await ensureRegisteredJdbcProductRuntimeDrivers(config, api);
if (!result) return; if (!result) return;
notifyComponentUpdatesChanged();
jdbcMavenBundles.value = result.bundles; jdbcMavenBundles.value = result.bundles;
jdbcDriverPathsInput.value = result.paths.join("\n"); jdbcDriverPathsInput.value = result.paths.join("\n");
@@ -2031,6 +2035,7 @@ async function ensureRequiredGaussdbMJdbcRuntime(config: ConnectionConfig): Prom
if (status.installed && status.compatible) return; if (status.installed && status.compatible) return;
testResult.value = { ok: true, message: t("connection.gaussdbMJdbcPluginInstalling") }; testResult.value = { ok: true, message: t("connection.gaussdbMJdbcPluginInstalling") };
await api.installJdbcPlugin(); await api.installJdbcPlugin();
notifyComponentUpdatesChanged();
} }
async function installSqlServerLegacyCompatibilityComponentIfNeeded(): Promise<boolean> { async function installSqlServerLegacyCompatibilityComponentIfNeeded(): Promise<boolean> {
@@ -2040,6 +2045,7 @@ async function installSqlServerLegacyCompatibilityComponentIfNeeded(): Promise<b
const operationId = beginAgentDriverInstall(SQLSERVER_LEGACY_COMPATIBILITY_DRIVER_KEY, label); const operationId = beginAgentDriverInstall(SQLSERVER_LEGACY_COMPATIBILITY_DRIVER_KEY, label);
try { try {
await api.installAgent(SQLSERVER_LEGACY_COMPATIBILITY_DRIVER_KEY, operationId); await api.installAgent(SQLSERVER_LEGACY_COMPATIBILITY_DRIVER_KEY, operationId);
notifyComponentUpdatesChanged();
await refreshLocalAgentDrivers(); await refreshLocalAgentDrivers();
// A stale promise (cancelled then retried) must not close the retry's dialog. // A stale promise (cancelled then retried) must not close the retry's dialog.
if (agentInstallOperationId.value === operationId) finishAgentDriverInstall(operationId); if (agentInstallOperationId.value === operationId) finishAgentDriverInstall(operationId);
@@ -205,6 +205,7 @@ import {
type McpLaunchConfig, type McpLaunchConfig,
} from "@/lib/mcp/mcpConfigTemplates"; } from "@/lib/mcp/mcpConfigTemplates";
import { beginMcpStatusRequest, mcpUpdateAvailability } from "@/lib/mcp/mcpUpdateStatus"; import { beginMcpStatusRequest, mcpUpdateAvailability } from "@/lib/mcp/mcpUpdateStatus";
import { notifyComponentUpdatesChanged } from "@/lib/updates/componentUpdateEvents";
import { isMcpPolicyMutationBlocked, MCP_CAPABILITY_ROWS, MCP_EXECUTION_MODE_COLUMNS, MCP_TOOL_OPTIONS, mcpExecutionModeFromPolicy, mcpPolicyFieldsForExecutionMode, toggleMcpAllowedToolName, type McpExecutionMode } from "@/lib/mcp/mcpPolicySelection"; import { isMcpPolicyMutationBlocked, MCP_CAPABILITY_ROWS, MCP_EXECUTION_MODE_COLUMNS, MCP_TOOL_OPTIONS, mcpExecutionModeFromPolicy, mcpPolicyFieldsForExecutionMode, toggleMcpAllowedToolName, type McpExecutionMode } from "@/lib/mcp/mcpPolicySelection";
import { isMacOS, isWindows } from "@/lib/backend/platform"; import { isMacOS, isWindows } from "@/lib/backend/platform";
import { combineDataTypeForDatabase, dataTypeLengthInputValue, getDataTypeOptions, getDefaultLengthForType, isDataTypeLengthDisabled, splitDataType } from "@/lib/table/tableStructureEditorState"; import { combineDataTypeForDatabase, dataTypeLengthInputValue, getDataTypeOptions, getDefaultLengthForType, isDataTypeLengthDisabled, splitDataType } from "@/lib/table/tableStructureEditorState";
@@ -3793,6 +3794,7 @@ async function installMcp() {
mcpInstallError.value = false; mcpInstallError.value = false;
// 安装成功后刷新状态 // 安装成功后刷新状态
await refreshMcpStatus(); await refreshMcpStatus();
notifyComponentUpdatesChanged();
} catch (e: any) { } catch (e: any) {
mcpInstallMessage.value = e?.message || String(e); mcpInstallMessage.value = e?.message || String(e);
mcpInstallError.value = true; mcpInstallError.value = true;
@@ -3815,6 +3817,7 @@ async function uninstallMcp() {
try { try {
mcpInstallMessage.value = await uninstallMcpServer(); mcpInstallMessage.value = await uninstallMcpServer();
await refreshMcpStatus(); await refreshMcpStatus();
notifyComponentUpdatesChanged();
} catch (e: any) { } catch (e: any) {
mcpInstallMessage.value = t("settings.mcpUninstallFailed", { error: e?.message || String(e) }); mcpInstallMessage.value = t("settings.mcpUninstallFailed", { error: e?.message || String(e) });
mcpInstallError.value = true; mcpInstallError.value = true;
@@ -19,7 +19,7 @@ import { physicalDropPositionInsideRect } from "@/lib/ai/aiAttachments";
import { createFrontendPluginRegistry, pluginConnectionProviderIcon } from "@/lib/plugins/frontendPlugin"; import { createFrontendPluginRegistry, pluginConnectionProviderIcon } from "@/lib/plugins/frontendPlugin";
import { beaconPluginInstall, buildMarketplacePluginListings, filterMarketplacePluginListings, listingRepositoryCanVerify, marketplaceHomepageUrl, type MarketplacePluginListing } from "@/lib/plugins/pluginMarketplace"; import { beaconPluginInstall, buildMarketplacePluginListings, filterMarketplacePluginListings, listingRepositoryCanVerify, marketplaceHomepageUrl, type MarketplacePluginListing } from "@/lib/plugins/pluginMarketplace";
import { isBatchSelectableListing, runBatch } from "@/lib/plugins/pluginBatch"; import { isBatchSelectableListing, runBatch } from "@/lib/plugins/pluginBatch";
import { COMPONENT_PLUGINS_UPDATED_EVENT } from "@/lib/updates/componentUpdateEvents"; import { COMPONENT_PLUGINS_UPDATED_EVENT, notifyComponentUpdatesChanged } from "@/lib/updates/componentUpdateEvents";
import { formatBytes } from "@/lib/database/serverMetrics"; import { formatBytes } from "@/lib/database/serverMetrics";
import type { PluginCenterFocus } from "@/lib/plugins/pluginCenterNavigation"; import type { PluginCenterFocus } from "@/lib/plugins/pluginCenterNavigation";
import { useConnectionStore } from "@/stores/connectionStore"; import { useConnectionStore } from "@/stores/connectionStore";
@@ -216,6 +216,7 @@ async function installMarketplaceListing(listing: MarketplacePluginListing) {
const result = await installListing(listing); const result = await installListing(listing);
toast(t(listing.status === "update" ? "pluginPlatform.updateSuccess" : "pluginPlatform.installSuccess", { name: result.plugin.manifest.name, version: result.plugin.manifest.version })); toast(t(listing.status === "update" ? "pluginPlatform.updateSuccess" : "pluginPlatform.installSuccess", { name: result.plugin.manifest.name, version: result.plugin.manifest.version }));
installedPlugins.value = await api.listPlugins(); installedPlugins.value = await api.listPlugins();
notifyComponentUpdatesChanged();
selectPlugin(result.plugin.manifest.id); selectPlugin(result.plugin.manifest.id);
} catch (cause) { } catch (cause) {
toast(translateBackendError(t, cause), 8000); toast(translateBackendError(t, cause), 8000);
@@ -223,6 +224,7 @@ async function installMarketplaceListing(listing: MarketplacePluginListing) {
// instance), so re-read the installed list instead of leaving the card on state it may no longer // instance), so re-read the installed list instead of leaving the card on state it may no longer
// describe. // describe.
installedPlugins.value = await api.listPlugins().catch(() => installedPlugins.value); installedPlugins.value = await api.listPlugins().catch(() => installedPlugins.value);
notifyComponentUpdatesChanged();
} finally { } finally {
marketplaceInstallingKey.value = ""; marketplaceInstallingKey.value = "";
} }
@@ -325,6 +327,7 @@ async function runBatchInstallUpdate() {
clearBatchSelection(); clearBatchSelection();
reportBatchSummary(outcome); reportBatchSummary(outcome);
await refreshAfterBatch(); await refreshAfterBatch();
notifyComponentUpdatesChanged();
} finally { } finally {
batchRunning.value = false; batchRunning.value = false;
} }
@@ -348,6 +351,7 @@ async function runBatchUninstall() {
clearBatchSelection(); clearBatchSelection();
reportBatchSummary(outcome); reportBatchSummary(outcome);
await refreshAfterBatch(); await refreshAfterBatch();
notifyComponentUpdatesChanged();
} finally { } finally {
batchRunning.value = false; batchRunning.value = false;
} }
@@ -543,6 +547,7 @@ async function finishInstall(result: PluginInstallResult) {
toast(t("pluginPlatform.installSuccess", { name: result.plugin.manifest.name, version: result.plugin.manifest.version })); toast(t("pluginPlatform.installSuccess", { name: result.plugin.manifest.name, version: result.plugin.manifest.version }));
clearPluginIconCache(); clearPluginIconCache();
installedPlugins.value = await api.listPlugins(); installedPlugins.value = await api.listPlugins();
notifyComponentUpdatesChanged();
selectPlugin(result.plugin.manifest.id); selectPlugin(result.plugin.manifest.id);
activeSection.value = "installed"; activeSection.value = "installed";
} }
@@ -689,6 +694,7 @@ async function rollbackSelectedPlugin() {
toast(t("pluginPlatform.rollbackSuccess", { version: result.plugin.manifest.version })); toast(t("pluginPlatform.rollbackSuccess", { version: result.plugin.manifest.version }));
clearPluginIconCache(); clearPluginIconCache();
installedPlugins.value = await api.listPlugins(); installedPlugins.value = await api.listPlugins();
notifyComponentUpdatesChanged();
selectPlugin(result.plugin.manifest.id); selectPlugin(result.plugin.manifest.id);
} catch (cause) { } catch (cause) {
toast(translateBackendError(t, cause), 8000); toast(translateBackendError(t, cause), 8000);
@@ -703,6 +709,7 @@ async function uninstallSelectedPlugin() {
operating.value = true; operating.value = true;
try { try {
installedPlugins.value = await api.uninstallPlugin(definition.plugin.manifest.id); installedPlugins.value = await api.uninstallPlugin(definition.plugin.manifest.id);
notifyComponentUpdatesChanged();
clearPluginIconCache(); clearPluginIconCache();
toast(t("pluginPlatform.uninstallSuccess", { name: definition.plugin.manifest.name })); toast(t("pluginPlatform.uninstallSuccess", { name: definition.plugin.manifest.name }));
selectFirstProvider(); selectFirstProvider();
@@ -5,7 +5,7 @@ import { readFileSync } from "node:fs";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { InstalledPlugin, PluginRepositoryCatalogResult } from "@/types/database"; import type { InstalledPlugin, PluginRepositoryCatalogResult } from "@/types/database";
import type { MarketplacePluginListing } from "@/lib/plugins/pluginMarketplace"; import type { MarketplacePluginListing } from "@/lib/plugins/pluginMarketplace";
import { COMPONENT_PLUGINS_UPDATED_EVENT } from "@/lib/updates/componentUpdateEvents"; import { COMPONENT_PLUGINS_UPDATED_EVENT, COMPONENT_UPDATES_CHANGED_EVENT } from "@/lib/updates/componentUpdateEvents";
const mocks = vi.hoisted(() => ({ const mocks = vi.hoisted(() => ({
listPlugins: vi.fn(), listPlugins: vi.fn(),
@@ -246,6 +246,24 @@ describe("PluginContributionsPanel batch source validation", () => {
}); });
}); });
describe("PluginContributionsPanel update center synchronization", () => {
it("notifies after a single marketplace update without duplicating per batch item", async () => {
const listener = vi.fn();
window.addEventListener(COMPONENT_UPDATES_CHANGED_EVENT, listener);
try {
await state.installMarketplaceListing(state.marketplaceListings[0]);
expect(listener).toHaveBeenCalledOnce();
listener.mockClear();
state.selectAllUpdatable();
await state.runBatchInstallUpdate();
expect(listener).toHaveBeenCalledOnce();
} finally {
window.removeEventListener(COMPONENT_UPDATES_CHANGED_EVENT, listener);
}
});
});
describe("PluginContributionsPanel installed plugin pin controls", () => { describe("PluginContributionsPanel installed plugin pin controls", () => {
it("renders selection and pin actions as sibling native buttons", async () => { it("renders selection and pin actions as sibling native buttons", async () => {
state.batchMode = false; state.batchMode = false;
@@ -87,6 +87,26 @@ describe("useComponentUpdates", () => {
expect(updates.totalUpdateCount.value).toBe(4); expect(updates.totalUpdateCount.value).toBe(4);
}); });
it("forces a fresh snapshot when a management surface changes during an in-flight refresh", async () => {
const firstAgents = deferred<Array<{ db_type: string; update_available: boolean }>>();
const secondAgents = deferred<Array<{ db_type: string; update_available: boolean }>>();
mocks.listInstalledAgents.mockReturnValueOnce(firstAgents.promise).mockReturnValueOnce(secondAgents.promise);
const updates = useComponentUpdates({ isDesktop: true });
const initialRefresh = updates.refresh();
await Promise.resolve();
const forcedRefresh = updates.refresh({ force: true });
await Promise.resolve();
secondAgents.resolve([{ db_type: "mysql", update_available: false }]);
expect(await forcedRefresh).toBe(true);
firstAgents.resolve([{ db_type: "mysql", update_available: true }]);
expect(await initialRefresh).toBe(false);
expect(mocks.listInstalledAgents).toHaveBeenCalledTimes(2);
expect(updates.driverUpdateCount.value).toBe(0);
});
it("clears driver and MCP update state after a successful update and refresh", async () => { it("clears driver and MCP update state after a successful update and refresh", async () => {
mocks.listInstalledAgents.mockResolvedValueOnce([{ db_type: "mysql", update_available: true }]).mockResolvedValueOnce([{ db_type: "mysql", update_available: false }]); mocks.listInstalledAgents.mockResolvedValueOnce([{ db_type: "mysql", update_available: true }]).mockResolvedValueOnce([{ db_type: "mysql", update_available: false }]);
mocks.checkMcpServerStatus.mockResolvedValueOnce(mcpStatus).mockResolvedValueOnce({ ...mcpStatus, latest_version: "1.0.0", update_available: false }); mocks.checkMcpServerStatus.mockResolvedValueOnce(mcpStatus).mockResolvedValueOnce({ ...mcpStatus, latest_version: "1.0.0", update_available: false });
@@ -20,6 +20,10 @@ export interface ComponentUpdateResult {
failed: string[]; failed: string[];
} }
interface ComponentUpdateRefreshOptions {
force?: boolean;
}
function emptyResult(): ComponentUpdateResult { function emptyResult(): ComponentUpdateResult {
return { drivers: 0, jdbc: false, mcp: false, plugins: 0, skippedDrivers: 0, failed: [] }; return { drivers: 0, jdbc: false, mcp: false, plugins: 0, skippedDrivers: 0, failed: [] };
} }
@@ -44,16 +48,18 @@ export function useComponentUpdates(options: { isDesktop: boolean }) {
const totalUpdateCount = computed(() => driverUpdateCount.value + (jdbcUpdateAvailable.value ? 1 : 0) + (mcpUpdateAvailable.value ? 1 : 0) + pluginUpdateCount.value); const totalUpdateCount = computed(() => driverUpdateCount.value + (jdbcUpdateAvailable.value ? 1 : 0) + (mcpUpdateAvailable.value ? 1 : 0) + pluginUpdateCount.value);
let refreshPromise: Promise<boolean> | null = null; let refreshPromise: Promise<boolean> | null = null;
let refreshVersion = 0;
let activeUpdatePromise: Promise<ComponentUpdateResult> | null = null; let activeUpdatePromise: Promise<ComponentUpdateResult> | null = null;
function refresh() { function startRefresh(): Promise<boolean> {
if (!options.isDesktop) return Promise.resolve(false); if (!options.isDesktop) return Promise.resolve(false);
if (refreshPromise) return refreshPromise; const version = ++refreshVersion;
refreshPromise = (async () => { refreshPromise = Promise.resolve().then(async () => {
loading.value = true; loading.value = true;
lastError.value = ""; lastError.value = "";
try { try {
if (isUpdatePreviewMockEnabled()) { if (isUpdatePreviewMockEnabled()) {
if (version !== refreshVersion) return false;
drivers.value = previewDriverUpdates(); drivers.value = previewDriverUpdates();
jdbcPluginStatus.value = previewJdbcUpdate(); jdbcPluginStatus.value = previewJdbcUpdate();
mcpStatus.value = previewMcpUpdate(); mcpStatus.value = previewMcpUpdate();
@@ -61,6 +67,7 @@ export function useComponentUpdates(options: { isDesktop: boolean }) {
return true; return true;
} }
const [agentResult, jdbcResult, mcpResult, installedPluginsResult, catalogsResult] = await Promise.allSettled([api.listInstalledAgents(), api.jdbcPluginStatus(), api.checkMcpServerStatus(), api.listPlugins(), api.fetchPluginMarketplaceCatalogs()]); const [agentResult, jdbcResult, mcpResult, installedPluginsResult, catalogsResult] = await Promise.allSettled([api.listInstalledAgents(), api.jdbcPluginStatus(), api.checkMcpServerStatus(), api.listPlugins(), api.fetchPluginMarketplaceCatalogs()]);
if (version !== refreshVersion) return false;
const errors: string[] = []; const errors: string[] = [];
if (agentResult.status === "fulfilled") drivers.value = agentResult.value; if (agentResult.status === "fulfilled") drivers.value = agentResult.value;
else { else {
@@ -87,16 +94,24 @@ export function useComponentUpdates(options: { isDesktop: boolean }) {
lastError.value = errors.join("; "); lastError.value = errors.join("; ");
return errors.length === 0; return errors.length === 0;
} catch (error) { } catch (error) {
if (version !== refreshVersion) return false;
lastError.value = error instanceof Error ? error.message : String(error); lastError.value = error instanceof Error ? error.message : String(error);
return false; return false;
} finally { } finally {
loading.value = false; if (version === refreshVersion) {
refreshPromise = null; loading.value = false;
refreshPromise = null;
}
} }
})(); });
return refreshPromise; return refreshPromise;
} }
function refresh(refreshOptions: ComponentUpdateRefreshOptions = {}) {
if (!refreshOptions.force && refreshPromise) return refreshPromise;
return startRefresh();
}
async function updateDrivers(result: ComponentUpdateResult) { async function updateDrivers(result: ComponentUpdateResult) {
const updatable = driverUpdates.value.map((driver) => driver.db_type); const updatable = driverUpdates.value.map((driver) => driver.db_type);
if (!updatable.length) return; if (!updatable.length) return;
@@ -8,6 +8,8 @@ const driverStoreSource = readFileSync(new URL("../../../components/config/Drive
const appDialogsSource = readFileSync(new URL("../../../components/layout/AppDialogs.vue", import.meta.url), "utf8"); const appDialogsSource = readFileSync(new URL("../../../components/layout/AppDialogs.vue", import.meta.url), "utf8");
const connectionDialogSource = readFileSync(new URL("../../../components/connection/ConnectionDialog.vue", import.meta.url), "utf8"); const connectionDialogSource = readFileSync(new URL("../../../components/connection/ConnectionDialog.vue", import.meta.url), "utf8");
const pluginCenterSource = readFileSync(new URL("../../../components/plugins/PluginContributionsPanel.vue", import.meta.url), "utf8"); const pluginCenterSource = readFileSync(new URL("../../../components/plugins/PluginContributionsPanel.vue", import.meta.url), "utf8");
const settingsDialogSource = readFileSync(new URL("../../../components/editor/EditorSettingsDialog.vue", import.meta.url), "utf8");
const connectionStoreSource = readFileSync(new URL("../../../stores/connectionStore.ts", import.meta.url), "utf8");
describe("plugin center integration", () => { describe("plugin center integration", () => {
it("opens from the top toolbar as an independent app surface", () => { it("opens from the top toolbar as an independent app surface", () => {
@@ -43,6 +45,15 @@ describe("plugin center integration", () => {
expect(pluginCenterSource).toContain("installedPlugins.value = await api.listPlugins()"); expect(pluginCenterSource).toContain("installedPlugins.value = await api.listPlugins()");
}); });
it("refreshes global component update state after manual management-surface changes", () => {
expect(appSource).toContain("COMPONENT_UPDATES_CHANGED_EVENT");
expect(appSource).toContain("window.addEventListener(COMPONENT_UPDATES_CHANGED_EVENT, handleComponentUpdatesChanged)");
expect(appSource).toContain("componentUpdates.refresh({ force: true })");
for (const source of [pluginCenterSource, driverStoreSource, settingsDialogSource, connectionDialogSource, connectionStoreSource]) {
expect(source).toContain("notifyComponentUpdatesChanged()");
}
});
it("formats structured backend errors for local and URL package installs", () => { it("formats structured backend errors for local and URL package installs", () => {
const localInstall = pluginCenterSource.slice(pluginCenterSource.indexOf("async function installPlugin("), pluginCenterSource.indexOf("function isHttpPackageUrl(")); const localInstall = pluginCenterSource.slice(pluginCenterSource.indexOf("async function installPlugin("), pluginCenterSource.indexOf("function isHttpPackageUrl("));
const urlInstall = pluginCenterSource.slice(pluginCenterSource.indexOf("async function installPluginFromUrl("), pluginCenterSource.indexOf("const urlProgressPercent")); const urlInstall = pluginCenterSource.slice(pluginCenterSource.indexOf("async function installPluginFromUrl("), pluginCenterSource.indexOf("const urlProgressPercent"));
@@ -1,7 +1,7 @@
// @vitest-environment happy-dom // @vitest-environment happy-dom
import { describe, expect, it, vi } from "vitest"; import { describe, expect, it, vi } from "vitest";
import { COMPONENT_PLUGINS_UPDATED_EVENT, notifyComponentPluginsUpdated } from "@/lib/updates/componentUpdateEvents"; import { COMPONENT_PLUGINS_UPDATED_EVENT, COMPONENT_UPDATES_CHANGED_EVENT, notifyComponentPluginsUpdated, notifyComponentUpdatesChanged } from "@/lib/updates/componentUpdateEvents";
describe("component update events", () => { describe("component update events", () => {
it("notifies plugin surfaces after component-level plugin updates", () => { it("notifies plugin surfaces after component-level plugin updates", () => {
@@ -13,4 +13,24 @@ describe("component update events", () => {
expect(listener).toHaveBeenCalledOnce(); expect(listener).toHaveBeenCalledOnce();
window.removeEventListener(COMPONENT_PLUGINS_UPDATED_EVENT, listener); window.removeEventListener(COMPONENT_PLUGINS_UPDATED_EVENT, listener);
}); });
it("notifies the app when a management surface changes component state", () => {
const listener = vi.fn();
window.addEventListener(COMPONENT_UPDATES_CHANGED_EVENT, listener);
notifyComponentUpdatesChanged();
expect(listener).toHaveBeenCalledOnce();
window.removeEventListener(COMPONENT_UPDATES_CHANGED_EVENT, listener);
});
it("is inert when the store runs outside a browser environment", () => {
vi.stubGlobal("window", undefined);
try {
expect(() => notifyComponentPluginsUpdated()).not.toThrow();
expect(() => notifyComponentUpdatesChanged()).not.toThrow();
} finally {
vi.unstubAllGlobals();
}
});
}); });
@@ -1,5 +1,12 @@
export const COMPONENT_PLUGINS_UPDATED_EVENT = "dbx:component-plugins-updated"; export const COMPONENT_PLUGINS_UPDATED_EVENT = "dbx:component-plugins-updated";
export const COMPONENT_UPDATES_CHANGED_EVENT = "dbx:component-updates-changed";
export function notifyComponentPluginsUpdated(): void { export function notifyComponentPluginsUpdated(): void {
if (typeof window === "undefined") return;
window.dispatchEvent(new Event(COMPONENT_PLUGINS_UPDATED_EVENT)); window.dispatchEvent(new Event(COMPONENT_PLUGINS_UPDATED_EVENT));
} }
export function notifyComponentUpdatesChanged(): void {
if (typeof window === "undefined") return;
window.dispatchEvent(new Event(COMPONENT_UPDATES_CHANGED_EVENT));
}
@@ -50,6 +50,7 @@ describe("connectionStore SQL Server legacy compatibility", () => {
connectDb, connectDb,
installAgent, installAgent,
isAgentInstalled: vi.fn().mockResolvedValue(false), isAgentInstalled: vi.fn().mockResolvedValue(false),
listInstalledAgents: vi.fn().mockResolvedValue([]),
})); }));
const { useConnectionStore } = await import("@/stores/connectionStore"); const { useConnectionStore } = await import("@/stores/connectionStore");
@@ -81,6 +82,7 @@ describe("connectionStore SQL Server legacy compatibility", () => {
connectDb, connectDb,
installAgent, installAgent,
isAgentInstalled: vi.fn().mockResolvedValue(true), isAgentInstalled: vi.fn().mockResolvedValue(true),
listInstalledAgents: vi.fn().mockResolvedValue([]),
})); }));
const { useConnectionStore } = await import("@/stores/connectionStore"); const { useConnectionStore } = await import("@/stores/connectionStore");
@@ -3,6 +3,7 @@ import { uuid } from "@/lib/common/utils";
import { containsHan, orderedSubsequenceSpan, pinyinFirstLetters } from "@/lib/common/pinyin"; import { containsHan, orderedSubsequenceSpan, pinyinFirstLetters } from "@/lib/common/pinyin";
import { ref, computed, watch, markRaw } from "vue"; import { ref, computed, watch, markRaw } from "vue";
import { DEFAULT_QUERY_TIMEOUT_SECS } from "@/lib/connection/timeoutLimits"; import { DEFAULT_QUERY_TIMEOUT_SECS } from "@/lib/connection/timeoutLimits";
import { notifyComponentUpdatesChanged } from "@/lib/updates/componentUpdateEvents";
import type { import type {
ColumnInfo, ColumnInfo,
CompletionAssistantCandidate, CompletionAssistantCandidate,
@@ -3830,6 +3831,7 @@ export const useConnectionStore = defineStore("connection", () => {
if (!requiresSqlServerLegacyCompatibilityComponent(config)) return; if (!requiresSqlServerLegacyCompatibilityComponent(config)) return;
if (await api.isAgentInstalled(SQLSERVER_LEGACY_COMPATIBILITY_DRIVER_KEY)) return; if (await api.isAgentInstalled(SQLSERVER_LEGACY_COMPATIBILITY_DRIVER_KEY)) return;
await api.installAgent(SQLSERVER_LEGACY_COMPATIBILITY_DRIVER_KEY); await api.installAgent(SQLSERVER_LEGACY_COMPATIBILITY_DRIVER_KEY);
notifyComponentUpdatesChanged();
} }
async function setDefaultDatabase(connectionId: string, database: string) { async function setDefaultDatabase(connectionId: string, database: string) {