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。

feat(updater): allow switching download source after failure

zipg170608180285
diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue
index f92c19db65..5eb7a393fc 100644
--- a/apps/desktop/src/App.vue
+++ b/apps/desktop/src/App.vue
@@ -194,6 +194,7 @@ const {
checkingUpdates,
updateInfo,
updateCheckMessage,
+ updateCheckFailed,
showUpdateDialog,
isDownloadingUpdate,
downloadProgress,
@@ -206,6 +207,7 @@ const {
openUrl,
checkUpdates,
openLatestRelease,
+ changeUpdateDownloadSource,
ignoreCurrentVersion,
downloadUpdateInBackground,
cancelDownload,
@@ -3359,6 +3361,9 @@ onUnmounted(() => {
v-model:open="showUpdateDialog"
:update-info="updateInfo"
:update-check-message="updateCheckMessage"
+ :checking-updates="checkingUpdates"
+ :update-check-failed="updateCheckFailed"
+ :update-download-source="settingsStore.editorSettings.updateDownloadSource"
:is-downloading-update="isDownloadingUpdate"
:download-progress="downloadProgress"
:update-downloaded="updateDownloaded"
@@ -3367,6 +3372,7 @@ onUnmounted(() => {
:is-ignoring-update="isIgnoringUpdate"
:active-task-count="activeUpdateTaskCount"
@open-latest-release="openLatestRelease"
+ @change-download-source="changeUpdateDownloadSource"
@download-in-background="downloadUpdateInBackground"
@cancel-download="cancelDownload"
@install-downloaded="installDownloadedUpdate"
diff --git a/apps/desktop/src/components/layout/UpdateDialog.spec.ts b/apps/desktop/src/components/layout/UpdateDialog.spec.ts
index 937e2717aa..095a9e495b 100644
--- a/apps/desktop/src/components/layout/UpdateDialog.spec.ts
+++ b/apps/desktop/src/components/layout/UpdateDialog.spec.ts
@@ -79,6 +79,9 @@ async function mountDialog(activeTaskCount: number, initialState: Partial<Dialog
release_notes: "",
},
updateCheckMessage: "",
+ checkingUpdates: false,
+ updateCheckFailed: false,
+ updateDownloadSource: "official",
isDownloadingUpdate: state.isDownloadingUpdate,
downloadProgress: state.downloadProgress,
updateDownloaded: state.updateDownloaded,
diff --git a/apps/desktop/src/components/layout/UpdateDialog.vue b/apps/desktop/src/components/layout/UpdateDialog.vue
index 262eed04fb..9aa168c7ba 100644
--- a/apps/desktop/src/components/layout/UpdateDialog.vue
+++ b/apps/desktop/src/components/layout/UpdateDialog.vue
@@ -4,7 +4,9 @@ import { useI18n } from "vue-i18n";
import { AlertTriangle, Loader2 } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import type { UpdateInfo } from "@/lib/backend/api";
+import type { UpdateDownloadSource } from "@/lib/backend/tauri";
import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
import { canDownloadAndInstallUpdate } from "@/composables/useAppUpdater";
@@ -20,6 +22,9 @@ const props = defineProps<{
updateReady: boolean;
isIgnoringUpdate: boolean;
activeTaskCount: number;
+ checkingUpdates: boolean;
+ updateCheckFailed: boolean;
+ updateDownloadSource: UpdateDownloadSource;
}>();
const emit = defineEmits<{
@@ -29,6 +34,7 @@ const emit = defineEmits<{
"install-downloaded": [];
restart: [];
"ignore-version": [];
+ "change-download-source": [source: UpdateDownloadSource];
}>();
const { t } = useI18n();
@@ -136,7 +142,19 @@ watch(
<span>{{ t("updates.activeTasksBlockUpdate", { count: activeTaskCount }) }}</span>
</div>
</div>
- <DialogFooter class="min-w-0">
+ <DialogFooter class="relative min-w-0 sm:justify-end">
+ <div v-if="updateCheckFailed && !isDownloadingUpdate && !updateReady" class="flex items-center gap-1.5 self-start sm:absolute sm:left-4 sm:top-1/2 sm:-translate-y-1/2">
+ <span class="text-xs text-muted-foreground">{{ t("updates.source") }}</span>
+ <Select :model-value="updateDownloadSource" :disabled="checkingUpdates" @update:model-value="(value) => value && emit('change-download-source', value as UpdateDownloadSource)">
+ <SelectTrigger class="h-8 w-[150px] text-xs">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value="official">{{ t("updates.sourceOfficial") }}</SelectItem>
+ <SelectItem value="cnb">{{ t("updates.sourceCnb") }}</SelectItem>
+ </SelectContent>
+ </Select>
+ </div>
<template v-if="updateInfo?.update_available">
<div class="flex min-w-0 flex-wrap items-center gap-2 sm:justify-end">
<Button v-if="!isCloseBlocked" variant="outline" class="shrink-0" @click="handleCancel">{{ t("dangerDialog.cancel") }}</Button>
diff --git a/apps/desktop/src/composables/__tests__/useAppUpdater.spec.ts b/apps/desktop/src/composables/__tests__/useAppUpdater.spec.ts
index 51be5cfd9f..eb8d07f1d0 100644
--- a/apps/desktop/src/composables/__tests__/useAppUpdater.spec.ts
+++ b/apps/desktop/src/composables/__tests__/useAppUpdater.spec.ts
@@ -267,6 +267,70 @@ describe("useAppUpdater reopening the dialog from the toolbar", () => {
});
});
+describe("useAppUpdater failure state handling", () => {
+ interface UpdateInfo {
+ current_version: string;
+ latest_version: string;
+ update_available: boolean;
+ release_name: string;
+ release_url: string;
+ release_notes: string;
+ }
+
+ it("keeps the failed state visible while a retry is in flight and clears it on success", async () => {
+ apiMock.checkForUpdates.mockRejectedValueOnce(new Error("boom"));
+ const updater = mountUpdater();
+
+ await updater.checkUpdates();
+ expect(updater.updateCheckFailed.value).toBe(true);
+ expect(updater.updateCheckMessage.value).not.toBe("");
+
+ const retry = deferred<UpdateInfo>();
+ apiMock.checkForUpdates.mockReturnValueOnce(retry.promise);
+ const pending = updater.checkUpdates();
+ await vi.waitFor(() => expect(updater.checkingUpdates.value).toBe(true));
+
+ // Mid-retry: the source switcher stays mounted (updateCheckFailed) and
+ // the dialog must not fall through to "up to date" with an empty version.
+ expect(updater.updateCheckFailed.value).toBe(true);
+ expect(updater.updateCheckMessage.value).not.toBe("");
+
+ retry.resolve({
+ current_version: "0.5.69",
+ latest_version: "0.5.69",
+ update_available: false,
+ release_name: "",
+ release_url: "",
+ release_notes: "",
+ });
+ await pending;
+
+ expect(updater.updateCheckFailed.value).toBe(false);
+ expect(updater.updateCheckMessage.value).toContain("0.5.69");
+ });
+
+ it("keeps the last update info when a silent background check fails", async () => {
+ apiMock.checkForUpdates.mockResolvedValueOnce({
+ current_version: "0.5.69",
+ latest_version: "0.5.70",
+ update_available: true,
+ release_name: "DBX v0.5.70",
+ release_url: "https://github.com/t8y2/dbx/releases/tag/v0.5.70",
+ release_notes: "",
+ });
+ const updater = mountUpdater();
+ await updater.checkUpdates({ silent: true });
+ expect(updater.updateInfo.value?.update_available).toBe(true);
+
+ apiMock.checkForUpdates.mockRejectedValueOnce(new Error("network down"));
+ await updater.checkUpdates({ silent: true });
+
+ expect(updater.updateInfo.value?.update_available).toBe(true);
+ expect(updater.updateCheckFailed.value).toBe(false);
+ expect(updater.showUpdateDialog.value).toBe(false);
+ });
+});
+
describe("useAppUpdater ignore version", () => {
it("persists the ignored latest version and closes the update dialog", async () => {
const updater = mountUpdater();
diff --git a/apps/desktop/src/composables/useAppUpdater.ts b/apps/desktop/src/composables/useAppUpdater.ts
index bf6c013c36..113d1de65f 100644
--- a/apps/desktop/src/composables/useAppUpdater.ts
+++ b/apps/desktop/src/composables/useAppUpdater.ts
@@ -94,6 +94,7 @@ export function resolveUpdateReleaseUrl(info: api.UpdateInfo | null, source: unk
if (normalizedSource === "cnb" && info?.latest_version) {
return `https://cnb.cool/dbxio.com/dbx/-/releases/tag/${tagVersion(info.latest_version)}`;
}
+ if (normalizedSource === "cnb") return "https://cnb.cool/dbxio.com/dbx/-/releases";
return info?.release_url || fallbackUrl;
}
@@ -115,6 +116,7 @@ export function useAppUpdater(options: UseAppUpdaterOptions = {}) {
const checkingUpdates = ref(false);
const updateInfo = ref<api.UpdateInfo | null>(null);
const updateCheckMessage = ref("");
+ const updateCheckFailed = ref(false);
const showUpdateDialog = ref(false);
const isDownloadingUpdate = ref(false);
// null while the download size is unknown (backend reported no total) — the UI shows an indeterminate state.
@@ -146,10 +148,14 @@ export function useAppUpdater(options: UseAppUpdaterOptions = {}) {
return;
}
checkingUpdates.value = true;
- updateCheckMessage.value = "";
+ // Keep the previous message/failed state visible while the check is in
+ // flight: pre-clearing would flip the dialog to "up to date" with an empty
+ // version and unmount the source switcher until the request settles.
try {
const info = await api.checkForUpdates(currentLocale(), normalizeUpdateDownloadSource(settingsStore.editorSettings.updateDownloadSource));
updateInfo.value = info;
+ updateCheckMessage.value = "";
+ updateCheckFailed.value = false;
if (info.update_available) {
if (shouldOpenUpdateDialog({ silent: options.silent })) {
showUpdateDialog.value = true;
@@ -160,7 +166,13 @@ export function useAppUpdater(options: UseAppUpdaterOptions = {}) {
}
} catch (e: any) {
if (!options.silent) {
+ // Drop the stale update info only on a surfaced failure; silent
+ // background checks keep the last known state so the toolbar
+ // indicator and an in-flight download's portable-mode flag survive
+ // a single failed poll.
+ updateInfo.value = null;
updateCheckMessage.value = formatUpdateError(String(e));
+ updateCheckFailed.value = true;
showUpdateDialog.value = true;
}
} finally {
@@ -187,6 +199,11 @@ export function useAppUpdater(options: UseAppUpdaterOptions = {}) {
openUrl(url);
}
+ async function changeUpdateDownloadSource(source: SettingsUpdateDownloadSource) {
+ await settingsStore.updateEditorSettingsAndPersist({ updateDownloadSource: source });
+ await checkUpdates();
+ }
+
async function ignoreCurrentVersion() {
const latest = updateInfo.value?.latest_version;
if (!latest || isIgnoringUpdate.value) return;
@@ -342,6 +359,7 @@ export function useAppUpdater(options: UseAppUpdaterOptions = {}) {
checkingUpdates,
updateInfo,
updateCheckMessage,
+ updateCheckFailed,
showUpdateDialog,
isDownloadingUpdate,
downloadProgress,
@@ -356,6 +374,7 @@ export function useAppUpdater(options: UseAppUpdaterOptions = {}) {
checkUpdates,
formatUpdateError,
openLatestRelease,
+ changeUpdateDownloadSource,
ignoreCurrentVersion,
downloadUpdateInBackground,
cancelDownload,
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index 0be300a89a..f02add5dc8 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -309,6 +309,9 @@ export default {
installNow: "Install Now",
installedReadyToRestart: "DBX has been updated. Restart to finish.",
networkOrMirrorFailed: "Network connection timed out or download mirrors are currently unreachable. Please check your connection or click 'Open Release' to download manually.",
+ source: "Update source",
+ sourceOfficial: "Official source",
+ sourceCnb: "CNB",
installing: "Installing update...",
installFailed: "Update installation failed: {error}",
restart: "Exit & Restart",
diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts
index 9e0e86ea82..40e4615697 100644
--- a/apps/desktop/src/i18n/locales/es.ts
+++ b/apps/desktop/src/i18n/locales/es.ts
@@ -318,6 +318,9 @@ export default withEnglishFallback({
exitAndUpdate: "Salir y actualizar",
dockerUsersRun: "Los usuarios de Docker deben ejecutar",
toUpdate: "para actualizar",
+ source: "Fuente de actualizaciones",
+ sourceOfficial: "Fuente oficial",
+ sourceCnb: "CNB",
},
sidebar: {
connections: "CONEXIONES",
diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts
index dafebcdb87..d447cd0ab1 100644
--- a/apps/desktop/src/i18n/locales/it.ts
+++ b/apps/desktop/src/i18n/locales/it.ts
@@ -317,6 +317,9 @@ export default withEnglishFallback({
exitAndUpdate: "Esci e Aggiorna",
dockerUsersRun: "Gli utenti Docker dovrebbero eseguire",
toUpdate: "per aggiornare",
+ source: "Sorgente di aggiornamento",
+ sourceOfficial: "Sorgente ufficiale",
+ sourceCnb: "CNB",
},
sidebar: {
connections: "CONNESSIONI",
diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.ts
index ced7fd6be7..5065f858b1 100644
--- a/apps/desktop/src/i18n/locales/ja.ts
+++ b/apps/desktop/src/i18n/locales/ja.ts
@@ -318,6 +318,9 @@ export default withEnglishFallback({
exitAndUpdate: "終了してアップデート",
dockerUsersRun: "Dockerユーザーは以下を実行してください",
toUpdate: "更新するには",
+ source: "更新ソース",
+ sourceOfficial: "公式ソース",
+ sourceCnb: "CNB",
},
sidebar: {
connections: "接続",
diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.ts
index 7117b6ed41..2dd7342e32 100644
--- a/apps/desktop/src/i18n/locales/ko.ts
+++ b/apps/desktop/src/i18n/locales/ko.ts
@@ -316,6 +316,9 @@ export default withEnglishFallback({
exitAndUpdate: "종료 후 업데이트",
dockerUsersRun: "Docker 사용자는 다음 명령을 실행하세요",
toUpdate: "업데이트하려면",
+ source: "업데이트 소스",
+ sourceOfficial: "공식 소스",
+ sourceCnb: "CNB",
},
sidebar: {
connections: "연결",
diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts
index 6bb9e4213c..9e666a05f7 100644
--- a/apps/desktop/src/i18n/locales/pt-BR.ts
+++ b/apps/desktop/src/i18n/locales/pt-BR.ts
@@ -318,6 +318,9 @@ export default withEnglishFallback({
exitAndUpdate: "Sair e Atualizar",
dockerUsersRun: "Usuários do Docker devem executar",
toUpdate: "para atualizar",
+ source: "Fonte de atualização",
+ sourceOfficial: "Fonte oficial",
+ sourceCnb: "CNB",
},
sidebar: {
connections: "CONEXÕES",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index 5ebee7a967..b5b86651a9 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -234,6 +234,9 @@ export default withEnglishFallback({
installNow: "立即安装",
installedReadyToRestart: "DBX 已更新完成,重启后生效。",
networkOrMirrorFailed: "网络连接超时或所有镜像源暂不可用。请检查网络状态,或点击“打开下载页”手动下载。",
+ source: "更新源",
+ sourceOfficial: "官方源",
+ sourceCnb: "CNB",
installing: "正在安装更新...",
installFailed: "更新安装失败:{error}",
restart: "退出并重启",
diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts
index de5a07a2c3..54db4cabdd 100644
--- a/apps/desktop/src/i18n/locales/zh-TW.ts
+++ b/apps/desktop/src/i18n/locales/zh-TW.ts
@@ -318,6 +318,9 @@ export default withEnglishFallback({
exitAndUpdate: "結束並更新",
dockerUsersRun: "Docker 使用者請執行",
toUpdate: "更新",
+ source: "更新來源",
+ sourceOfficial: "官方來源",
+ sourceCnb: "CNB",
},
sidebar: {
connections: "連線",
diff --git a/packages/app-tests/appUpdater.test.ts b/packages/app-tests/appUpdater.test.ts
index 3cb5642436..5dfe5734a3 100644
--- a/packages/app-tests/appUpdater.test.ts
+++ b/packages/app-tests/appUpdater.test.ts
@@ -84,7 +84,7 @@ test("resolves release page URL from update download source", () => {
const fallbackUrl = "https://github.com/t8y2/dbx/releases/latest";
assert.equal(resolveUpdateReleaseUrl(updateInfo({ latest_version: "0.5.39" }), "cnb", fallbackUrl), "https://cnb.cool/dbxio.com/dbx/-/releases/tag/v0.5.39");
assert.equal(resolveUpdateReleaseUrl(updateInfo({ release_url: "https://github.com/t8y2/dbx/releases/tag/v0.5.39" }), "official", fallbackUrl), "https://github.com/t8y2/dbx/releases/tag/v0.5.39");
- assert.equal(resolveUpdateReleaseUrl(null, "cnb", fallbackUrl), fallbackUrl);
+ assert.equal(resolveUpdateReleaseUrl(null, "cnb", fallbackUrl), "https://cnb.cool/dbxio.com/dbx/-/releases");
});
test("counts background and query tasks that must finish before updating", () => {