const {Menu, Tray } = require('electron');
const path = require('path');
var tray = null;//系统托盘
exports.tray = (data,funEv1,funEv2,mainWindow) => {
    try {
		tray = new Tray(data["图片地址"])
		let MenuData = [];
		for (let index = 0; index < data["菜单数据"].length; index++) {
			MenuData[MenuData.length] = {
				"label": data["菜单数据"][index],
				click: () => {
                    if(funEv1!=""){
						mainWindow.webContents.executeJavaScript(funEv1+"('" + data["菜单数据"][index] + "')")
                    }
				}
			}
		}
		const contextMenu = Menu.buildFromTemplate(MenuData)
		tray.setToolTip(data["托盘提示"])
		tray.setContextMenu(contextMenu)
		tray.on("click", (event) => {
            if(funEv2!=undefined){
				mainWindow.webContents.executeJavaScript(funEv2+"()")
            }
		})
	} catch (err) {

	}
}
exports.destroyTray = () => {
    if (tray != null) {
		tray.destroy()
	}
}
