From a179f130314b8fdce51213d3c5d8818787f10e4e Mon Sep 17 00:00:00 2001 From: cc <98377878+hicccc77@users.noreply.github.com> Date: Sat, 21 Mar 2026 15:17:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=BC=B9=E7=AA=97=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=BF=87=E6=BB=A4=E4=B8=8B=E8=BD=BD=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main.ts | 65 ++++++++++++++++++++++++++++- scripts/afterPack-sign-manifest.cjs | 2 +- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/electron/main.ts b/electron/main.ts index 3a5dab3..2ebe56b 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -122,6 +122,67 @@ let isDownloadInProgress = false let downloadProgressHandler: ((progress: any) => void) | null = null let downloadedHandler: (() => void) | null = null +const normalizeReleaseNotes = (rawReleaseNotes: unknown): string => { + const merged = (() => { + if (typeof rawReleaseNotes === 'string') { + return rawReleaseNotes + } + if (Array.isArray(rawReleaseNotes)) { + return rawReleaseNotes + .map((item) => { + if (!item || typeof item !== 'object') return '' + const note = (item as { note?: unknown }).note + return typeof note === 'string' ? note : '' + }) + .filter(Boolean) + .join('\n\n') + } + return '' + })() + + if (!merged.trim()) return '' + + // 兼容 electron-updater 直接返回 HTML 的场景 + const removeDownloadSectionFromHtml = (input: string): string => { + return input.replace( + /]*>\s*(?:下载|download)\s*<\/h[1-6]>\s*[\s\S]*?(?= { + const lines = input.split(/\r?\n/) + const output: string[] = [] + let skipDownloadSection = false + + for (const line of lines) { + const headingMatch = line.match(/^\s*#{1,6}\s*(.+?)\s*$/) + if (headingMatch) { + const heading = headingMatch[1].trim().toLowerCase() + if (heading === '下载' || heading === 'download') { + skipDownloadSection = true + continue + } + if (skipDownloadSection) { + skipDownloadSection = false + } + } + if (!skipDownloadSection) { + output.push(line) + } + } + + return output.join('\n') + } + + const cleaned = removeDownloadSectionFromMarkdown(removeDownloadSectionFromHtml(merged)) + .replace(/\n{3,}/g, '\n\n') + .trim() + + return cleaned +} + type AnnualReportYearsLoadStrategy = 'cache' | 'native' | 'hybrid' type AnnualReportYearsLoadPhase = 'cache' | 'native' | 'scan' | 'done' @@ -1121,7 +1182,7 @@ function registerIpcHandlers() { return { hasUpdate: true, version: latestVersion, - releaseNotes: result.updateInfo.releaseNotes as string || '' + releaseNotes: normalizeReleaseNotes(result.updateInfo.releaseNotes) } } } @@ -2574,7 +2635,7 @@ function checkForUpdatesOnStartup() { // 通知渲染进程有新版本 mainWindow.webContents.send('app:updateAvailable', { version: latestVersion, - releaseNotes: result.updateInfo.releaseNotes || '' + releaseNotes: normalizeReleaseNotes(result.updateInfo.releaseNotes) }) } } diff --git a/scripts/afterPack-sign-manifest.cjs b/scripts/afterPack-sign-manifest.cjs index 1433430..7e92d50 100644 --- a/scripts/afterPack-sign-manifest.cjs +++ b/scripts/afterPack-sign-manifest.cjs @@ -155,8 +155,8 @@ function getModulePath(resourcesDir, appOutDir, platform) { if (!filename) return null; const direct = findFirstExisting([ - path.join(resourcesDir, filename), path.join(resourcesDir, 'resources', filename), + path.join(resourcesDir, filename), ]); if (direct) return direct;