Electron.net: Tray.OnDoubleClick and Tray.OnClick produced at the same time

Created on 27 Nov 2019  路  2Comments  路  Source: ElectronNET/Electron.NET

  • Version: 5.30.1


.Net Core 3.0

  • Target: Windows 10


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.

bug

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:

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.

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ThuCommix picture ThuCommix  路  3Comments

zlspjp picture zlspjp  路  5Comments

AykutToprak picture AykutToprak  路  4Comments

iqmeta picture iqmeta  路  3Comments

cdespinosaagmx picture cdespinosaagmx  路  3Comments