{"size": 1242, "ext": "js", "max_stars_repo_path": "example/main.js", "max_stars_repo_name": "Zaitsev/electron-process-manager", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "example/main.js", "max_issues_repo_name": "Zaitsev/electron-process-manager", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/main.js", "max_forks_repo_name": "Zaitsev/electron-process-manager", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.6, "max_line_length": 79, "alphanum_fraction": 0.5853462158}
var { app, shell, BrowserWindow, Menu, ipcMain } = require('electron');
var join = require('path').join;

var processManager  = require('..');
const defaultMenu = require('electron-default-menu');

processManager.on('killed-process', pid => console.log('Killed process', pid));

app.once('window-all-closed',function() { app.quit(); });

app.once('ready', function() {
    var w = new BrowserWindow();
    w.once('closed', function() { w = null; });
    w.loadURL('file://' + join(__dirname, 'index.html'));

    const menu =
      defaultMenu(app, shell)
      .map(menu => {
        if(menu.label === 'Window') {
          menu.submenu.push({
            label: 'Open Process Manager',
            click: () => processManager.open({
              defaultSorting: {
                path: 'cpu.percentCPUUsage',
                how: 'descending'
            }})
          })
        }
        return menu;
      });

   Menu.setApplicationMenu(Menu.buildFromTemplate(menu));
});

if (process.env.TEST_PROCESS_MANAGER) {
  // emulate click on menu item
  ipcMain.on('open-process-manager', () => processManager.open());

  process.on('uncaughtException', function (error) {
    console.error(error, error.stack);
    process.exit(1);
  });

}
