<commit_before>'use strict'

const {app, Tray} = require('electron')
const path = require('path')

const {buildAppMenu} = require('./menu')
const window = require('./window')

const {Server} = require('./server')

const logPath = require('./logDirectory')
const rotate = require('rotating-file-stream')

function getIcon () {
  return path.join(__dirname, 'images', 'icon.png')
}

let server = null
let tray = null

const isSecondInstance = app.makeSingleInstance((commandLine, workingDirectory) => {
  // Someone tried to run a second instance, we should focus our window.
  if (window.mainWindow) {
    if (window.mainWindow.isMinimized()) {
      window.mainWindow.restore()
      window.mainWindow.show()
    }
  } else {
    window.buildMainWindow()
  }
})

if (isSecondInstance) {
  app.quit()
} else {
  app.on('ready', () => {
    var stream = rotate('launcher', {
      size: '10M',
      interval: '1d',
      path: logPath
    })
    process.stdout.pipe(stream)
    process.stderr.pipe(stream)
    server = new Server(path.join(process.cwd(), 'modules.yml'))
    exports.server = server
    server.start()
      .then(() => buildAppMenu(server.getModules()))
      .then(appMenu => {
        tray = new Tray(getIcon())
        const contextMenu = appMenu
        tray.setToolTip('FIRST LEGO League Scoring')
        tray.setContextMenu(contextMenu)
      })
      .then(() => window.buildMainWindow())
      .catch(err => {
        console.error(err)
      })

  })

  app.on('window-all-closed', event => { // this prevents the app from trying to quit when you close the main window
    event.preventDefault()
  })

  app.on('before-quit', () => {
    window.mainWindow.destroy() // prevents it from showing any closing dialog
    server.close()
  })
}<commit_msg>fixed app crushing when quiting with no window open<commit_after>'use strict'

const {app, Tray} = require('electron')
const path = require('path')

const {buildAppMenu} = require('./menu')
const window = require('./window')

const {Server} = require('./server')

const logPath = require('./logDirectory')
const rotate = require('rotating-file-stream')

function getIcon () {
  return path.join(__dirname, 'images', 'icon.png')
}

let server = null
let tray = null

const isSecondInstance = app.makeSingleInstance((commandLine, workingDirectory) => {
  // Someone tried to run a second instance, we should focus our window.
  if (window.mainWindow) {
    if (window.mainWindow.isMinimized()) {
      window.mainWindow.restore()
      window.mainWindow.show()
    }
  } else {
    window.buildMainWindow()
  }
})

if (isSecondInstance) {
  app.quit()
} else {
  app.on('ready', () => {
    var stream = rotate('launcher', {
      size: '10M',
      interval: '1d',
      path: logPath
    })
    process.stdout.pipe(stream)
    process.stderr.pipe(stream)
    server = new Server(path.join(process.cwd(), 'modules.yml'))
    exports.server = server
    server.start()
      .then(() => buildAppMenu(server.getModules()))
      .then(appMenu => {
        tray = new Tray(getIcon())
        const contextMenu = appMenu
        tray.setToolTip('FIRST LEGO League Scoring')
        tray.setContextMenu(contextMenu)
      })
      .then(() => window.buildMainWindow())
      .catch(err => {
        console.error(err)
      })

  })

  app.on('window-all-closed', event => { // this prevents the app from trying to quit when you close the main window
    event.preventDefault()
  })

  app.on('before-quit', () => {
    if (window.mainWindow) {
      window.mainWindow.destroy() // prevents it from showing any closing dialog
    }
    server.close()
  })
}
{'fraction_non_alphanumeric': 0.15026192445547285, 'fraction_numerical': 0.0016542597187758478, 'mean_word_length': 3.0855855855855854, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '166237', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1099, 'n_words': 266}