fix: address PR review feedback for auto-update

- Register manual check listeners before checkForUpdates() to avoid race
- Strip prerelease/build metadata in version comparison
- Add res.setEncoding("utf8") for GitHub API response
- Stream file hashing in CI script instead of reading into memory
- Add directory existence checks in fix-latest-yml.mjs
- Define UpdateStatus type locally in preload to avoid tsconfig scope issues
- Show error dialog for manual check failures (parse/network errors)
This commit is contained in:
dayuan.jiang
2026-04-03 17:59:57 +09:00
parent e27afe6f0d
commit 2158d26bbb
3 changed files with 53 additions and 13 deletions

View File

@@ -1,5 +1,13 @@
import { contextBridge, type IpcRendererEvent, ipcRenderer } from "electron"
// Locally defined to avoid dependency on electron.d.ts compilation scope
type UpdateStatus =
| { status: "available"; version: string }
| { status: "available-manual"; version: string; url: string }
| { status: "downloading"; percent: number }
| { status: "downloaded" }
| { status: "error"; message: string }
/**
* Expose safe APIs to the renderer process
*/
@@ -33,8 +41,8 @@ contextBridge.exposeInMainWorld("electronAPI", {
ipcRenderer.invoke("set-user-locale", locale),
// Auto-update
onUpdateStatus: (callback: (data: UpdateStatusData) => void) => {
const handler = (_event: IpcRendererEvent, data: UpdateStatusData) =>
onUpdateStatus: (callback: (data: UpdateStatus) => void) => {
const handler = (_event: IpcRendererEvent, data: UpdateStatus) =>
callback(data)
ipcRenderer.on("update-status", handler)
return () => ipcRenderer.removeListener("update-status", handler)