'use strict';

const { Tray, Menu, ipcMain } = require('electron');

class IpcManager {

    constructor(win, icon) {

        this.tray = null;
        this.trayIcon = icon;
        this.win = win;
    }

    bindEvents() {

        ipcMain.on('showTray', () => {

            this.show();
        });

        ipcMain.on('hideTray', () => {

            this.hide();
        });
    }

    show() {

        this.tray = new Tray(this.trayIcon);

        const contextMenu = Menu.buildFromTemplate([
            {
                label: 'Show',
                click: () => {
                    this.win.show();
                    this.hide();
                }
            },
            {
                type: 'separator'
            },
            {
                label: 'Quit',
                click: () => {
                    this.win.destroy();
                }
            }
        ]);

        this.tray.setToolTip('Museeks');
        this.tray.setContextMenu(contextMenu);
    }

    hide() {

        this.tray.destroy();
    }
}

module.exports = IpcManager;

@@ -8,16 +8,43 @@
 rict';%0A%0A
+const os = require('os');%0A%0A
 const %7B 
@@ -965,16 +965,398 @@
 eeks');%0A
+        this.tray.setTitle('Museeks');%0A%0A        if(os.platform() === 'win32') %7B%0A            this.tray.on('click', () =%3E %7B%0A                this.win.show();%0A                this.hide();%0A            %7D);%0A        %7D%0A        else %7B // Darwin or Linux%0A            this.tray.on('double-click', () =%3E %7B%0A                this.win.show();%0A                this.hide();%0A            %7D);%0A        %7D%0A%0A
         

Improve tray click actions depending of the OS