From de08b9460df52ad036ef521e796064e31bfec0fa Mon Sep 17 00:00:00 2001 From: Mus Date: Wed, 18 Nov 2026 08:48:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=95=8C=E9=9D=A2=EF=BC=9A=E5=8A=A0=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=8A=A0=E8=BD=BD=E7=94=BB=E9=9D=A2=EF=BC=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E8=AF=B4=E6=98=8E=E6=94=B9=E6=88=90=E7=8B=AC=E7=AB=8B?= =?UTF-8?q?=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 启动画面:双击后先挂一张自绘的加载画面(标志 + 进度条),主窗口首帧画好后 再收掉 —— 不再先闪一个白底、系统标题栏的空窗口。它不激活、不进任务栏, 配色跟随用户选的主题(system / light / dark),进度条只重画自己那一条。 - 启动闸门:窗口建好先 cloak,前端 cmpWinReady 报到后再露面;托盘模式不自动 露面,4 秒没报到就强制显示。窗口、WebView2 和消息循环 LockOSThread。 - 更新说明:关于弹窗里改成一行「更新说明 v2026.11.17 … 打开」,正文搬到独立 弹窗(照 magpie 的 What's new);标题、圆点列表、行内代码和链接自己渲染。 - 清单:version.json 增加 notesBody(发布流水线用 --rawfile 写整篇说明), 老清单没有这个字段就退回 notes 那句摘要。 - 测试与文档:TestCheckReadsNotesBody;docs/build 补 notesBody 说明。 --- .github/workflows/release.yml | 4 + cmd/markpic/splash_windows.go | 399 ++++++++++++++++++++++++++ cmd/markpic/startup_windows.go | 217 ++++++++++++++ cmd/markpic/tray_windows.go | 2 + cmd/markpic/window_windows.go | 37 ++- docs/build.md | 3 +- docs/build.zh-CN.md | 1 + internal/app/update.go | 2 + internal/update/update.go | 3 + internal/update/update_test.go | 41 +++ web/src/App.vue | 41 ++- web/src/api.ts | 11 + web/src/components/AboutDialog.vue | 62 ++-- web/src/components/ReleaseNotes.vue | 177 ++++++++++++ web/src/components/WhatsNewDialog.vue | 156 ++++++++++ web/src/composables/useUpdate.ts | 1 + web/src/i18n/en.ts | 6 + web/src/i18n/zh.ts | 6 + web/src/types.ts | 2 + 19 files changed, 1124 insertions(+), 47 deletions(-) create mode 100644 cmd/markpic/splash_windows.go create mode 100644 cmd/markpic/startup_windows.go create mode 100644 web/src/components/ReleaseNotes.vue create mode 100644 web/src/components/WhatsNewDialog.vue diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c30940b..88115e9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -359,15 +359,19 @@ jobs: URL="https://github.com/$REPOSITORY/releases/download/$TAG/$ASSET" mkdir -p "$RUNNER_TEMP/manifest" + # notes 是给「有新版本」那一行看的一句话摘要;notesBody 是整篇更新说明 + # ——程序里的「更新说明」对话框读的是它,不用再连一次 GitHub。 jq -n \ --arg version "$VERSION" \ --arg tag "$TAG" \ --arg published "$PUBLISHED" \ --arg notes "$ONELINE" \ + --rawfile notesBody "$RUNNER_TEMP/notes.md" \ --arg url "$URL" \ --arg sha256 "$SHA" \ --argjson size "$SIZE" \ '{version: $version, tag: $tag, published: $published, notes: $notes, + notesBody: $notesBody, windows: {amd64: {url: $url, sha256: $sha256, size: $size}}}' \ > "$RUNNER_TEMP/manifest/version.json" diff --git a/cmd/markpic/splash_windows.go b/cmd/markpic/splash_windows.go new file mode 100644 index 0000000..f9b9420 --- /dev/null +++ b/cmd/markpic/splash_windows.go @@ -0,0 +1,399 @@ +//go:build windows + +package main + +import ( + "math" + "sync" + "syscall" + "unsafe" +) + +// 启动画面:双击之后马上给一张「正在启动」的窗口,而不是等 WebView2 起来。 +// +// 主窗口要等 WebView2 初始化完(冷启动几百毫秒到一两秒)才有内容,这段时间 +// 它被启动闸门 cloaked 住、看不见(见 startup_windows.go)。于是这里再开一张 +// 同尺寸、同位置的无边框窗口,用 GDI 画上标志、名字和一条往返的进度条 —— +// 它不依赖 WebView2,建出来只要几毫秒,所以是「双击即出现」。 +// +// 主窗口一露面就把这张图收掉;它不做任何交互(WS_EX_NOACTIVATE),也不进 +// 任务栏和 Alt+Tab(WS_EX_TOOLWINDOW),所以不会抢焦点、不会留痕。 +// +// 配色跟主窗口一样来自用户上次选的主题(system / light / dark),不自己猜。 + +const ( + splashClass = "MarkPicSplash" + + wsPopup = 0x80000000 + wsExToolWindow = 0x00000080 + wsExNoActivate = 0x08000000 + + swShowNoActivate = 4 + + diNormal = 3 + + dtCenter = 0x0001 + dtVCenter = 0x0004 + dtSingleLine = 0x0020 + dtNoPrefix = 0x0800 + + wmPaint = 0x000F + wmTimer = 0x0113 + wmDestroy = 0x0002 + wmErase = 0x0014 + + defaultCharset = 1 + cleartype = 5 + fwSemibold = 600 + splashTimerID = 1 + splashTimerMS = 16 + splashCycleSecs = 1.2 +) + +var ( + gdi32Splash = syscall.NewLazyDLL("gdi32.dll") + + procRegisterClassExW = user32.NewProc("RegisterClassExW") + procCreateWindowExW = user32.NewProc("CreateWindowExW") + procDefWindowProcW = user32.NewProc("DefWindowProcW") + procSetTimer = user32.NewProc("SetTimer") + procKillTimer = user32.NewProc("KillTimer") + procLoadCursorW = user32.NewProc("LoadCursorW") + procDrawIconEx = user32.NewProc("DrawIconEx") + + // DestroyWindow / BeginPaint / EndPaint / InvalidateRect / SelectObject / + // SetBkMode / SetTextColor / CreateFontW / DrawTextW 都在 traymenu_windows.go + // 里声明过了,同一个包直接复用;只补一个它没有的 DeleteObject。 + procDeleteObjectGDI = gdi32Splash.NewProc("DeleteObject") +) + +type wndClassEx struct { + cbSize uint32 + style uint32 + lpfnWndProc uintptr + cbClsExtra int32 + cbWndExtra int32 + hInstance uintptr + hIcon uintptr + hCursor uintptr + hbrBackground uintptr + lpszMenuName *uint16 + lpszClassName *uint16 + hIconSm uintptr +} + +type splashWindow struct { + hwnd uintptr + scale float64 + dark bool + phase float64 + + bg uintptr + track uintptr + accent uintptr + title uintptr + icon uintptr +} + +var ( + splashMu sync.Mutex + splashWin *splashWindow + splashProc = syscall.NewCallback(splashWndProc) +) + +// showSplash 建出启动画面并立刻显示(不激活)。width/height 是主窗口的物理 +// 像素尺寸,splash 与它完全重合,主窗口露面时像是同一块地方换了内容。 +func showSplash(width, height uint, scale float64, dark bool) { + if splashWin != nil || width == 0 || height == 0 { + return + } + s := &splashWindow{scale: scale, dark: dark} + + className, _ := syscall.UTF16PtrFromString(splashClass) + hInst, _, _ := procGetModuleHandle.Call(0) + + wc := wndClassEx{ + style: 0x0020, // CS_OWNDC,画图不用每次取 DC + lpfnWndProc: splashProc, + hInstance: hInst, + hCursor: loadArrowCursor(), + lpszClassName: className, + } + wc.cbSize = uint32(unsafe.Sizeof(wc)) + procRegisterClassExW.Call(uintptr(unsafe.Pointer(&wc))) + + sw, _, _ := procGetSystemMetrics.Call(smCxScreen) + sh, _, _ := procGetSystemMetrics.Call(smCyScreen) + x := (int32(sw) - int32(width)) / 2 + y := (int32(sh) - int32(height)) / 2 + + s.hwnd, _, _ = procCreateWindowExW.Call( + uintptr(wsExToolWindow|wsExNoActivate), + uintptr(unsafe.Pointer(className)), + 0, + uintptr(wsPopup), + uintptr(x), uintptr(y), + uintptr(width), uintptr(height), + 0, 0, hInst, 0, + ) + if s.hwnd == 0 { + return + } + + s.prepareResources() + splashMu.Lock() + splashWin = s + splashMu.Unlock() + + // 圆角、深色边框之类交给 DWM,和主窗口同一套 + applySplashFrame(s.hwnd, dark) + procShowWindow.Call(s.hwnd, swShowNoActivate) + // 立刻自己画一遍:紧接着就去初始化 WebView2 了,等消息循环来发 WM_PAINT + // 可能还要几百毫秒(核对过:冷启动时那段时间窗口是全黑的)。 + if hdc, _, _ := procGetDC.Call(s.hwnd); hdc != 0 { + s.paint(hdc) + procReleaseDC.Call(s.hwnd, hdc) + } + procSetTimer.Call(s.hwnd, splashTimerID, splashTimerMS, 0) +} + +// closeSplash 收掉启动画面。主窗口已经画好了再叫它,中间不会露出桌面。 +func closeSplash() { + splashMu.Lock() + s := splashWin + splashWin = nil + splashMu.Unlock() + if s == nil || s.hwnd == 0 { + return + } + procKillTimer.Call(s.hwnd, splashTimerID) + procDestroyWindow.Call(s.hwnd) + s.hwnd = 0 + s.releaseResources() +} + +func (s *splashWindow) releaseResources() { + for _, h := range []uintptr{s.bg, s.track, s.accent, s.title} { + if h != 0 { + procDeleteObjectGDI.Call(h) + } + } + s.bg, s.track, s.accent, s.title = 0, 0, 0, 0 +} + +func loadArrowCursor() uintptr { + c, _, _ := procLoadCursorW.Call(0, 32512) // IDC_ARROW + return c +} + +// applySplashFrame 让启动画面和主窗口一样是圆角、无描边,并跟随深色主题。 +func applySplashFrame(hwnd uintptr, dark bool) { + v := int32(0) + if dark { + v = 1 + } + procDwmSetAttribute.Call(hwnd, dwmwaUseImmersiveDarkMode, uintptr(unsafe.Pointer(&v)), unsafe.Sizeof(v)) + corner := int32(dwmcpRound) + procDwmSetAttribute.Call(hwnd, dwmwaWindowCornerPreference, uintptr(unsafe.Pointer(&corner)), unsafe.Sizeof(corner)) + border := uint32(dwmwaColorNone) + procDwmSetAttribute.Call(hwnd, dwmwaBorderColor, uintptr(unsafe.Pointer(&border)), unsafe.Sizeof(border)) +} + +// prepareResources 建一次画刷与字体:画的时候只换颜色,不再反复创建。 +func (s *splashWindow) prepareResources() { + bg, track, accent := colorCanvasLight, colorTrackLight, colorAccentLight + if s.dark { + bg, track, accent = colorCanvasDark, colorTrackDark, colorAccentDark + } + s.bg = solidBrush(bg) + s.track = solidBrush(track) + s.accent = solidBrush(accent) + + // 标题用界面同款字体;字号按当前屏缩放折算成物理像素。 + face, _ := syscall.UTF16PtrFromString("Segoe UI") + size := int32(math.Round(21 * s.scale)) + s.title, _, _ = procCreateFont.Call( + uintptr(uint32(int32(-size))), 0, 0, 0, + fwSemibold, 0, 0, 0, + defaultCharset, 0, 0, cleartype, 0, + uintptr(unsafe.Pointer(face)), + ) + + group := themeIconGroup(s.dark) + if group != 0 { + hInst, _, _ := procGetModuleHandle.Call(0) + iconSize := uintptr(math.Round(56 * s.scale)) + s.icon, _, _ = procLoadImage.Call(hInst, group, imageIcon, iconSize, iconSize, lrShared) + } +} + +func (s *splashWindow) paint(hdc uintptr) { + var rc rect32 + procGetClientRect.Call(s.hwnd, uintptr(unsafe.Pointer(&rc))) + if rc.right <= 0 || rc.bottom <= 0 { + return + } + procFillRect.Call(hdc, uintptr(unsafe.Pointer(&rc)), s.bg) + + iconSize := int32(math.Round(56 * s.scale)) + gap := int32(math.Round(20 * s.scale)) + titleH := int32(math.Round(30 * s.scale)) + barH := int32(math.Round(3 * s.scale)) + barGap := int32(math.Round(22 * s.scale)) + + blockH := iconSize + gap + titleH + barGap + barH + top := (rc.bottom - blockH) / 2 + if top < 0 { + top = 0 + } + cx := (rc.right + rc.left) / 2 + + if s.icon != 0 { + procDrawIconEx.Call( + hdc, + uintptr(cx-iconSize/2), uintptr(top), + s.icon, + uintptr(iconSize), uintptr(iconSize), + 0, 0, diNormal, + ) + } + + // 名字 + if s.title != 0 { + old, _, _ := procSelectObject.Call(hdc, s.title) + procSetBkMode.Call(hdc, 1) // TRANSPARENT + ink := colorInkLight + if s.dark { + ink = colorInkDark + } + procSetTextColor.Call(hdc, uintptr(ink)) + text, _ := syscall.UTF16PtrFromString("MarkPic") + tr := rect32{ + left: rc.left, + top: top + iconSize + gap, + right: rc.right, + bottom: top + iconSize + gap + titleH, + } + procDrawText.Call( + hdc, uintptr(unsafe.Pointer(text)), ^uintptr(0), + uintptr(unsafe.Pointer(&tr)), + dtCenter|dtVCenter|dtSingleLine|dtNoPrefix, + ) + procSelectObject.Call(hdc, old) + } + + // 进度条:轨道 + 一段往返的强调色 + bar := s.barRect() + procFillRect.Call(hdc, uintptr(unsafe.Pointer(&bar)), s.track) + + segW := int32(float64(bar.right-bar.left) * 0.34) + span := (bar.right - bar.left) - segW + t := easeInOut(s.phase) + segLeft := bar.left + int32(float64(span)*t) + seg := rect32{left: segLeft, top: bar.top, right: segLeft + segW, bottom: bar.bottom} + procFillRect.Call(hdc, uintptr(unsafe.Pointer(&seg)), s.accent) +} + +// barRect 是进度条在客户区里的位置(和 paint 里同一套排布)。 +func (s *splashWindow) barRect() rect32 { + var rc rect32 + procGetClientRect.Call(s.hwnd, uintptr(unsafe.Pointer(&rc))) + iconSize := int32(math.Round(56 * s.scale)) + gap := int32(math.Round(20 * s.scale)) + titleH := int32(math.Round(30 * s.scale)) + barW := int32(math.Round(176 * s.scale)) + barH := int32(math.Round(3 * s.scale)) + barGap := int32(math.Round(22 * s.scale)) + blockH := iconSize + gap + titleH + barGap + barH + top := (rc.bottom - blockH) / 2 + if top < 0 { + top = 0 + } + cx := (rc.right + rc.left) / 2 + barTop := top + iconSize + gap + titleH + barGap + return rect32{left: cx - barW/2, top: barTop, right: cx + barW/2, bottom: barTop + barH} +} + +// easeInOut 让进度条两头慢、中间快,比匀速更像「在加载」。 +func easeInOut(t float64) float64 { + if t < 0 { + t = 0 + } else if t > 1 { + t = 1 + } + return t * t * (3 - 2*t) +} + +func splashWndProc(hwnd, msg, wp, lp uintptr) uintptr { + s := currentSplash(hwnd) + switch msg { + case wmErase: + return 1 // 全部自己画,别让系统先刷一遍白 + case wmPaint: + var ps paintStruct + hdc, _, _ := procBeginPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps))) + if s != nil && hdc != 0 { + s.paint(hdc) + } + procEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps))) + return 0 + case wmTimer: + if s != nil && wp == splashTimerID { + step := float64(splashTimerMS) / 1000 / splashCycleSecs + s.phase += step + if s.phase > 1 { + s.phase -= 1 + } + // 只重画进度条那一条:4K 屏上整窗重绘 60 次每秒不划算。 + bar := s.barRect() + procInvalidateRect.Call(hwnd, uintptr(unsafe.Pointer(&bar)), 0) + } + return 0 + case wmDestroy: + return 0 + } + r, _, _ := procDefWindowProcW.Call(hwnd, msg, wp, lp) + return r +} + +func currentSplash(hwnd uintptr) *splashWindow { + splashMu.Lock() + defer splashMu.Unlock() + if splashWin != nil && splashWin.hwnd == hwnd { + return splashWin + } + return nil +} + +type paintStruct struct { + hdc uintptr + fErase int32 + rcPaint rect32 + fRestore int32 + fIncUpdate int32 + rgbReserved [32]byte +} + +func solidBrush(color uint32) uintptr { + b, _, _ := procCreateSolidBrush.Call(uintptr(color)) + return b +} + +// 与 tokens.css 同一组值。 +const ( + colorCanvasLight uint32 = 0x00f6f1ee // #eef1f6 (COLORREF 是 BGR) + colorTrackLight uint32 = 0x00f3ece7 // #e7ecf3 + colorAccentLight uint32 = 0x0090740e // #0e7490 + colorInkLight uint32 = 0x001f1612 // #12161f + + colorCanvasDark uint32 = 0x00140e0b // #0b0e14 + colorTrackDark uint32 = 0x0018110d // #0d1118 + colorAccentDark uint32 = 0x00e2d658 // #58d6e2 + colorInkDark uint32 = 0x00f4ece8 // #e8ecf4 +) + +// GetSystemMetrics 的索引(主屏尺寸,和库建窗时的 Center 算法保持一致) +const ( + smCxScreen = 0 + smCyScreen = 1 +) diff --git a/cmd/markpic/startup_windows.go b/cmd/markpic/startup_windows.go new file mode 100644 index 0000000..549dc48 --- /dev/null +++ b/cmd/markpic/startup_windows.go @@ -0,0 +1,217 @@ +//go:build windows + +package main + +import ( + "sync" + "syscall" + "time" + "unsafe" +) + +// 启动闸门:让窗口「先存在、后露面」。 +// +// go-webview2 建窗口的顺序是 CreateWindowEx → ShowWindow → UpdateWindow, +// 之后才去初始化 WebView2(它的 CreateWithOptions 里 Embed 要等环境建好, +// 冷启动几百毫秒到一两秒)。这段时间屏幕上是「白底 + 系统标题栏」的原生空 +// 窗口,跟我们的界面没有一点关系 —— 双击后先闪一个不像自己的窗口,再变成 +// 自绘标题栏的界面,就是它。 +// +// 库没有「先别 Show」的开关,所以在建窗口之前挂一个本线程的 CBT 钩子:窗口 +// 即将被激活(ShowWindow 把它变成可见的那一刻)时,用 DWM cloak 把它从合成 +// 里摘掉 —— 窗口照常收消息、WebView2 照常在里面初始化,只是不显示。等前端 +// 画完首屏、通过 cmpWinReady 报到之后,再取消 cloak 让它露面。 +// +// 为什么不在 HCBT_CREATEWND 里就做:那一刻窗口刚分配出来,还没挂上 DWM, +// DwmSetWindowAttribute 会回 E_HANDLE;挪位置也不行,CreateWindowEx 是在返回 +// 前才把 x/y 落到窗口上,挪了会被盖回去。 +// +// 兜底分两层:cloak 用不了就在激活时把窗口挪到屏幕外;钩子整个没拦住就在建完 +// 之后把窗口藏起来。前端一直不报到的话,Navigate 之后 startupRevealFallback +// 会强制露面 —— 界面再慢,也不该让人以为程序没打开。 + +const ( + whCbt = 5 + hcbtActivate = 5 + + // DWMWA_CLOAK 没有公开的常量名,值是 13:窗口不参与 DWM 合成,屏幕上看不见。 + dwmwaCloak = 13 + + // 库注册的窗口类名。钩子里靠它认出「这是我们自己的窗口」。 + webviewWindowClass = "webview" + + // cloak 用不了时藏窗口用的屏幕外坐标。 + parkX = -32000 + parkY = -32000 + + // 等前端报到最多等这么久,超时就先露出来。 + startupRevealFallback = 4 * time.Second +) + +var ( + kernel32Startup = syscall.NewLazyDLL("kernel32.dll") + procGetCurrentThreadID = kernel32Startup.NewProc("GetCurrentThreadId") + procGetClassNameW = user32.NewProc("GetClassNameW") + procSetWindowsHookExW = user32.NewProc("SetWindowsHookExW") + procUnhookWindowsHookEx = user32.NewProc("UnhookWindowsHookEx") + procCallNextHookEx = user32.NewProc("CallNextHookEx") +) + +// startupGate 是单窗口程序的启动状态:和 chromeWindow 一样用包级变量。 +type startupGate struct { + mu sync.Mutex + hook uintptr // CBT 钩子句柄,建完窗口就摘掉 + hwnd uintptr // 钩子里认出来的主窗口 + + cloaked bool // DWM cloak 成功:窗口已经 Show 过,但看不见 + parked bool // cloak 不可用时的退路:窗口被挪到屏幕外 + parkedAt rect32 // 挪之前的位置 + + autoShow bool // 前端报到时是否自动露面(「启动时只留托盘」时不) + revealed bool // 已经露过面,后续 Show / 托盘回来不再重复处理 +} + +var startup = &startupGate{} + +// holdStartupWindow 在 webview2.NewWithOptions 之前调用:挂钩子,拦住第一个 +// 窗口。autoShow 为 false 时只藏不自动露面(托盘模式,等用户点托盘)。 +func holdStartupWindow(autoShow bool) { + startup.mu.Lock() + startup.autoShow = autoShow + startup.mu.Unlock() + + // 钩子只认本线程:窗口是在这个线程上建的,没必要做成全局钩子。 + tid, _, _ := procGetCurrentThreadID.Call() + startup.hook, _, _ = procSetWindowsHookExW.Call( + whCbt, + syscall.NewCallback(startupHookProc), + 0, + tid, + ) +} + +// releaseStartupHook 在窗口建好之后调用:钩子只为了拦这一次创建。 +func releaseStartupHook() { + startup.mu.Lock() + hook := startup.hook + startup.hook = 0 + startup.mu.Unlock() + if hook != 0 { + procUnhookWindowsHookEx.Call(hook) + } +} + +func startupHookProc(nCode int, wParam, lParam uintptr) uintptr { + if nCode == hcbtActivate { + startup.hide(wParam) + } + ret, _, _ := procCallNextHookEx.Call(0, uintptr(nCode), wParam, lParam) + return ret +} + +// hide 在窗口即将被激活时把它藏起来:先试 DWM cloak,不行就挪到屏幕外。 +func (s *startupGate) hide(hwnd uintptr) { + if hwnd == 0 || windowClassName(hwnd) != webviewWindowClass { + return + } + s.mu.Lock() + defer s.mu.Unlock() + if s.hwnd != 0 { + return + } + s.hwnd = hwnd + + one := int32(1) + hr, _, _ := procDwmSetAttribute.Call( + hwnd, dwmwaCloak, uintptr(unsafe.Pointer(&one)), unsafe.Sizeof(one), + ) + if hr == 0 { + s.cloaked = true + return + } + + var r rect32 + procGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&r))) + x, y := int32(parkX), int32(parkY) + procSetWindowPos.Call( + hwnd, 0, + uintptr(x), uintptr(y), + uintptr(r.right-r.left), uintptr(r.bottom-r.top), + swpNoZOrder|swpNoActivate, + ) + s.parked = true + s.parkedAt = r +} + +// concealStartupWindow 在窗口建好之后调用:钩子没拦住(类名对不上之类)就 +// 退而求其次,直接把窗口藏起来 —— 用户至少不会盯着那块白板等 WebView2 起来。 +func concealStartupWindow() { + startup.mu.Lock() + hwnd, hidden := startup.hwnd, startup.cloaked || startup.parked + startup.mu.Unlock() + if hwnd != 0 && !hidden { + procShowWindow.Call(hwnd, swHide) + } +} + +// markStartupWindowReady 由前端在首屏画完之后调用(cmpWinReady)。 +func markStartupWindowReady() { + startup.mu.Lock() + auto := startup.autoShow + startup.mu.Unlock() + if !auto { + return + } + revealStartupWindow() +} + +// allowStartupReveal 用于「本来只想进托盘,但托盘图标没挂上」的情况: +// 不露面的话用户既看不见窗口,也找不到托盘入口。 +func allowStartupReveal() { + startup.mu.Lock() + startup.autoShow = true + startup.mu.Unlock() +} + +// revealStartupWindow 把窗口摆回本来的位置并露面。重复调用无害。 +// 必须在窗口线程上调用(绑定回调与 showFromTray 都在窗口线程)。 +func revealStartupWindow() { + s := startup + s.mu.Lock() + if s.revealed || s.hwnd == 0 { + s.mu.Unlock() + return + } + s.revealed = true + hwnd, cloaked, parked, at := s.hwnd, s.cloaked, s.parked, s.parkedAt + s.mu.Unlock() + + if cloaked { + zero := int32(0) + procDwmSetAttribute.Call( + hwnd, dwmwaCloak, uintptr(unsafe.Pointer(&zero)), unsafe.Sizeof(zero), + ) + } + if parked { + procSetWindowPos.Call( + hwnd, 0, + uintptr(at.left), uintptr(at.top), + uintptr(at.right-at.left), uintptr(at.bottom-at.top), + swpNoZOrder|swpNoActivate, + ) + } + procShowWindow.Call(hwnd, swShow) + procSetForeground.Call(hwnd) + // 主窗口已经画好了,再把启动画面收掉 —— 中间不会露出桌面。 + closeSplash() +} + +// windowClassName 取窗口的类名(最多 64 个 UTF-16 字符)。 +func windowClassName(hwnd uintptr) string { + buf := make([]uint16, 64) + n, _, _ := procGetClassNameW.Call(hwnd, uintptr(unsafe.Pointer(&buf[0])), uintptr(len(buf))) + if n == 0 { + return "" + } + return syscall.UTF16ToString(buf[:n]) +} diff --git a/cmd/markpic/tray_windows.go b/cmd/markpic/tray_windows.go index ee4e7bd..0198ce7 100644 --- a/cmd/markpic/tray_windows.go +++ b/cmd/markpic/tray_windows.go @@ -221,6 +221,8 @@ func hideToTray() bool { // showFromTray 从托盘或最小化状态回到屏幕。托盘图标从启动一直挂到退出, // 不在这里摘:窗口回来了,通知区那个入口仍然在(用户要求与 Mac 版一致)。 func showFromTray() { + // 启动时窗口被 cloak 住还没露过面的话,先揭开 —— 只 Show 是看不见的。 + revealStartupWindow() hwnd := hwndValue() if hwnd == 0 { return diff --git a/cmd/markpic/window_windows.go b/cmd/markpic/window_windows.go index 81db540..58636c1 100644 --- a/cmd/markpic/window_windows.go +++ b/cmd/markpic/window_windows.go @@ -9,7 +9,9 @@ import ( "log" "math" "os" + "runtime" "syscall" + "time" webview2 "github.com/jchv/go-webview2" @@ -37,6 +39,12 @@ var ( // openAppWindow 在原生窗口里打开界面,并在传给 stop 的通道收到信号时关掉窗口。 // 窗口被用户关闭后返回 nil;拿不到 WebView2 时返回 errNoWebView2。 func openAppWindow(indexURL, title string, desktop *app.App, stop <-chan os.Signal) error { + // 窗口、WebView2 和消息循环必须在同一个 OS 线程上:Go 的 goroutine 会被调度 + // 到别的线程去,而 Windows 的窗口消息只投递给创建它的那个线程。启动闸门的 + // CBT 钩子也是按线程挂的,不锁线程就会挂到一条「已经不在跑这段代码」的线上。 + runtime.LockOSThread() + defer runtime.UnlockOSThread() + // 尺寸与内边距都是按 96 DPI 设计的,窗口要按显示器缩放折算成物理像素, // 这样在 125% / 150% 的屏幕上界面「看上去」还是同样大小(内容由 WebView 自己按缩放渲染)。 scale := systemScale() @@ -50,6 +58,18 @@ func openAppWindow(indexURL, title string, desktop *app.App, stop <-chan os.Sign height = uint(math.Round(float64(saved.Height) * scale)) } + // 先挂一张同尺寸的「正在启动」画面:主窗口要等 WebView2 起来才有内容, + // 这张图几毫秒就能画出来,双击后立刻有反应(见 splash_windows.go)。 + if !desktop.StartInTray() { + showSplash(width, height, scale, resolveThemeDark(startupThemeChoice())) + defer closeSplash() + } + + // 窗口建出来之后先别让人看见:库建完窗口立刻 ShowWindow,而 WebView2 要 + // 再过几百毫秒才初始化完,那段时间屏幕上是白底 + 系统标题栏的空窗口。 + // 钩子在这里挂、下一个窗口创建时生效(见 startup_windows.go)。 + holdStartupWindow(!desktop.StartInTray()) + w := webview2.NewWithOptions(webview2.WebViewOptions{ AutoFocus: true, // 默认会把用户数据放在 exe 旁边(污染绿色版目录),改放到本机应用数据里。 @@ -63,6 +83,7 @@ func openAppWindow(indexURL, title string, desktop *app.App, stop <-chan os.Sign IconId: 1, }, }) + releaseStartupHook() if w == nil { return errNoWebView2 } @@ -70,6 +91,8 @@ func openAppWindow(indexURL, title string, desktop *app.App, stop <-chan os.Sign // 去掉系统标题栏,标题栏交给前端画(Magpie 风格)。 installWindowChrome(w) + // cloak 万一没成功:至少别让用户盯着那块白板等 WebView2 起来。 + concealStartupWindow() // 托盘图标跟进程同寿:窗口开着也在通知区留一个入口(用户要求与 Mac 版 // 一致),只有真正退出程序才摘掉。挂不上不影响窗口继续用。 @@ -85,7 +108,11 @@ func openAppWindow(indexURL, title string, desktop *app.App, stop <-chan os.Sign // hideToTray 自己保证「先挂上托盘图标再藏窗口」,挂不上就不藏 —— // 否则用户既看不见窗口,也找不到托盘入口。 if desktop.StartInTray() { - hideToTray() + if !hideToTray() { + // 托盘图标没挂上就不藏:前端报到时照常露面,否则用户既看不见窗口、 + // 也找不到托盘入口。启动闸门在那种情况下也得跟着放行。 + allowStartupReveal() + } } if err := bindBridge(w, desktop); err != nil { @@ -121,6 +148,10 @@ func openAppWindow(indexURL, title string, desktop *app.App, stop <-chan os.Sign } w.Navigate(indexURL) + // 前端一直不报到就先露出来:界面再慢,也不该让人以为程序没打开。 + time.AfterFunc(startupRevealFallback, func() { + w.Dispatch(func() { markStartupWindowReady() }) + }) w.Run() return nil } @@ -177,6 +208,10 @@ func bindWindowCommands(w webview2.WebView, desktop *app.App) { }}, {"cmpWinTheme", func(choice string) { applyThemeChoice(w, choice) }}, {"cmpWinFlash", func() { flashTaskbar() }}, + // 前端首屏画完了:揭开启动时 cloak 住的窗口(见 startup_windows.go)。 + {"cmpWinReady", func() { + w.Dispatch(func() { markStartupWindowReady() }) + }}, {"cmpWinSnapZone", func(x, y, w, h int) { placeSnapOverlay(x, y, w, h) }}, } for _, b := range binds { diff --git a/docs/build.md b/docs/build.md index 401866c..ef65c40 100644 --- a/docs/build.md +++ b/docs/build.md @@ -60,7 +60,8 @@ they are not regenerated. same day becomes `2026.11.17.1` and so on, discovered from tags. - A commit subject containing `[no-release]` builds and tests, but publishes nothing. - The release carries the executable plus `version.json`, the manifest that clients - read to find updates. Nothing is pushed back to the repository. + read to find updates. Nothing is pushed back to the repository. The manifest also + carries `notesBody`, the full release notes the in-app “What's new” dialog shows. - Release notes are generated by `scripts/release-notes.mjs` from the commits since the previous tag. Preview them locally with: diff --git a/docs/build.zh-CN.md b/docs/build.zh-CN.md index f7edfe2..629437c 100644 --- a/docs/build.zh-CN.md +++ b/docs/build.zh-CN.md @@ -57,6 +57,7 @@ `2026.11.17.1`,靠 tag 探测,不落状态。 - 提交标题里带 `[no-release]` 时照常构建和跑测试,但不发布。 - 发布产物是 exe 加 `version.json`——客户端靠这份清单发现更新。整个流程不往仓库里推东西。 + 清单里的 `notesBody` 是整篇更新说明,程序的「更新说明」对话框直接读它。 - 更新说明由 `scripts/release-notes.mjs` 从上一次 tag 到现在的提交生成。本地预览: ```bash diff --git a/internal/app/update.go b/internal/app/update.go index b3a4f27..ade8117 100644 --- a/internal/app/update.go +++ b/internal/app/update.go @@ -19,6 +19,7 @@ type updateStatus struct { Latest string `json:"latest"` Tag string `json:"tag"` Notes string `json:"notes"` + NotesBody string `json:"notesBody"` Published string `json:"published"` Asset update.Asset `json:"asset"` Received int64 `json:"received"` @@ -62,6 +63,7 @@ func (t *updateTracker) applyRelease(rel *update.Release) { t.status.Latest = rel.Latest t.status.Tag = rel.Tag t.status.Notes = rel.Notes + t.status.NotesBody = rel.NotesBody t.status.Published = rel.Published t.status.Asset = rel.Asset t.status.Received, t.status.Total = 0, rel.Asset.Size diff --git a/internal/update/update.go b/internal/update/update.go index 9ecf295..c57a913 100644 --- a/internal/update/update.go +++ b/internal/update/update.go @@ -84,6 +84,7 @@ type Release struct { Latest string Tag string Notes string + NotesBody string // 发布说明正文(Markdown),可能为空:老清单里没有 Published string Asset Asset HasUpdate bool @@ -94,6 +95,7 @@ type manifest struct { Tag string `json:"tag"` Notes string `json:"notes"` Published string `json:"published"` + NotesBody string `json:"notesBody"` Windows map[string]Asset `json:"windows"` } @@ -139,6 +141,7 @@ func Check(ctx context.Context, current, arch string, lang i18n.Lang) (*Release, } release := &Release{ + NotesBody: strings.TrimSpace(m.NotesBody), Current: current, Latest: strings.TrimSpace(m.Version), Tag: strings.TrimSpace(m.Tag), diff --git a/internal/update/update_test.go b/internal/update/update_test.go index 9a45513..27bf74b 100644 --- a/internal/update/update_test.go +++ b/internal/update/update_test.go @@ -178,6 +178,47 @@ func TestCheckAcceptsOnlyRealUpgrades(t *testing.T) { }) } +func TestCheckReadsNotesBody(t *testing.T) { + const sha = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" + + // 整篇更新说明走 notesBody:程序里的「更新说明」对话框读它, + // notes 仍然只留给关于里那一行摘要。 + t.Run("清单带 notesBody 就读进来", func(t *testing.T) { + body := fmt.Sprintf(`{ + "version": "1.2.0", "tag": "v1.2.0", "notes": "一句话简介", "published": "2026-01-01", + "notesBody": "## v1.2.0(2026-01-01)\n\n### ✨ 新功能\n- 第一条\n", + "windows": {"amd64": {"url": "http://example.invalid/a.exe", "sha256": %q, "size": 3}} +}`, sha) + srv := manifestServer(t, body, http.StatusOK) + t.Setenv(ManifestEnv, srv.URL) + + rel, err := Check(context.Background(), "1.0.0", "amd64", i18n.ZH) + if err != nil { + t.Fatalf("不该报错:%v", err) + } + want := "## v1.2.0(2026-01-01)\n\n### ✨ 新功能\n- 第一条" + if rel.NotesBody != want { + t.Errorf("notesBody = %q,想要 %q", rel.NotesBody, want) + } + if rel.Notes != "一句话简介" { + t.Errorf("notes 该还是一句话摘要:%q", rel.Notes) + } + }) + + t.Run("老清单没有 notesBody 就是空串", func(t *testing.T) { + srv := manifestServer(t, manifestWith("1.2.0", "amd64", "http://example.invalid/a.exe", sha), http.StatusOK) + t.Setenv(ManifestEnv, srv.URL) + + rel, err := Check(context.Background(), "1.0.0", "amd64", i18n.ZH) + if err != nil { + t.Fatalf("不该报错:%v", err) + } + if rel.NotesBody != "" { + t.Errorf("没有 notesBody 时该是空串,实际 %q", rel.NotesBody) + } + }) +} + func TestDownloadVerifiesHash(t *testing.T) { payload := []byte("假装这是一个 exe") sum := sha256.Sum256(payload) diff --git a/web/src/App.vue b/web/src/App.vue index 857f998..507bfe3 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -11,9 +11,11 @@ import DownloadPage from './components/DownloadPage.vue' import FileQueue from './components/FileQueue.vue' import OptionsPanel from './components/OptionsPanel.vue' import ToastStack from './components/ToastStack.vue' +import WhatsNewDialog from './components/WhatsNewDialog.vue' import { describeError, isDialogUnsupported, + markWindowReady, pickFiles, pickFolder, revealPath, @@ -178,6 +180,17 @@ const runningElsewhere = computed(() => { }) const aboutOpen = ref(false) +/** + * 「更新说明」弹窗:从关于里点「打开」进来,关于本身先关掉 —— 两个弹窗叠在一起 + * 既挡视线又难退出,一次只留一个。 + */ +const whatsNewOpen = ref(false) + +function openWhatsNew(): void { + aboutOpen.value = false + whatsNewOpen.value = true +} + /** * 点叉号需要确认的两种情况(见 cmd/markpic/chrome_windows.go 的 WM_CLOSE): * - 没有任务、设置是「每次询问」:选「最小化」还是「退出程序」,可勾「不再询问」, @@ -535,6 +548,10 @@ function handleKeydown(event: KeyboardEvent): void { closePrompt.value = false return } + if (whatsNewOpen.value) { + whatsNewOpen.value = false + return + } if (aboutOpen.value) { aboutOpen.value = false return @@ -561,6 +578,22 @@ function handleKeydown(event: KeyboardEvent): void { } } +/** + * 首屏画完再让原生窗口露面。 + * + * 启动时窗口是 cloak 着的(见 cmd/markpic/startup_windows.go):报到之前用户 + * 根本看不到窗口,也就不会先看见一个白底、带系统标题栏的空窗口。两份首屏数据 + * 落地、再等两帧把界面画出来,报到才算数。 + */ +async function revealWindowWhenReady(firstLoad: Promise): Promise { + await firstLoad.catch(() => undefined) + await nextTick() + await new Promise((resolve) => { + window.requestAnimationFrame(() => window.requestAnimationFrame(() => resolve())) + }) + markWindowReady() +} + onMounted(() => { // 后端点叉号时调用;浏览器预览里没有这个函数,弹窗也就不会出现。 closeBridge.__markpicCloseRequest = handleCloseRequest @@ -571,8 +604,8 @@ onMounted(() => { () => writeQueues(), ) window.setTimeout(() => void restoreQueue(), 700) - void refreshHealth() - void loadSettings() + // 首屏要这两份数据:拿到(或失败)再让原生窗口露面,别把半张空架子推给人。 + void revealWindowWhenReady(Promise.allSettled([refreshHealth(), loadSettings()])) window.addEventListener('keydown', handleKeydown) // 启动后悄悄查一次(可在「关于」里关掉),查到就在侧边栏版本号旁点个记号。 if (autoCheck.value) { @@ -739,8 +772,12 @@ onBeforeUnmount(() => { :data-note="dataNote" :settings-note="settingsNote" @close="aboutOpen = false" + @open-notes="openWhatsNew" /> + + + (method: string, params: unknown = {}): Promise { return reply.data as T } +/** + * 首屏已经画好:让原生窗口露面(见 cmd/markpic/startup_windows.go)。 + * + * 窗口命令走 go-webview2 的直接绑定(和 cmpWinMinimize 一样),没有参数; + * 浏览器预览里没有这个函数,所以是可选调用。 + */ +export function markWindowReady(): void { + const bridge = window as Window & { cmpWinReady?: () => Promise } + void bridge.cmpWinReady?.() +} + /** 把任意异常收敛成一句可展示的文案。 */ export function describeError(error: unknown, fallback: string): string { if (error instanceof ApiError) return error.message.trim() || fallback diff --git a/web/src/components/AboutDialog.vue b/web/src/components/AboutDialog.vue index 83a232b..4892d9f 100644 --- a/web/src/components/AboutDialog.vue +++ b/web/src/components/AboutDialog.vue @@ -16,7 +16,7 @@ const props = defineProps<{ settingsNote?: string }>() -const emit = defineEmits<{ close: [] }>() +const emit = defineEmits<{ close: []; 'open-notes': [] }>() /* 打开就把焦点搬进对话框:键盘操作不该落在背后的页面上 */ const panel = ref(null) @@ -87,8 +87,15 @@ const statusTone = computed(() => { } }) -const notes = computed(() => status.value.notes.trim()) -const published = computed(() => status.value.published.trim()) +/** + * 「更新说明」只留一行:版本号加摘要,够判断值不值得点开。整篇在 WhatsNewDialog 里。 + */ +const notesLine = computed(() => { + const latest = status.value.latest.trim() + if (!latest) return t('about.notesEmpty') + const summary = status.value.notes.trim() + return summary ? `v${latest} · ${summary}` : `v${latest}` +}) const sizeLabel = computed(() => { const size = status.value.asset.size @@ -176,6 +183,15 @@ async function openDataDir(): Promise {
{{ t('about.asset') }}
{{ sizeLabel }}
+
+
{{ t('about.notes') }}
+
+ {{ notesLine }} + +
+
{{ t('about.project') }}
@@ -220,14 +236,6 @@ async function openDataDir(): Promise {
-
-

- {{ t('about.notes') }} - {{ published }} -

-
{{ notes }}
-
-