mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-09-01 17:10:24 +08:00
Closes #613 - Add electron-updater for Windows NSIS and Linux AppImage auto-update - macOS and Linux DEB fall back to GitHub API check with download link - Add "Check for Updates" menu item with i18n (en, zh, ja, zh-Hant) - Fix Windows CI workflow to publish correct latest.yml after code signing - Add update toast notifications in renderer via sonner
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
import { contextBridge, type IpcRendererEvent, ipcRenderer } from "electron"
|
|
|
|
/**
|
|
* 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: UpdateStatusData) => void) => {
|
|
const handler = (_event: IpcRendererEvent, data: UpdateStatusData) =>
|
|
callback(data)
|
|
ipcRenderer.on("update-status", handler)
|
|
return () => ipcRenderer.removeListener("update-status", handler)
|
|
},
|
|
startDownload: () => ipcRenderer.invoke("updater:start-download"),
|
|
})
|