App icon keep duplicates when i close app and open it


#1

tray

    app,
    BrowserWindow,
    Tray,
    Menu
} = require('electron');

let win;
var path = require('path')
var url = require('url')
var iconpath = path.join(__dirname, './work_path/logo.png')

function createWindow() {
    win = new BrowserWindow({
        resizable: false,
        center: true,
        icon: iconpath
    })
    win.setMenu(null);
    win.loadURL(url.format({
        pathname: path.join(__dirname, '/Work_path/index.html'),
    }))

    var appIcon = new Tray(iconpath)
    var contextMenu = Menu.buildFromTemplate([{
            label: 'Show App',
            click: function () {
                win.show()
            }
        },
        {
            label: 'Quit',
            click: function () {
                app.isQuiting = true
                app.quit()
            }
        }
    ])

    appIcon.setContextMenu(contextMenu)
    appIcon.addListener("double-click", function () {
        win.show();
    })
    win.on('close', function (event) {
        win = null
    })

    win.on('minimize', function (event) {
        event.preventDefault()
        win.hide()
    })

    win.on('show', function () {
        appIcon.setHighlightMode('always')
    })

}

app.on('ready', createWindow)

this my code to handle the app tray everything on it work fine just the app icons stay there when I close the app and they stack there until I open again and give it some seconds and disappear any idea of what I'm doing wrong ??