async Task CreateTray(string __dirname) { if (IsWindows) { tray = await Tray.Create($"{__dirname}/assets/icons/appicon.ico"); } else { tray = await Tray.Create($"{__dirname}/assets/icons/[email protected]"); } // Sets the hover text for this tray icon. await tray.SetToolTip("MinimizeToTray Sample Program"); // Sets the title displayed aside of the tray icon in the status bar. //await tray.SetTitle("MinimizeToTray"); // Create a context menu to be displayed on the Tray var menuItemOptions = new MenuItemOptions[] { new MenuItemOptions() { Label = "Show App", Click = new ScriptObjectCallback <MenuItem, BrowserWindow, Event> ( async(ar) => { //await console.Log("Show App"); if (mainWindow != null) { if (await mainWindow.IsMinimized()) { await mainWindow.Restore(); } if (!await mainWindow.IsVisible()) { await mainWindow.Show(); } await mainWindow.Focus(); } } ) }, new MenuItemOptions() { Label = "Quit App", Click = new ScriptObjectCallback <MenuItem, BrowserWindow, Event> ( async(ar) => { //await console.Log("Quit App"); // Notify the close event that we will be quitting the app IsShouldQuit = true; mainWindow = null; await app.Quit(); } ) }, }; var contextMenu = await Menu.BuildFromTemplate(menuItemOptions); // Set our tray context menu await tray.SetContextMenu(contextMenu); // Allow the user to click on the tray icon to show the context menu. await tray.On("click", new ScriptObjectCallback ( async(sr) => { if (mainWindow != null) { await tray.PopUpContextMenu(); } }) ); }