<commit_before>import { app, Menu, MenuItem, ipcMain, BrowserWindow, autoUpdater, dialog } from 'electron'

import { AppWindow } from './app-window'
import { buildDefaultMenu, MenuEvent, findMenuItemByID } from './menu'
import { parseURL, URLActionType } from '../lib/parse-url'
import { handleSquirrelEvent } from './squirrel-updater'
import { SharedProcess } from '../shared-process/shared-process'
import { fatalError } from '../lib/fatal-error'

import { IMenuItemState } from '../lib/menu-update'
import { ILogEntry, logError, log } from '../lib/logging/main'
import { formatError } from '../lib/logging/format-error'
import { reportError } from './exception-reporting'
import { enableSourceMaps } from '../lib/enable-source-maps'

enableSourceMaps()

let mainWindow: AppWindow | null = null
let sharedProcess: SharedProcess | null = null

const launchTime = Date.now()

let preventQuit = false
let readyTime: number | null = null

/**
 * The URL action with which the app was launched. On macOS, we could receive an
 * `open-url` command before the app ready event, so we stash it away and handle
 * it when we're ready.
 */
let launchURLAction: URLActionType | null = null

function uncaughtException(error: Error) {
  preventQuit = true

  logError(formatError(error))

  if (mainWindow) {
    mainWindow.destroy()
    mainWindow = null
  }

  if (sharedProcess) {
    sharedProcess.destroy()
    mainWindow = null
  }

  dialog.showMessageBox({
    type: 'error',
    title: __DARWIN__ ? `Unrecoverable Error` : 'Unrecoverable error',
    message:
      `GitHub Desktop has encountered an unrecoverable error and will need to restart.\n\n` +
      `This has been reported to the team, but if you encounter this repeatedly please report ` +
      `this issue to the GitHub Desktop issue tracker.\n\n${error.stack || error.message}`,
  }, (response) => {
    if (!__DEV__) {
      app.relaunch()
    }
    app.quit()
  })
}

process.on('uncaughtException', (error: Error) => {
  uncaughtException(error)
})

if (__WIN32__ && process.argv.length > 1) {
  if (handleSquirrelEvent(process.argv[1])) {
    app.quit()
  }
}

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

  // look at the second argument received, it should have the OAuth
  // callback contents and code for us to complete the signin flow<commit_msg>Report errors from the main process<commit_after>import { app, Menu, MenuItem, ipcMain, BrowserWindow, autoUpdater, dialog } from 'electron'

import { AppWindow } from './app-window'
import { buildDefaultMenu, MenuEvent, findMenuItemByID } from './menu'
import { parseURL, URLActionType } from '../lib/parse-url'
import { handleSquirrelEvent } from './squirrel-updater'
import { SharedProcess } from '../shared-process/shared-process'
import { fatalError } from '../lib/fatal-error'

import { IMenuItemState } from '../lib/menu-update'
import { ILogEntry, logError, log } from '../lib/logging/main'
import { formatError } from '../lib/logging/format-error'
import { reportError } from './exception-reporting'
import { enableSourceMaps } from '../lib/enable-source-maps'

enableSourceMaps()

let mainWindow: AppWindow | null = null
let sharedProcess: SharedProcess | null = null

const launchTime = Date.now()

let preventQuit = false
let readyTime: number | null = null

/**
 * The URL action with which the app was launched. On macOS, we could receive an
 * `open-url` command before the app ready event, so we stash it away and handle
 * it when we're ready.
 */
let launchURLAction: URLActionType | null = null

function uncaughtException(error: Error) {
  preventQuit = true

  logError(formatError(error))

  if (mainWindow) {
    mainWindow.destroy()
    mainWindow = null
  }

  if (sharedProcess) {
    sharedProcess.destroy()
    mainWindow = null
  }

  dialog.showMessageBox({
    type: 'error',
    title: __DARWIN__ ? `Unrecoverable Error` : 'Unrecoverable error',
    message:
      `GitHub Desktop has encountered an unrecoverable error and will need to restart.\n\n` +
      `This has been reported to the team, but if you encounter this repeatedly please report ` +
      `this issue to the GitHub Desktop issue tracker.\n\n${error.stack || error.message}`,
  }, (response) => {
    if (!__DEV__) {
      app.relaunch()
    }
    app.quit()
  })
}

process.on('uncaughtException', (error: Error) => {
  reportError(error)
  uncaughtException(error)
})

if (__WIN32__ && process.argv.length > 1) {
  if (handleSquirrelEvent(process.argv[1])) {
    app.quit()
  }
}

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

  // look at the second argument received, it should have the OAuth
  // callback contents and code for us to complete the signin flow
{'fraction_non_alphanumeric': 0.11778425655976676, 'fraction_numerical': 0.001554907677356657, 'mean_word_length': 3.699543378995434, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3599139', 'n_tokens_mistral': 1559, 'n_tokens_neox': 1530, 'n_words': 487}