(function () {
  let transfer = require('transfer'),
    EventEmitter = require('myevents');

  transfer['window_load.tray'] = (nwWindow) => {

    var tray = new nw.Tray({
      "title": '政务云盘',
      "tooltip": "政务云盘",
      "icon": '/web_content/assets/imgs/logo.png'
    });

    tray.on('click', function () {
      nwWindow.focus();
      nwWindow.show();
      nwWindow.restore();
    })

    var menu = new nw.Menu();

    menu.append(new nw.MenuItem({
      label: "显示云盘",
      click: function () {
        nwWindow.show();
      }
    }));
    menu.append(new nw.MenuItem({
      label: '退出',
      click: function () {
        // tray.remove();
        // tray = null;
        nw.process.exit();
      }
    }));
    // menu.append(new nw.MenuItem({
    //   label: "切换账号",
    //   click: function () { 
    //       tray.remove();
    //       tray = null;
    //      EventEmitter.emit('logout');
    //   }
    // }));
    tray.menu = menu;


    EventEmitter.on('reopen', () => {
      nwWindow.focus();
      nwWindow.show();
      nwWindow.restore();
    });

  }
}());