[PR #973] [MERGED] Add dynamic tray menu update functionality #1395

Closed
opened 2026-01-29 17:00:20 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ElectronNET/Electron.NET/pull/973
Author: @davidroth
Created: 12/10/2025
Status: Merged
Merged: 12/11/2025
Merged by: @FlorianRappl

Base: developHead: set-menu-items


📝 Commits (1)

  • 218b998 Add dynamic tray menu update functionality

📊 Changes

4 files changed (+52 additions, -13 deletions)

View changed files

📝 src/ElectronNET.API/API/Tray.cs (+23 -1)
📝 src/ElectronNET.Host/api/tray.js (+13 -5)
📝 src/ElectronNET.Host/api/tray.js.map (+1 -1)
📝 src/ElectronNET.Host/api/tray.ts (+15 -6)

📄 Description

Introduced a SetMenuItems method in Tray.cs to enable dynamic updates to the tray's context menu. This method clears the existing menu items, adds new ones, and registers the necessary click handlers.

Previously, updating menu item properties (such as changing the enabled state) required deleting and recreating the entire tray. Although this was functional, it caused noticeable flickering of the tray icon because the icon was briefly removed and then re-added.

With this change, the tray icon remains constant, and only the menu items themselves are replaced.

With the existing api

await Electron.Tray.Show(ImagePath("Assets/electron.ico"), menuItems)

// Disabling an existing menu item in the tray by dropping and recreating the entire tray:
menuItems[0].Enabled = false;

await Electron.Tray.Destroy()
await Electron.Tray.Show(ImagePath("Assets/electron.ico"), menuItems)

With the new api

await Electron.Tray.Show(ImagePath("Assets/electron.ico"), menuItems)

// Disabling an existing menu item in the tray by  replacing the menu items  only.
menuItems[0].Enabled = false;
await Electron.Tray.SetMenuItems(items);

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ElectronNET/Electron.NET/pull/973 **Author:** [@davidroth](https://github.com/davidroth) **Created:** 12/10/2025 **Status:** ✅ Merged **Merged:** 12/11/2025 **Merged by:** [@FlorianRappl](https://github.com/FlorianRappl) **Base:** `develop` ← **Head:** `set-menu-items` --- ### 📝 Commits (1) - [`218b998`](https://github.com/ElectronNET/Electron.NET/commit/218b99808be1fecccd40dfc577a379e79696a93b) Add dynamic tray menu update functionality ### 📊 Changes **4 files changed** (+52 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `src/ElectronNET.API/API/Tray.cs` (+23 -1) 📝 `src/ElectronNET.Host/api/tray.js` (+13 -5) 📝 `src/ElectronNET.Host/api/tray.js.map` (+1 -1) 📝 `src/ElectronNET.Host/api/tray.ts` (+15 -6) </details> ### 📄 Description Introduced a SetMenuItems method in Tray.cs to enable dynamic updates to the tray's context menu. This method clears the existing menu items, adds new ones, and registers the necessary click handlers. Previously, updating menu item properties (such as changing the enabled state) required deleting and recreating the entire tray. Although this was functional, it caused noticeable flickering of the tray icon because the icon was briefly removed and then re-added. With this change, the tray icon remains constant, and only the menu items themselves are replaced. ### With the existing api ```csharp await Electron.Tray.Show(ImagePath("Assets/electron.ico"), menuItems) // Disabling an existing menu item in the tray by dropping and recreating the entire tray: menuItems[0].Enabled = false; await Electron.Tray.Destroy() await Electron.Tray.Show(ImagePath("Assets/electron.ico"), menuItems) ``` ### With the new api ```csharp await Electron.Tray.Show(ImagePath("Assets/electron.ico"), menuItems) // Disabling an existing menu item in the tray by replacing the menu items only. menuItems[0].Enabled = false; await Electron.Tray.SetMenuItems(items); ```` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 17:00:20 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#1395