.Net Core 3.0
When subscribed to the tray events OnClick and OnDoubleClick, the two events trigger when double-clicking the tray icon. OnClick event should not trigger when double-clicking the tray icon.
I'm sorry, but that's a standard behavior of the native electron. A double-click on a tray icon should not be used normally either. See the following discussion: https://github.com/electron/electron/issues/8952
You could use at most a separate solution using reactive extensions. I see no reason to use a workaround here.
Maybe the double-click should not be used in MacOS, but on Windows, all the applications in the system tray work with double-click. So, in Windows, this is a very strange behaviour because it's normal to react to single-click and double-click separately.
By the way, here my simple workaround if other faces the same problem as me:
Electron.Tray.OnClick += async (args, rectangle) => await SingleClickAsync();
Electron.Tray.OnDoubleClick += async (args, rectangle) => await DoubleClickAsync();
public async Task SingleClickAsync()
{
await Task.Delay(200);
if (_isDoubleClickEvent)
{
return;
}
// Put your code here
}
private async Task DoubleClickAsync()
{
_isDoubleClickEvent = true;
await Task.Delay(215);
_isDoubleClickEvent = false;
// Put your code here
}
It works by triggering the single-click event, async wait some time while the double-click gets triggered, flag as double-click event and when the single-click event resume from the wait, it detects the double-click and returns.
Most helpful comment
Maybe the double-click should not be used in MacOS, but on Windows, all the applications in the system tray work with double-click. So, in Windows, this is a very strange behaviour because it's normal to react to single-click and double-click separately.
By the way, here my simple workaround if other faces the same problem as me:
It works by triggering the single-click event, async wait some time while the double-click gets triggered, flag as double-click event and when the single-click event resume from the wait, it detects the double-click and returns.