<commit_before><script>
// Load native UI library
var gui = require('nw.gui');

var states = [{
    label: 'Tests have been written and are failing',
    icon: 'assets/red.png'
  },{
    label: 'Implementation was made, tests are passing',
    icon: 'assets/green.png'
  },{
    label: 'Refactoring is done and code is clean',
    icon: 'assets/blue.png'
}];

var counter = 1;

// Create a tray icon
var tray = new gui.Tray({
  icon: states[0].icon,
  iconsAreTemplates: false,
  // click: function () {
  //   tray.icon = states[counter].icon;
  //   counter = counter >= states.length - 1 ? 0 : counter + 1;
  // }
});

// Give it a menu
var menu = new gui.Menu();

menu.append(new gui.MenuItem({
  label: states[0].label,
  click: function() {
    tray.icon = states[counter].icon;
    menu.items[0].label = states[counter].label;
    counter = counter >= 2 ? 0 : counter + 1;
  },
}));

menu.append(new gui.MenuItem({ type: 'separator' }));

menu.append(new gui.MenuItem({
  label: 'Quit',
  click: function() {
    tray.remove();
    tray = null;
    gui.App.quit();
  }
}));

tray.menu = menu;
</script><commit_msg>Fixes to and refactoring of main script<commit_after><script>

// Load native UI library
var gui = require('nw.gui');
var states = require('./states');

require('./server');

// gui.Window.get().showDevTools();

var currentIndex = 0;

// Create a tray icon
var tray = new gui.Tray({
  icon: states[0].icon,
  iconsAreTemplates: false,
  // click: function () {
  //   tray.icon = states[currentIndex].icon;
  //   currentIndex = currentIndex >= states.length - 1 ? 0 : currentIndex + 1;
  // }
});

// Give it a menu
var menu = new gui.Menu();
menu.append(new gui.MenuItem({
  label: states[0].label,
  click: function() {
    global.setState();
  },
}));
menu.append(new gui.MenuItem({ type: 'separator' }));
menu.append(new gui.MenuItem({
  label: 'Quit',
  click: function() {
    tray.remove();
    tray = null;
    gui.App.quit();
  }
}));
tray.menu = menu;

function getIndex (state) {
  var index;
  states.forEach(function (el, i) {
    if (el.phase === state) index = i;
  });
  return index;
}

global.setState = function(state){
  if (typeof state !== 'undefined') {
    currentIndex = getIndex(state);
  } else {
    currentIndex = currentIndex >= 2 ? 0 : currentIndex + 1;
  }
  tray.icon = states[currentIndex].icon;
  menu.items[0].label = states[currentIndex].label;
};

global.getState = function () {
  return states[currentIndex];
};

</script>
{'fraction_non_alphanumeric': 0.17552334943639292, 'fraction_numerical': 0.008051529790660225, 'mean_word_length': 3.190556492411467, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3037413', 'n_tokens_mistral': 871, 'n_tokens_neox': 858, 'n_words': 220}