mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-21 06:07:13 +08:00
fix(desktop): correct electron-updater import for commonjs
This commit is contained in:
@@ -4,23 +4,33 @@ let tray: Tray | null = null
|
||||
|
||||
interface TrayDeps {
|
||||
getWindow: () => BrowserWindow | null
|
||||
// Colored icon used on Windows/Linux trays.
|
||||
iconPath?: string
|
||||
// Monochrome (black + alpha) template icon for the macOS menu bar; renders
|
||||
// correctly in both light and dark menu bars when set as a template image.
|
||||
templateIconPath?: string
|
||||
// Called when the user picks "Quit" so the app can fully exit.
|
||||
onQuit: () => void
|
||||
}
|
||||
|
||||
// Build a system tray icon with a minimal menu. The tray lets users restore the
|
||||
// window after closing it to the background and start a new chat quickly.
|
||||
export function createTray({ getWindow, iconPath, onQuit }: TrayDeps): Tray | null {
|
||||
export function createTray({ getWindow, iconPath, templateIconPath, onQuit }: TrayDeps): Tray | null {
|
||||
if (tray) return tray
|
||||
if (!iconPath) return null
|
||||
|
||||
let image = nativeImage.createFromPath(iconPath)
|
||||
const isMac = process.platform === 'darwin'
|
||||
// Prefer the monochrome template icon on macOS (menu-bar convention).
|
||||
const sourcePath = isMac && templateIconPath ? templateIconPath : iconPath
|
||||
if (!sourcePath) return null
|
||||
|
||||
let image = nativeImage.createFromPath(sourcePath)
|
||||
if (image.isEmpty()) return null
|
||||
// Tray icons render small; resize to avoid an oversized image on some platforms.
|
||||
image = image.resize({ width: 18, height: 18 })
|
||||
// macOS renders template images correctly in both light/dark menubars.
|
||||
if (process.platform === 'darwin') image.setTemplateImage(false)
|
||||
// A template image must be pure black + alpha; macOS then auto-inverts it for
|
||||
// light/dark menu bars. Only mark it as such when we actually loaded the
|
||||
// dedicated template asset (a colored icon as template would render as a blob).
|
||||
if (isMac && templateIconPath) image.setTemplateImage(true)
|
||||
|
||||
tray = new Tray(image)
|
||||
tray.setToolTip(app.name)
|
||||
|
||||
Reference in New Issue
Block a user