<commit_before>const electron = require('electron')
const remote = electron.remote
const ipc = electron.ipcRenderer
const BrowserWindow = electron.remote.BrowserWindow
const serialPort = require('serialport')
const biu = require('biu.js')

var btnClose = document.getElementById('btn-close')
var btnConnect = document.getElementById('btn-connect')
var btnRefresh = document.getElementById('btn-refresh')
var table = document.getElementById('table-content')

btnClose.addEventListener('click', () => {BrowserWindow.getFocusedWindow().close()})
btnConnect.addEventListener('click', connect)
btnRefresh.addEventListener('click', loadDevices)
document.addEventListener("keydown", globalKeyHandler)

// Check which row was clicked
table.onmousedown = function (e) {
  var el = e.target;
  while (el != document.body && el.tagName.toLowerCase() != "tr") {
    el = el.parentNode;
  }
  changeSelectedDevice(parseInt([].indexOf.call(el.parentNode.children, el)));
}

// Handle all key shortcuts
function globalKeyHandler(e) {
  if((e.key === "r" && (e.ctrlKey || e.metaKey) ) || e.keyCode === 116) {
    // Reload devices
    loadDevices()
  }
  else if(e.keyCode === 123) {
    // Open Dev Tools
    remote.getCurrentWindow().toggleDevTools()
  }
}


function spawnDeviceUI(name, manufacturer) {
  var row = table.insertRow(deviceList.length - 1)
  var cell1 = row.insertCell(0)
  var cell2 = row.insertCell(1)
  cell1.innerHTML = name
  cell2.innerHTML = manufacturer
}

function loadDevices() {
  serialPort.list(function (err, ports) {

    // clear the UI
    table.innerHTML = ""
    deviceSelected = null
    deviceList = []

    // create the UI
    ports.forEach(function(port) {
      deviceList.push(port.comName)
      spawnDeviceUI(port.comName, port.manufacturer)
    })
  })
}

var deviceSelected = null
var deviceList = []
function changeSelectedDevice(input) {
  // check if there is even a device selected
  if (deviceSelected != null) {
    // remove the active class
    table.children[deviceSelected].classList.remove('active')
  }


  if (deviceSelected === input) {
    // if clicked on the selected device it should now be unselected
    deviceSelected = null
  }
  else {
    // add the active class to the nuw selected
    deviceSelected = input
    table.children[deviceSelected].classList.add('active')
  }
}<commit_msg>Add error if no devices found<commit_after>const electron = require('electron')
const remote = electron.remote
const ipc = electron.ipcRenderer
const BrowserWindow = electron.remote.BrowserWindow
const serialPort = require('serialport')
const biu = require('biu.js')

var btnClose = document.getElementById('btn-close')
var btnConnect = document.getElementById('btn-connect')
var btnRefresh = document.getElementById('btn-refresh')
var table = document.getElementById('table-content')

btnClose.addEventListener('click', () => {BrowserWindow.getFocusedWindow().close()})
btnConnect.addEventListener('click', connect)
btnRefresh.addEventListener('click', loadDevices)
document.addEventListener("keydown", globalKeyHandler)

// Check which row was clicked
table.onmousedown = function (e) {
  var el = e.target;
  while (el != document.body && el.tagName.toLowerCase() != "tr") {
    el = el.parentNode;
  }
  changeSelectedDevice(parseInt([].indexOf.call(el.parentNode.children, el)));
}

// Handle all key shortcuts
function globalKeyHandler(e) {
  if((e.key === "r" && (e.ctrlKey || e.metaKey) ) || e.keyCode === 116) {
    // Reload devices
    loadDevices()
  }
  else if(e.keyCode === 123) {
    // Open Dev Tools
    remote.getCurrentWindow().toggleDevTools()
  }
}


function spawnDeviceUI(name, manufacturer) {
  var row = table.insertRow(deviceList.length - 1)
  var cell1 = row.insertCell(0)
  var cell2 = row.insertCell(1)
  cell1.innerHTML = name
  cell2.innerHTML = manufacturer
}

function loadDevices() {
  serialPort.list(function (err, ports) {

    // clear the UI
    table.innerHTML = ""
    deviceSelected = null
    deviceList = []

    // create the UI
    ports.forEach(function(port) {
      deviceList.push(port.comName)
      spawnDeviceUI(port.comName, port.manufacturer)
    })

    // Error message if no ports found
    if (ports.length === 0) {
      spawnDeviceUI("<strong><i>No devices found!</i></strong>", null)
    }

  })
}

var deviceSelected = null
var deviceList = []
function changeSelectedDevice(input) {
  // check if there is even a device selected
  if (deviceSelected != null) {
    // remove the active class
    table.children[deviceSelected].classList.remove('active')
  }


  if (deviceSelected === input) {
    // if clicked on the selected device it should now be unselected
    deviceSelected = null
  }
  else {
    // add the active class to the nuw selected
    deviceSelected = input
    table.children[deviceSelected].classList.add('active')
  }
}
{'fraction_non_alphanumeric': 0.12959141560049525, 'fraction_numerical': 0.005571605447791993, 'mean_word_length': 3.9560327198364007, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '3351704', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1421, 'n_words': 352}