mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-09-02 17:40:22 +08:00
- 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)
52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
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
|
|
*/
|
|
contextBridge.exposeInMainWorld("electronAPI", {
|
|
// Platform information
|
|
platform: process.platform,
|
|
|
|
// Check if running in Electron
|
|
isElectron: true,
|
|
|
|
// Application version
|
|
getVersion: () => ipcRenderer.invoke("get-version"),
|
|
|
|
// Window controls (optional, for custom title bar)
|
|
minimize: () => ipcRenderer.send("window-minimize"),
|
|
maximize: () => ipcRenderer.send("window-maximize"),
|
|
close: () => ipcRenderer.send("window-close"),
|
|
|
|
// File operations
|
|
openFile: () => ipcRenderer.invoke("dialog-open-file"),
|
|
saveFile: (data: string) => ipcRenderer.invoke("dialog-save-file", data),
|
|
|
|
// Proxy settings
|
|
getProxy: () => ipcRenderer.invoke("get-proxy"),
|
|
setProxy: (config: { httpProxy?: string; httpsProxy?: string }) =>
|
|
ipcRenderer.invoke("set-proxy", config),
|
|
|
|
// User locale settings
|
|
getUserLocale: () => ipcRenderer.invoke("get-user-locale"),
|
|
setUserLocale: (locale: string) =>
|
|
ipcRenderer.invoke("set-user-locale", locale),
|
|
|
|
// Auto-update
|
|
onUpdateStatus: (callback: (data: UpdateStatus) => void) => {
|
|
const handler = (_event: IpcRendererEvent, data: UpdateStatus) =>
|
|
callback(data)
|
|
ipcRenderer.on("update-status", handler)
|
|
return () => ipcRenderer.removeListener("update-status", handler)
|
|
},
|
|
startDownload: () => ipcRenderer.invoke("updater:start-download"),
|
|
})
|