Skip to content

fix(tray): resolve IPC notification and icon display issues#1095

Merged
kuishou68 merged 2 commits intoiOfficeAI:mainfrom
cdxiaodong:feat/close-to-tray
Mar 4, 2026
Merged

fix(tray): resolve IPC notification and icon display issues#1095
kuishou68 merged 2 commits intoiOfficeAI:mainfrom
cdxiaodong:feat/close-to-tray

Conversation

@cdxiaodong
Copy link
Copy Markdown
Member

Summary

  • Fix tray toggle setting having no effect due to Vite SSR module instance separation causing bridge library IPC notifications to never reach the main process. Added direct ipcMain.handle in index.ts to bypass the bridge library, with bridge as fallback.
  • Fix tray icon appearing as blank square on macOS by switching from icon.png (Template image without proper black/transparent format) to app.png (colored app icon) resized to 16x16.
  • Renderer now uses ConfigStorage directly for reading/writing the close-to-tray setting, and notifies main process via direct IPC (window.electronAPI.setCloseToTray).

Closes #1072

Test plan

  • Enable "Close to tray" in Settings → System, verify tray icon appears immediately in macOS menu bar
  • Verify tray icon displays the colored app icon (not a blank square)
  • Close the window, verify it hides to tray instead of quitting
  • Click tray icon context menu "Show AionUi" to restore window
  • Disable "Close to tray", verify tray icon disappears
  • Restart app with setting enabled, verify tray icon appears on startup
  • Test on Windows/Linux if possible

@kuishou68
Copy link
Copy Markdown
Collaborator

@cdxiaodong Nice work on the close-to-tray feature! The dual-layer IPC approach and platform-specific icon handling look well thought out.

Before merging, please:

  1. Rebase onto latest main — the branch is currently behind.
  2. Complete the test plan — especially verify on macOS that the tray icon renders correctly (not a blank square), and test the full lifecycle: enable → close → tray icon → restore → disable.

Will merge once rebased and tested. Thanks!

@cdxiaodong cdxiaodong force-pushed the feat/close-to-tray branch from ed477d7 to f603f9a Compare March 3, 2026 01:23
@cdxiaodong
Copy link
Copy Markdown
Member Author

Rebased onto latest main — now 2 clean commits on top of 6b680ec (latest upstream HEAD). No conflicts.

Ready for review & merge.

@cdxiaodong
Copy link
Copy Markdown
Member Author

image

@kuishou68
Copy link
Copy Markdown
Collaborator

@cdxiaodong 功能方向没问题,close to tray 是常见需求。几个地方需要调整:

1. 去掉 direct IPC,只用 bridge

现在同时有 ipcMain.handle('tray-direct-set-close-to-tray') + preload.ts 暴露的 electronAPI.setCloseToTray,和 ipcBridge.systemSettings.setCloseToTray,两套做一样的事。项目有完整的 bridge 体系,统一用 bridge 就行,不需要加 direct IPC 通道。SystemModalContent 里也不用 if/else 两条路径了。

2. bridge provider 里做持久化

systemSettingsBridge.tssetCloseToTray provider 只调了 _changeListener,没有 ConfigStorage.set。持久化全靠 renderer 自己写,如果写入失败主进程状态就和存储不一致了。改成 provider 里统一做 ConfigStorage.set + 通知主进程。

3. macOS 不要隐藏 Dock 图标

最小化到托盘时 app.dock.hide() 会让 Dock 图标消失,用户找不到入口恢复窗口。大部分 macOS 应用(Slack、Discord 等)最小化到托盘时 Dock 图标还在。建议去掉 app.dock.hide(),或者至少做成单独的可选项。

4. 清理 console.log

6 处 console.log('[Tray] ...') 在生产环境太多了,保留关键的错误日志就行,其他去掉或改成 debug 级别。

5. 需要 rebase

当前和 main 有冲突,rebase 一下。

以上改完就可以合了。

Add system tray support with configurable close-to-tray behavior.
When enabled, closing the window minimizes to tray instead of quitting.

- Add Tray creation with context menu (Show/Quit)
- Intercept window close event to hide instead of quit
- Add IPC bridge for close-to-tray setting read/write
- Add toggle switch in System Settings page
- Add i18n translations for all 6 supported languages
- Remove direct IPC (ipcMain.handle), use bridge system only
- Add ConfigStorage.set to bridge provider for persistence
- Remove macOS dock.hide() to keep Dock icon visible
- Clean up console.log statements (keep only error logs)
@cdxiaodong cdxiaodong force-pushed the feat/close-to-tray branch from f603f9a to 9ec4804 Compare March 4, 2026 09:48
@kuishou68 kuishou68 merged commit 7083241 into iOfficeAI:main Mar 4, 2026
6 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: 希望能增加关闭到后台选项

2 participants