From 10427912e26bd5a77e6defe04a828bc9ea3710dd Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Thu, 3 Dec 2026 07:18:31 +0800 Subject: [PATCH] feat(launcher): display rendered markdown release notes in a modal Keep the About page launcher update notice compact by showing only the available version, package size, and action buttons, with a compact button to open a scrollable release notes dialog when notes are present. Render GFM Markdown safely into React elements via marked.lexer without injecting raw HTML, and raise the release notes cap from 1,600 chars to 64 KiB so full bilingual notes are preserved. --- apps/launcher/package.json | 1 + .../main/services/patch-pack/release-feed.ts | 3 +- .../src/components/MarkdownContent.tsx | 152 +++++++++++ .../src/renderer/src/i18n/locales/en.json | 3 + .../src/renderer/src/i18n/locales/zh-CN.json | 3 + .../src/pages/about/AppUpdateSection.tsx | 54 ++-- .../src/pages/about/ReleaseNotesModal.tsx | 57 ++++ .../src/renderer/src/styles/controls.css | 247 ++++++++++++++++++ .../src/renderer/src/styles/pages.css | 9 +- package-lock.json | 13 + 10 files changed, 522 insertions(+), 20 deletions(-) create mode 100644 apps/launcher/src/renderer/src/components/MarkdownContent.tsx create mode 100644 apps/launcher/src/renderer/src/pages/about/ReleaseNotesModal.tsx diff --git a/apps/launcher/package.json b/apps/launcher/package.json index cc2645c..0df71fb 100644 --- a/apps/launcher/package.json +++ b/apps/launcher/package.json @@ -19,6 +19,7 @@ "@wto/server": "*", "fflate": "^0.8.2", "i18next": "^26.3.6", + "marked": "^18.4.0", "react": "^19.2.8", "react-dom": "^19.2.8", "react-i18next": "^17.0.10", diff --git a/apps/launcher/src/main/services/patch-pack/release-feed.ts b/apps/launcher/src/main/services/patch-pack/release-feed.ts index b5f1ff0..47b2753 100644 --- a/apps/launcher/src/main/services/patch-pack/release-feed.ts +++ b/apps/launcher/src/main/services/patch-pack/release-feed.ts @@ -62,6 +62,7 @@ export class ReleasePageLimitError extends Error { } const GITHUB_HEADERS = { Accept: 'application/vnd.github+json', 'X-GitHub-Api-Version': '2022-11-28' }; +const MAX_RELEASE_NOTES_CHARS = 64 * 1024; const ReleaseAsset = z.object({ name: z.string(), browser_download_url: z.string().optional() }); const LauncherReleaseEntry = z.object({ draft: z.literal(false), @@ -265,7 +266,7 @@ function launcherRelease(entry: Record, version: string, source return { source, version, - notes: body?.trim().slice(0, 1600) ?? '', + notes: body?.trim().slice(0, MAX_RELEASE_NOTES_CHARS) ?? '', installer, manifest, signature, diff --git a/apps/launcher/src/renderer/src/components/MarkdownContent.tsx b/apps/launcher/src/renderer/src/components/MarkdownContent.tsx new file mode 100644 index 0000000..e8f0df8 --- /dev/null +++ b/apps/launcher/src/renderer/src/components/MarkdownContent.tsx @@ -0,0 +1,152 @@ +import { createElement, Fragment, useMemo, type ReactNode } from 'react'; +import { marked, type Token, type Tokens } from 'marked'; + +const SAFE_EXTERNAL_URL = /^https?:\/\//i; +const HTML_COMMENT = /^$/; + +function isSafeExternalUrl(href: string | undefined): href is string { + return typeof href === 'string' && SAFE_EXTERNAL_URL.test(href.trim()); +} + +function renderInline(tokens: readonly Token[], keyPrefix: string): ReactNode { + return tokens.map((token, index) => renderInlineToken(token, `${keyPrefix}-${index}`)); +} + +function renderInlineToken(token: Token, key: string): ReactNode { + switch (token.type) { + case 'text': { + const textToken = token as Tokens.Text; + if (textToken.tokens?.length) return {renderInline(textToken.tokens, key)}; + return {textToken.text}; + } + case 'escape': + return {(token as Tokens.Escape).text}; + case 'strong': + return {renderInline((token as Tokens.Strong).tokens, key)}; + case 'em': + return {renderInline((token as Tokens.Em).tokens, key)}; + case 'del': + return {renderInline((token as Tokens.Del).tokens, key)}; + case 'codespan': + return {(token as Tokens.Codespan).text}; + case 'br': + return
; + case 'link': { + const link = token as Tokens.Link; + const content = link.tokens.length ? renderInline(link.tokens, key) : link.text; + if (!isSafeExternalUrl(link.href)) return {content}; + return ( + + {content} + + ); + } + case 'image': + return {(token as Tokens.Image).text}; + case 'html': { + const raw = (token as Tokens.HTML).text.trim(); + if (!raw || HTML_COMMENT.test(raw)) return null; + return {raw}; + } + default: + return 'raw' in token && typeof token.raw === 'string' ? {token.raw} : null; + } +} + +function renderTable(table: Tokens.Table, key: string): ReactNode { + return ( +
+ + + + {table.header.map((cell, column) => ( + + ))} + + + + {table.rows.map((row, rowIndex) => ( + + {row.map((cell, column) => ( + + ))} + + ))} + +
+ {renderInline(cell.tokens, `${key}-h-${column}`)} +
+ {renderInline(cell.tokens, `${key}-r-${rowIndex}-${column}`)} +
+
+ ); +} + +function renderListItem(item: Tokens.ListItem, key: string): ReactNode { + return ( +
  • + {item.task && } + {renderBlocks(item.tokens, key)} +
  • + ); +} + +function renderBlock(token: Token, key: string): ReactNode { + switch (token.type) { + case 'space': + case 'def': + case 'checkbox': + return null; + case 'heading': { + const heading = token as Tokens.Heading; + const level = Math.min(6, Math.max(1, heading.depth)); + return createElement(`h${level}`, { key }, renderInline(heading.tokens, key)); + } + case 'paragraph': + return

    {renderInline((token as Tokens.Paragraph).tokens, key)}

    ; + case 'text': { + const textToken = token as Tokens.Text; + if (textToken.tokens?.length) return {renderInline(textToken.tokens, key)}; + return {textToken.text}; + } + case 'blockquote': + return
    {renderBlocks((token as Tokens.Blockquote).tokens, key)}
    ; + case 'list': { + const list = token as Tokens.List; + const items = list.items.map((item, index) => renderListItem(item, `${key}-i-${index}`)); + if (list.ordered) { + return
      {items}
    ; + } + return ; + } + case 'code': + return ( +
    +          {(token as Tokens.Code).text}
    +        
    + ); + case 'hr': + return
    ; + case 'table': + return renderTable(token as Tokens.Table, key); + case 'html': { + const raw = (token as Tokens.HTML).text.trim(); + if (!raw || HTML_COMMENT.test(raw)) return null; + return

    {raw}

    ; + } + default: + return 'raw' in token && typeof token.raw === 'string' && token.raw.trim() + ?

    {token.raw}

    + : null; + } +} + +function renderBlocks(tokens: readonly Token[], keyPrefix: string): ReactNode { + return tokens.map((token, index) => renderBlock(token, `${keyPrefix}-${index}`)); +} + +/** Safe React renderer for GFM Markdown without injecting raw HTML. */ +export function MarkdownContent({ markdown }: { readonly markdown: string }) { + const tokens = useMemo(() => marked.lexer(markdown, { gfm: true, breaks: false }), [markdown]); + return
    {renderBlocks(tokens, 'md')}
    ; +} diff --git a/apps/launcher/src/renderer/src/i18n/locales/en.json b/apps/launcher/src/renderer/src/i18n/locales/en.json index b6928f1..c49b9d4 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/en.json +++ b/apps/launcher/src/renderer/src/i18n/locales/en.json @@ -634,6 +634,9 @@ "download": "Download update", "install": "Quit and install", "installing": "Opening the installer…", + "viewNotes": "Release notes", + "notesTitle": "Release notes — v{{version}}", + "closeNotes": "Close", "errors": { "network": "The update source could not be reached.", "page_limit": "Could not confirm whether a newer version is available.", diff --git a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json index 45cd74d..4f2677e 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json +++ b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json @@ -634,6 +634,9 @@ "download": "下载更新", "install": "退出并安装", "installing": "正在打开安装包…", + "viewNotes": "查看更新说明", + "notesTitle": "版本 {{version}} 更新说明", + "closeNotes": "关闭", "errors": { "network": "暂时无法访问更新源。", "page_limit": "无法确认是否有新版本。", diff --git a/apps/launcher/src/renderer/src/pages/about/AppUpdateSection.tsx b/apps/launcher/src/renderer/src/pages/about/AppUpdateSection.tsx index 40cee36..9c95046 100644 --- a/apps/launcher/src/renderer/src/pages/about/AppUpdateSection.tsx +++ b/apps/launcher/src/renderer/src/pages/about/AppUpdateSection.tsx @@ -1,13 +1,19 @@ +import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Notice } from '../../components/Notice.tsx'; import { ProgressBar } from '../../components/ProgressBar.tsx'; import { formatBytes } from '../../format.ts'; import type { AppUpdateState } from '../../shell/useAppUpdate.ts'; +import { ReleaseNotesModal } from './ReleaseNotesModal.tsx'; export function AppUpdateSection({ state }: { readonly state: AppUpdateState }) { const { t } = useTranslation(); + const [notesOpen, setNotesOpen] = useState(false); if (!state.supported) return null; const { check, busy, progress } = state; + const available = check?.status === 'available' && busy !== 'checking' ? check : null; + const notes = available?.release.notes.trim() ?? ''; + return (
    @@ -21,30 +27,46 @@ export function AppUpdateSection({ state }: { readonly state: AppUpdateState })

    {t('about.update.check')}

    {check?.status === 'current' && busy !== 'checking' &&

    {t('about.update.current')}

    } {check?.status === 'failed' && busy !== 'checking' &&

    {t(`about.update.errors.${check.problem}`)}

    } - {check?.status === 'available' && busy !== 'checking' && ( + {available && ( -

    {t('about.update.available', { version: check.release.version, size: formatBytes(check.release.size) })}

    - {check.release.notes &&

    {check.release.notes}

    } - {busy === 'downloading' ? ( +

    {t('about.update.available', { version: available.release.version, size: formatBytes(available.release.size) })}

    + {busy === 'downloading' && ( <>

    {t('about.update.downloading')}

    - ) : ( - + )} + {(busy !== 'downloading' || notes) && ( +
    + {busy !== 'downloading' && ( + + )} + {notes && ( + + )} +
    )}
    )} + {notesOpen && available && notes && ( + setNotesOpen(false)} + /> + )}
    ); } diff --git a/apps/launcher/src/renderer/src/pages/about/ReleaseNotesModal.tsx b/apps/launcher/src/renderer/src/pages/about/ReleaseNotesModal.tsx new file mode 100644 index 0000000..924130e --- /dev/null +++ b/apps/launcher/src/renderer/src/pages/about/ReleaseNotesModal.tsx @@ -0,0 +1,57 @@ +import { useEffect, useId } from 'react'; +import { createPortal } from 'react-dom'; +import { useTranslation } from 'react-i18next'; +import { MarkdownContent } from '../../components/MarkdownContent.tsx'; + +interface ReleaseNotesModalProps { + readonly version: string; + readonly notes: string; + readonly onClose: () => void; +} + +/** Standalone dialog displaying rendered Markdown release notes for an available launcher update. */ +export function ReleaseNotesModal({ version, notes, onClose }: ReleaseNotesModalProps) { + const { t } = useTranslation(); + const titleId = useId(); + + useEffect(() => { + const onKeyDown = (event: KeyboardEvent): void => { + if (event.key === 'Escape') onClose(); + }; + window.addEventListener('keydown', onKeyDown); + return () => window.removeEventListener('keydown', onKeyDown); + }, [onClose]); + + return createPortal( +
    { + if (event.target === event.currentTarget) onClose(); + }} + > +
    +
    +

    {t('about.update.notesTitle', { version })}

    + +
    +
    + +
    + +
    +
    , + document.body, + ); +} diff --git a/apps/launcher/src/renderer/src/styles/controls.css b/apps/launcher/src/renderer/src/styles/controls.css index 6bd8dcf..1137e72 100644 --- a/apps/launcher/src/renderer/src/styles/controls.css +++ b/apps/launcher/src/renderer/src/styles/controls.css @@ -252,6 +252,11 @@ background: var(--red); } +.button-compact { + font-size: 13px; + padding: 5px 12px; +} + .link { font: inherit; color: var(--white); @@ -481,3 +486,245 @@ left: 100%; } } + +/* ===== Modal dialog & Markdown content ===== */ +.modal-backdrop { + position: fixed; + inset: 0; + z-index: 40; + display: flex; + align-items: center; + justify-content: center; + padding: 28px; + background: rgba(7, 10, 12, 0.72); +} + +.modal-dialog { + width: min(760px, 100%); + max-height: min(600px, 100%); + display: flex; + flex-direction: column; + overflow: hidden; + background: var(--sheet); + border: 1px solid var(--line-strong); + border-radius: var(--radius); + box-shadow: 0 18px 48px rgba(0, 0, 0, 0.65); +} + +.modal-head { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; + padding: 12px 14px 12px 20px; + background: linear-gradient(180deg, #343a40, #2b3136); + border-bottom: 1px solid #000; +} + +.modal-title { + margin: 0; + font: 500 18px var(--font-display); + color: var(--white); + letter-spacing: 0.02em; +} + +.modal-close { + flex: none; + width: 28px; + height: 28px; + display: grid; + place-items: center; + padding: 0; + border: 0; + border-radius: var(--radius); + background: none; + color: var(--text-dim); + font-size: 20px; + line-height: 1; + cursor: pointer; +} + +.modal-close:hover { + color: var(--white); + background: rgba(255, 255, 255, 0.1); +} + +.modal-body { + flex: 1; + min-height: 0; + overflow: auto; + padding: 18px 22px 22px; + user-select: text; +} + +.modal-foot { + display: flex; + justify-content: flex-end; + gap: 10px; + padding: 10px 20px; + border-top: 1px solid var(--line); + background: rgba(0, 0, 0, 0.17); +} + +.markdown-body { + font-size: 13.5px; + line-height: 1.65; + color: var(--text); + overflow-wrap: anywhere; +} + +.markdown-body > :first-child { + margin-top: 0; +} + +.markdown-body > :last-child { + margin-bottom: 0; +} + +.markdown-body h1, +.markdown-body h2, +.markdown-body h3, +.markdown-body h4, +.markdown-body h5, +.markdown-body h6 { + margin: 18px 0 8px; + font-family: var(--font-display); + font-weight: 500; + color: var(--white); + line-height: 1.3; +} + +.markdown-body h1 { + font-size: 20px; + padding-bottom: 6px; + border-bottom: 1px solid var(--line); +} + +.markdown-body h2 { + font-size: 17px; + padding-bottom: 5px; + border-bottom: 1px solid var(--line); +} + +.markdown-body h3 { + font-size: 15px; +} + +.markdown-body h4, +.markdown-body h5, +.markdown-body h6 { + font-size: 14px; + color: var(--text); +} + +.markdown-body p { + margin: 0 0 10px; +} + +.markdown-body strong { + color: var(--white); + font-weight: 600; +} + +.markdown-body ul, +.markdown-body ol { + margin: 6px 0 10px; + padding-left: 22px; +} + +.markdown-body li { + margin: 4px 0; +} + +.markdown-body li > ul, +.markdown-body li > ol { + margin: 4px 0; +} + +.markdown-body li > p { + margin: 0 0 4px; +} + +.markdown-body li > p:last-child { + margin-bottom: 0; +} + +.markdown-body code { + padding: 1px 5px; + font-family: var(--font-mono); + font-size: 12.5px; + color: #e6eff2; + background: rgba(0, 0, 0, 0.34); + border: 1px solid var(--line-soft); + border-radius: 2px; +} + +.markdown-body pre { + margin: 10px 0; + padding: 10px 12px; + overflow: auto; + background: rgba(0, 0, 0, 0.38); + border: 1px solid var(--line); + border-radius: var(--radius); +} + +.markdown-body pre code { + padding: 0; + background: none; + border: 0; + font-size: 12.5px; + line-height: 1.5; +} + +.markdown-body blockquote { + margin: 10px 0; + padding: 6px 12px; + color: var(--text-dim); + background: rgba(255, 255, 255, 0.03); + border-left: 3px solid var(--line-strong); +} + +.markdown-body hr { + margin: 16px 0; + border: 0; + border-top: 1px solid var(--line); +} + +.markdown-body a { + color: #7feaf2; + text-decoration: none; + border-bottom: 1px solid rgba(127, 234, 242, 0.35); +} + +.markdown-body a:hover { + color: var(--white); + border-bottom-color: var(--white); +} + +.markdown-table-wrap { + margin: 10px 0; + overflow-x: auto; +} + +.markdown-body table { + width: 100%; + border-collapse: collapse; + font-size: 12.5px; +} + +.markdown-body th, +.markdown-body td { + padding: 6px 10px; + border: 1px solid var(--line); + text-align: left; +} + +.markdown-body th { + color: var(--white); + background: rgba(255, 255, 255, 0.05); +} + +.markdown-task { + margin-right: 6px; + vertical-align: middle; +} diff --git a/apps/launcher/src/renderer/src/styles/pages.css b/apps/launcher/src/renderer/src/styles/pages.css index bbfda5d..4a88bf8 100644 --- a/apps/launcher/src/renderer/src/styles/pages.css +++ b/apps/launcher/src/renderer/src/styles/pages.css @@ -344,9 +344,12 @@ } /* ===== About ===== */ -.update-notes { - white-space: pre-line; - overflow-wrap: anywhere; +.update-actions { + display: flex; + align-items: center; + gap: 8px; + flex-wrap: wrap; + margin-top: 10px; } .about-head { diff --git a/package-lock.json b/package-lock.json index cfa0622..86894ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,6 +29,7 @@ "@wto/server": "*", "fflate": "^0.8.2", "i18next": "^26.3.6", + "marked": "^18.4.0", "react": "^19.2.8", "react-dom": "^19.2.8", "react-i18next": "^17.0.10", @@ -4067,6 +4068,18 @@ "@jridgewell/sourcemap-codec": "^1.5.5" } }, + "node_modules/marked": { + "version": "18.4.0", + "resolved": "https://registry.npmjs.org/marked/-/marked-18.4.0.tgz", + "integrity": "sha512-evbvoaiBPFO2lk2kSkIbrwjPMuX/HjKyefPdZbtwccsJWY91xlLF/SzB5hRsAOwStztmKC09i+IGsUcTYMt//A==", + "license": "MIT", + "bin": { + "marked": "bin/marked.js" + }, + "engines": { + "node": ">= 20" + } + }, "node_modules/matcher": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/matcher/-/matcher-3.0.0.tgz",