feat: 增加忽略本次更新

This commit is contained in:
Wxw-Gu committed 2026-11-09 16:51:03 +08:00
1 parent 6cadcb9a5a
commit 7dcda8554e
7 files changed
+219 -5

No files matched your search

+13
View File
@@ -108,6 +108,7 @@ import {
saveSettings,
updateSettings,
getSettingsPath,
normalizeSkippedUpdateVersion,
AppSettings,
validateDbRoot
} from './services/settings-store'
@@ -1473,6 +1474,18 @@ app.whenReady().then(async () => {
ipcMain.handle('app-update:download', () => appUpdateService.download())
ipcMain.handle('app-update:install', () => appUpdateService.install())
ipcMain.handle('app-update:openDownloadPage', () => appUpdateService.openDownloadPage())
ipcMain.handle('app-update:getIgnoredVersion', () => loadSettings().skippedUpdateVersion)
/**
* 记录 / 清除「忽略此版本」。
*
* 传 null 或非法版本号 = 清除。校验放在主进程:渲染层传来的字符串不可信,
* 一个脏值会让「忽略」永远命中不了同一条记录,表现为每次都弹。
*/
ipcMain.handle('app-update:setIgnoredVersion', (_, version: unknown) => {
const normalized = normalizeSkippedUpdateVersion(version)
saveSettings({ ...loadSettings(), skippedUpdateVersion: normalized })
return normalized
})
appUpdateService.scheduleStartupCheck()
ipcMain.handle('cache:getSummary', () => getCacheSummary())
ipcMain.handle('cache:openKnowledgeDirectory', () => openKnowledgeDirectory())
+24 -2
View File
@@ -60,6 +60,21 @@ export interface AppSettings {
* 设置页随时可以改回来。
*/
closeAction: CloseAction
/**
* 用户点过「忽略此版本」的更新版本号(不含 `v` 前缀)。
*
* 只影响**启动时的自动弹窗**:同一版本不再打扰。手动检查更新与「设置 → 关于」
* 始终展示最新版本 —— 忽略的是提示,不是版本本身。空串表示没有忽略任何版本。
*/
skippedUpdateVersion: string
}
/** 只接受 `1.2.3` / `1.2.3-beta.1` 这类版本号;其它输入一律按"没有忽略"处理。 */
const UPDATE_VERSION_PATTERN = /^\d{1,6}\.\d{1,6}\.\d{1,6}(?:[-+][0-9A-Za-z.-]{1,32})?$/
export function normalizeSkippedUpdateVersion(value: unknown): string {
const text = String(value ?? '').trim()
return UPDATE_VERSION_PATTERN.test(text) ? text : ''
}
function getDefaultDbRoot(): string {
@@ -145,7 +160,8 @@ const DEFAULT_SETTINGS: AppSettings = {
windowsWechatPort: '',
reportImagePostfixText: '今日日报',
queryAgentEnabled: true,
closeAction: 'ask'
closeAction: 'ask',
skippedUpdateVersion: ''
}
const SETTINGS_FILE = path.join(
@@ -192,9 +208,15 @@ export function loadSettings(): AppSettings {
}
// 关闭行为可能来自旧版本或手改过的 settings.json —— 非法值一律收敛回 `ask`。
// 放任非法值会造成最难排查的一种表现:点关闭窗口什么也不发生。
if (cache.closeAction !== 'ask' && cache.closeAction !== 'tray' && cache.closeAction !== 'quit') {
if (
cache.closeAction !== 'ask' &&
cache.closeAction !== 'tray' &&
cache.closeAction !== 'quit'
) {
cache.closeAction = 'ask'
}
// 版本号是拿来逐字比对的:脏值会让「忽略」永远命中不了同一条记录。
cache.skippedUpdateVersion = normalizeSkippedUpdateVersion(cache.skippedUpdateVersion)
// 防撤回已下线(设置入口已隐藏):历史版本可能把它持久化为 true。
// 这里强制收敛为 false 并回写磁盘,确保旧的撤回监听与撤回日志不会继续运行。
if (cache.recallProtectionEnabled || retiredKeepProcess !== undefined) {
+2
View File
@@ -239,6 +239,8 @@ declare global {
downloadAppUpdate: () => Promise<AppUpdateCheckResult>
installAppUpdate: () => Promise<AppUpdateInstallResult>
openAppUpdateDownloadPage: () => Promise<AppUpdateOpenDownloadPageResult>
getIgnoredUpdateVersion: () => Promise<string>
setIgnoredUpdateVersion: (version: string | null) => Promise<string>
onAppUpdateState: (callback: (state: AppUpdateState) => void) => () => void
getCacheSummary: () => Promise<CacheSummary>
clearCache: (scope: CacheClearScope) => Promise<CacheSummary>
+5
View File
@@ -142,6 +142,11 @@ const api = {
downloadAppUpdate: () => ipcRenderer.invoke('app-update:download'),
installAppUpdate: () => ipcRenderer.invoke('app-update:install'),
openAppUpdateDownloadPage: () => ipcRenderer.invoke('app-update:openDownloadPage'),
getIgnoredUpdateVersion: (): Promise<string> =>
ipcRenderer.invoke('app-update:getIgnoredVersion'),
/** 传 `null` 清除忽略记录并恢复启动提示;返回写入后的值(非法版本会被收敛成空串)。 */
setIgnoredUpdateVersion: (version: string | null): Promise<string> =>
ipcRenderer.invoke('app-update:setIgnoredVersion', version),
onAppUpdateState: (callback: (state: AppUpdateState) => void) => {
const listener = (_event: Electron.IpcRendererEvent, state: AppUpdateState): void =>
callback(state)
@@ -1,4 +1,4 @@
import { useState } from 'react'
import { useEffect, useState } from 'react'
import {
AlertDialog,
AlertDialogAction,
@@ -21,14 +21,53 @@ export function AppUpdatePrompt({
}): React.ReactElement {
const update = useAppUpdateState()
const [dismissedVersion, setDismissedVersion] = useState<string>()
/**
* 已忽略的版本号。`null` 表示还没读回来 —— 这期间不弹,否则用户会看到
* 弹窗闪一下就消失(启动时状态先到、设置后到)。
*/
const [ignoredVersion, setIgnoredVersion] = useState<string | null>(null)
useEffect(() => {
let active = true
void window.api
.getIgnoredUpdateVersion()
.then((version) => {
if (active) setIgnoredVersion(version || '')
})
.catch(() => {
// 读不到就按"没有忽略"处理:宁可多弹一次,也不要静默吞掉更新提示。
if (active) setIgnoredVersion('')
})
return () => {
active = false
}
}, [])
const shouldPrompt =
update.status === 'available' &&
update.source === 'startup' &&
Boolean(update.version) &&
ignoredVersion !== null &&
update.version !== ignoredVersion &&
update.version !== dismissedVersion
const dismiss = (): void => setDismissedVersion(update.version)
const ignoreVersion = async (): Promise<void> => {
const version = update.version
if (!version) return
setIgnoredVersion(version)
dismiss()
try {
await window.api.setIgnoredUpdateVersion(version)
onNotice(`已忽略 v${version} 的更新提示,可在「设置 → 关于」恢复`)
} catch (error) {
// 没写进磁盘就当作没忽略,否则用户以为设置生效了,下次启动照样弹。
setIgnoredVersion('')
onNotice(error instanceof Error ? error.message : '忽略更新提示失败')
}
}
const continueUpdate = async (): Promise<void> => {
dismiss()
if (update.delivery === 'release-page') {
@@ -55,6 +94,9 @@ export function AppUpdatePrompt({
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<Button variant="ghost" className="sm:mr-auto" onClick={() => void ignoreVersion()}>
忽略此版本
</Button>
<AlertDialogCancel asChild>
<Button variant="outline" onClick={dismiss}>
取消
@@ -1,4 +1,4 @@
import { useMemo, useState } from 'react'
import { useEffect, useMemo, useState } from 'react'
import { Button, Progress } from '../../../components/ui'
import { useAppUpdateState } from '../../app-update/useAppUpdateState'
@@ -19,6 +19,30 @@ export function AboutPage({
}): React.ReactElement {
const update = useAppUpdateState()
const [busy, setBusy] = useState(false)
const [ignoredUpdateVersion, setIgnoredUpdateVersion] = useState('')
useEffect(() => {
let active = true
void window.api
.getIgnoredUpdateVersion()
.then((version) => {
if (active) setIgnoredUpdateVersion(version || '')
})
.catch(() => undefined)
return () => {
active = false
}
}, [])
const restoreUpdatePrompt = async (): Promise<void> => {
try {
await window.api.setIgnoredUpdateVersion(null)
setIgnoredUpdateVersion('')
onNotice('已恢复启动时的更新提示')
} catch (error) {
onNotice(error instanceof Error ? error.message : '恢复更新提示失败')
}
}
const action = useMemo(() => {
if (update.status === 'available') {
@@ -153,6 +177,20 @@ export function AboutPage({
</div>
</section>
{ignoredUpdateVersion ? (
<section className="settings-card flex flex-wrap items-center justify-between gap-3">
<div>
<strong>已忽略 v{ignoredUpdateVersion} 的更新提示</strong>
<span className="mt-1 block text-sm text-muted-foreground">
该版本不会在启动时弹窗;更高版本仍会提醒。
</span>
</div>
<Button variant="outline" size="sm" onClick={() => void restoreUpdatePrompt()}>
恢复提示
</Button>
</section>
) : null}
<h2 className="settings-section-heading">支持</h2>
<section className="settings-card about-links-card">
<a href={RELEASES_URL} target="_blank" rel="noreferrer">