MCPcopy Index your code
hub / github.com/ZToolsCenter/ZTools / createTray

Method createTray

src/main/managers/windowManager.ts:531–573  ·  view source on GitHub ↗

* 创建系统托盘

()

Source from the content-addressed store, hash-verified

529 * 创建系统托盘
530 */
531 public createTray(): void {
532 // 创建托盘图标
533 let icon: Electron.NativeImage
534
535 if (platform.isMacOS) {
536 // macOS 使用 Template 模式的图标(会自动适配明暗主题)
537 // 使用 dark 版本作为模板图标
538 icon = nativeImage.createFromPath(trayIcon)
539 // 设置为模板图标(适配明暗模式)
540 icon.setTemplateImage(true)
541 } else {
542 // Windows/Linux - 根据系统主题选择图标
543 // 暗色模式用 light(白色图标),亮色模式用 dark(黑色图标)
544 // const iconPath = nativeTheme.shouldUseDarkColors ? trayIconLight : trayIcon
545 icon = nativeImage.createFromPath(windowsIcon)
546 icon.setTemplateImage(false)
547 }
548
549 this.tray = new Tray(icon)
550
551 // 设置托盘提示文字
552 this.tray.setToolTip('ZTools')
553
554 // 创建右键菜单
555 this.createTrayMenu()
556
557 if (platform.isLinux && this.trayMenu) {
558 // Linux 下往往无法触发 click 事件,直接使用原生菜单
559 this.tray.setContextMenu(this.trayMenu)
560 } else {
561 // 左键点击:切换窗口显示
562 this.tray.on('click', () => {
563 this.toggleWindow()
564 })
565
566 // 右键点击:显示菜单
567 this.tray.on('right-click', () => {
568 if (this.tray && this.trayMenu) {
569 this.tray.popUpContextMenu(this.trayMenu)
570 }
571 })
572 }
573 }
574
575 /**
576 * 创建托盘菜单

Callers 1

setTrayIconVisibleMethod · 0.95

Calls 3

createTrayMenuMethod · 0.95
toggleWindowMethod · 0.95
onMethod · 0.80

Tested by

no test coverage detected