From 385022bd13bb4fdbdf6333b52fe491f0de502bdd Mon Sep 17 00:00:00 2001 From: Tunglies Date: Fri, 27 Nov 2026 06:18:37 +0000 Subject: [PATCH] refactor(updater): drop the never-matching break-change gate (#8742) --- package.json | 1 - pnpm-lock.yaml | 3 -- src-tauri/src/core/notify/mod.rs | 6 +-- src-tauri/src/core/notify/notification.rs | 4 +- src-tauri/src/core/updater.rs | 15 ------ src/components/setting/mods/update-viewer.tsx | 11 ----- .../setting/setting-verge-advanced.tsx | 2 +- src/hooks/use-update.ts | 4 +- src/locales/ar/settings.json | 1 - src/locales/de/settings.json | 1 - src/locales/en/settings.json | 1 - src/locales/es/settings.json | 1 - src/locales/fa/settings.json | 1 - src/locales/id/settings.json | 1 - src/locales/jp/settings.json | 1 - src/locales/ko/settings.json | 1 - src/locales/pt/settings.json | 1 - src/locales/ru/settings.json | 1 - src/locales/tr/settings.json | 1 - src/locales/tt/settings.json | 1 - src/locales/zh/settings.json | 1 - src/locales/zhtw/settings.json | 1 - src/services/bindings.ts | 1 - src/services/notice-handlers.ts | 3 -- src/services/update.ts | 48 ++----------------- src/types/generated/i18n-keys.ts | 1 - src/types/generated/i18n-resources.ts | 1 - 27 files changed, 10 insertions(+), 104 deletions(-) diff --git a/package.json b/package.json index c401adfdb..fcea7184e 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,6 @@ "@tauri-apps/plugin-updater": "2.14.1", "ahooks": "^3.10.0", "cidr-block": "^2.3.0", - "compare-versions": "^6.1.1", "dayjs": "1.11.23", "foxact": "^0.3.12", "foxts": "^5.9.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ed31c0489..019edc0ae 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -245,9 +245,6 @@ importers: cidr-block: specifier: ^2.3.0 version: 2.3.0 - compare-versions: - specifier: ^6.1.1 - version: 6.1.1 dayjs: specifier: 1.11.23 version: 1.11.23 diff --git a/src-tauri/src/core/notify/mod.rs b/src-tauri/src/core/notify/mod.rs index 9a6b7699f..581394494 100644 --- a/src-tauri/src/core/notify/mod.rs +++ b/src-tauri/src/core/notify/mod.rs @@ -6,8 +6,6 @@ pub mod notification; #[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, specta::Type)] pub enum NoticeStatus { - #[serde(rename = "info")] - Info, #[serde(rename = "import_sub_url::ok")] ImportSubUrlOk, #[serde(rename = "import_sub_url::error")] @@ -83,8 +81,7 @@ impl NoticeStatus { /// test both derive their variant list from here; expected strings stay /// hand-written in the test so renames cannot slip through. #[cfg(test)] - pub const ALL: [Self; 34] = [ - Self::Info, + pub const ALL: [Self; 33] = [ Self::ImportSubUrlOk, Self::ImportSubUrlError, Self::SetConfigError, @@ -129,7 +126,6 @@ mod tests { fn notice_status_wire_contract() -> Result<(), serde_json::Error> { let statuses = NoticeStatus::ALL; let expected = [ - "info", "import_sub_url::ok", "import_sub_url::error", "set_config::error", diff --git a/src-tauri/src/core/notify/notification.rs b/src-tauri/src/core/notify/notification.rs index 7ee40b090..c5c07e549 100644 --- a/src-tauri/src/core/notify/notification.rs +++ b/src-tauri/src/core/notify/notification.rs @@ -387,11 +387,11 @@ fn sample_frontend_events(uid: &str) -> Vec<(FrontendEvent<'_>, &'static str, se ), ( FrontendEvent::NoticeMessage { - status: NoticeStatus::Info, + status: NoticeStatus::UpdateFailed, message: Arc::from("ok"), }, "verge://notice-message", - json!(["info", "ok"]), + json!(["update_failed", "ok"]), ), ( FrontendEvent::TimerUpdated { profile_index: uid }, diff --git a/src-tauri/src/core/updater.rs b/src-tauri/src/core/updater.rs index 061d3da01..d6e902772 100644 --- a/src-tauri/src/core/updater.rs +++ b/src-tauri/src/core/updater.rs @@ -605,21 +605,6 @@ impl SilentUpdater { let version = update.version.as_str(); logging!(info, Type::System, "Silent updater: update available: v{version}"); - if let Some(body) = &update.body - && body.to_lowercase().contains("break change") - { - logging!( - info, - Type::System, - "Silent updater: breaking change detected in v{version}, notifying frontend" - ); - super::handle::Handle::notice( - super::notify::NoticeStatus::Info, - format!("New version v{version} contains breaking changes. Please update manually."), - ); - return Ok(()); - } - if Self::verified_cache(&update).is_some() { logging!(info, Type::System, "Silent updater: v{version} already cached"); } else { diff --git a/src/components/setting/mods/update-viewer.tsx b/src/components/setting/mods/update-viewer.tsx index e6390d916..9e51becf1 100644 --- a/src/components/setting/mods/update-viewer.tsx +++ b/src/components/setting/mods/update-viewer.tsx @@ -306,19 +306,8 @@ export function UpdateViewer({ ref }: { ref?: Ref }) { return updateInfo?.body }, [activeLanguage, t, updateInfo]) - const breakChangeFlag = useMemo(() => { - if (!updateInfo?.body) { - return false - } - return updateInfo?.body.toLowerCase().includes('break change') - }, [updateInfo]) - const onUpdate = useLockFn(async () => { if (!updateInfo?.body) return - if (breakChangeFlag) { - showNotice.error('settings.modals.update.messages.breakChangeError') - return - } if (updateState) return setUpdateState(true) setDownload({ downloaded: 0, total: 0 }) diff --git a/src/components/setting/setting-verge-advanced.tsx b/src/components/setting/setting-verge-advanced.tsx index b0dcd7008..414225b25 100644 --- a/src/components/setting/setting-verge-advanced.tsx +++ b/src/components/setting/setting-verge-advanced.tsx @@ -15,7 +15,7 @@ import { } from '@/services/cmds' import { mutate } from '@/services/mutate' import { showNotice } from '@/services/notice-service' -import { checkUpdateSafe as checkUpdate } from '@/services/update' +import { checkForUpdate as checkUpdate } from '@/services/update' import { version } from '@root/package.json' import { BackupViewer } from './mods/backup-viewer' diff --git a/src/hooks/use-update.ts b/src/hooks/use-update.ts index 37dff3055..0c5c5f955 100644 --- a/src/hooks/use-update.ts +++ b/src/hooks/use-update.ts @@ -1,5 +1,5 @@ import { fetchCacheData, setCacheData, useQuery } from '@/services/query-client' -import { checkUpdateSafe } from '@/services/update' +import { checkForUpdate } from '@/services/update' import { useVerge } from './use-verge' @@ -26,7 +26,7 @@ export const useUpdate = (enabled: boolean = true) => { const shouldCheck = enabled && auto_check_update !== false const fetchUpdate = async () => { - const result = await checkUpdateSafe() + const result = await checkForUpdate() updateLastCheckTime() return result } diff --git a/src/locales/ar/settings.json b/src/locales/ar/settings.json index 01647411b..2e3d36bf9 100644 --- a/src/locales/ar/settings.json +++ b/src/locales/ar/settings.json @@ -445,7 +445,6 @@ "update": "تحديث" }, "messages": { - "breakChangeError": "هذا الإصدار هو تحديث رئيسي ولا يدعم التحديث داخل التطبيق. يرجى إلغاء التثبيت وتنزيل الإصدار الجديد وتثبيته يدويًا", "available": "يتوفّر إصدار جديد" }, "alerts": { diff --git a/src/locales/de/settings.json b/src/locales/de/settings.json index 0f0d5e40c..923f1544d 100644 --- a/src/locales/de/settings.json +++ b/src/locales/de/settings.json @@ -445,7 +445,6 @@ "update": "Aktualisieren" }, "messages": { - "breakChangeError": "Dies ist eine wichtige Aktualisierung. Die In-App-Aktualisierung wird nicht unterstützt. Bitte deinstallieren Sie die Software und laden Sie die neue Version manuell herunter und installieren Sie sie.", "available": "Eine neue Version ist verfügbar" }, "alerts": { diff --git a/src/locales/en/settings.json b/src/locales/en/settings.json index 776f7ecdb..b369d45c1 100644 --- a/src/locales/en/settings.json +++ b/src/locales/en/settings.json @@ -445,7 +445,6 @@ "update": "Update" }, "messages": { - "breakChangeError": "This version is a major update and does not support in-app updates. Please uninstall it and manually download and install the new version", "available": "A new version is available" }, "alerts": { diff --git a/src/locales/es/settings.json b/src/locales/es/settings.json index 0f11798e2..46aaf579a 100644 --- a/src/locales/es/settings.json +++ b/src/locales/es/settings.json @@ -445,7 +445,6 @@ "update": "Actualizar" }, "messages": { - "breakChangeError": "Esta es una actualización importante y no se admite la actualización desde dentro de la aplicación. Desinstale e instale manualmente la nueva versión.", "available": "Hay una nueva versión disponible" }, "alerts": { diff --git a/src/locales/fa/settings.json b/src/locales/fa/settings.json index a8268fab3..71de8138e 100644 --- a/src/locales/fa/settings.json +++ b/src/locales/fa/settings.json @@ -445,7 +445,6 @@ "update": "به‌روزرسانی" }, "messages": { - "breakChangeError": "این نسخه یک به‌روزرسانی اساسی است و پشتیبانی از به‌روزرسانی درون برنامه را پشتیبانی نمی‌کند. لطفاً پس از حذف، دستی دانلود و نصب کنید.", "available": "نسخه جدیدی در دسترس است" }, "alerts": { diff --git a/src/locales/id/settings.json b/src/locales/id/settings.json index 203b2e909..bddfe0dd7 100644 --- a/src/locales/id/settings.json +++ b/src/locales/id/settings.json @@ -445,7 +445,6 @@ "update": "Perbarui" }, "messages": { - "breakChangeError": "Versi ini adalah pembaruan besar dan tidak mendukung pembaruan dalam aplikasi. Harap hapus instalasi dan unduh serta instal versi baru secara manual", "available": "Versi baru tersedia" }, "alerts": { diff --git a/src/locales/jp/settings.json b/src/locales/jp/settings.json index 3ecedefd0..290ea6b7d 100644 --- a/src/locales/jp/settings.json +++ b/src/locales/jp/settings.json @@ -445,7 +445,6 @@ "update": "更新" }, "messages": { - "breakChangeError": "このバージョンは重大な更新であり、アプリケーション内での更新はサポートされていません。アンインストールしてから手動でダウンロードしてインストールしてください。", "available": "新しいバージョンが利用可能です" }, "alerts": { diff --git a/src/locales/ko/settings.json b/src/locales/ko/settings.json index 203e44e4d..1a9d3264a 100644 --- a/src/locales/ko/settings.json +++ b/src/locales/ko/settings.json @@ -445,7 +445,6 @@ "update": "업데이트" }, "messages": { - "breakChangeError": "이 버전은 메이저 업데이트로 앱 내 업데이트를 지원하지 않습니다. 프로그램을 제거한 뒤 새 버전을 수동으로 설치하세요", "available": "새 버전을 사용할 수 있습니다" }, "alerts": { diff --git a/src/locales/pt/settings.json b/src/locales/pt/settings.json index da9540c2a..011d76621 100644 --- a/src/locales/pt/settings.json +++ b/src/locales/pt/settings.json @@ -445,7 +445,6 @@ "update": "Atualizar" }, "messages": { - "breakChangeError": "Esta versão é uma atualização importante e não oferece suporte a atualizações dentro do aplicativo. Desinstale-a e baixe e instale a nova versão manualmente", "available": "Uma nova versão está disponível" }, "alerts": { diff --git a/src/locales/ru/settings.json b/src/locales/ru/settings.json index 94d5ee07b..2d342a7eb 100644 --- a/src/locales/ru/settings.json +++ b/src/locales/ru/settings.json @@ -445,7 +445,6 @@ "update": "Обновить" }, "messages": { - "breakChangeError": "Это крупное обновление, которое не поддерживает обновление внутри приложения. Пожалуйста, удалите текущую версию и загрузите установочный файл вручную.", "available": "Доступна новая версия" }, "alerts": { diff --git a/src/locales/tr/settings.json b/src/locales/tr/settings.json index a26379d22..8a3b77e14 100644 --- a/src/locales/tr/settings.json +++ b/src/locales/tr/settings.json @@ -445,7 +445,6 @@ "update": "Güncelle" }, "messages": { - "breakChangeError": "Bu sürüm büyük bir güncellemedir ve uygulama içi güncellemeleri desteklemez. Lütfen kaldırın ve yeni sürümü manuel olarak indirip kurun", "available": "Yeni bir sürüm mevcut" }, "alerts": { diff --git a/src/locales/tt/settings.json b/src/locales/tt/settings.json index a18456bde..bf73263ab 100644 --- a/src/locales/tt/settings.json +++ b/src/locales/tt/settings.json @@ -445,7 +445,6 @@ "update": "Яңарту" }, "messages": { - "breakChangeError": "Бу зур яңарту, ул кушымта эчендә яңартылмый. Борып алып ташлап, яңадан урнаштыру сорала.", "available": "Яңа версия бар" }, "alerts": { diff --git a/src/locales/zh/settings.json b/src/locales/zh/settings.json index a50ec8db5..5aaaa236f 100644 --- a/src/locales/zh/settings.json +++ b/src/locales/zh/settings.json @@ -445,7 +445,6 @@ "update": "更新" }, "messages": { - "breakChangeError": "此版本为重大更新,不支持应用内更新,请卸载后手动下载安装", "available": "有新版本可用" }, "alerts": { diff --git a/src/locales/zhtw/settings.json b/src/locales/zhtw/settings.json index 0fab116c6..7e56437b7 100644 --- a/src/locales/zhtw/settings.json +++ b/src/locales/zhtw/settings.json @@ -445,7 +445,6 @@ "update": "更新" }, "messages": { - "breakChangeError": "此版本為重大更新,不支援應用程式內更新,請解除安裝後手動下載安裝", "available": "有新版本可用" }, "alerts": { diff --git a/src/services/bindings.ts b/src/services/bindings.ts index 8c2887493..89c74e223 100644 --- a/src/services/bindings.ts +++ b/src/services/bindings.ts @@ -621,7 +621,6 @@ export type NetworkInterfaceView_Serialize = { } export type NoticeStatus = - | 'info' | 'import_sub_url::ok' | 'import_sub_url::error' | 'set_config::error' diff --git a/src/services/notice-handlers.ts b/src/services/notice-handlers.ts index 3a8ff5eba..f633cbdf0 100644 --- a/src/services/notice-handlers.ts +++ b/src/services/notice-handlers.ts @@ -35,9 +35,6 @@ const handlers: Record< NoticeStatus, (msg: string, navigate: NavigateFunction) => void > = { - info: (msg) => { - if (msg) showNotice.info(msg) - }, 'import_sub_url::ok': (_msg, navigate) => { // 空 msg 传入,我们不希望导致 后端-前端-后端 死循环,这里只做提醒。 // 未来细分事件通知时,可以考虑传入订阅 ID 或其他标识符 diff --git a/src/services/update.ts b/src/services/update.ts index 16eea0773..f541aee11 100644 --- a/src/services/update.ts +++ b/src/services/update.ts @@ -3,51 +3,11 @@ import { type CheckOptions, type Update, } from '@tauri-apps/plugin-updater' -import { compareVersions as compareSemver } from 'compare-versions' -import { version as appVersion } from '@root/package.json' - -const normalizeVersion = (input: string | null | undefined): string | null => { - if (typeof input !== 'string') return null - const trimmed = input.trim() - if (!trimmed) return null - return trimmed.replace(/^v/i, '') -} - -const compareVersions = (a: string | null, b: string | null): number | null => { - if (!a || !b) return null - try { - return compareSemver(a, b) - } catch { - return null - } -} - -const localVersionNormalized = normalizeVersion(appVersion) - -export const checkUpdateSafe = async ( +// The plugin's version comparator is overridden in src-tauri/src/lib.rs, so an update +// returned by `check` is already installable and needs no extra filtering here. +export const checkForUpdate = async ( options?: CheckOptions, ): Promise => { - const result = await check(options ?? {}) - if (!result) return null - - const remoteVersion = result.version - const comparison = compareVersions(remoteVersion, localVersionNormalized) - - const isBuildToStable = - /^\d+\.\d+\.\d+\+[0-9A-Za-z.-]+$/.test(localVersionNormalized ?? '') && - remoteVersion === localVersionNormalized?.split('+')[0] - - if (comparison !== null && comparison <= 0 && !isBuildToStable) { - try { - await result.close() - } catch (err) { - console.warn('[updater] failed to close stale update resource', err) - } - return null - } - - return result + return check(options ?? {}) } - -export type { CheckOptions } diff --git a/src/types/generated/i18n-keys.ts b/src/types/generated/i18n-keys.ts index 879684130..0cd5edaf4 100644 --- a/src/types/generated/i18n-keys.ts +++ b/src/types/generated/i18n-keys.ts @@ -709,7 +709,6 @@ export const translationKeys = [ 'settings.modals.update.title', 'settings.modals.update.actions.goToRelease', 'settings.modals.update.actions.update', - 'settings.modals.update.messages.breakChangeError', 'settings.modals.update.messages.available', 'settings.modals.update.alerts.note', 'settings.modals.update.alerts.tip', diff --git a/src/types/generated/i18n-resources.ts b/src/types/generated/i18n-resources.ts index 2eff3d7e6..2ee127158 100644 --- a/src/types/generated/i18n-resources.ts +++ b/src/types/generated/i18n-resources.ts @@ -1263,7 +1263,6 @@ export interface TranslationResources { } messages: { available: string - breakChangeError: string } title: string }