<commit_before>import * as ChildProcess from 'child_process'
import * as Path from 'path'
import * as Fs from 'fs-extra'
import * as Os from 'os'

/**
 * Handle Squirrel.Windows app lifecycle events.
 *
 * Returns a promise which will resolve when the work is done.
 */
export function handleSquirrelEvent(eventName: string): Promise<void> | null {
  switch (eventName) {
    case '--squirrel-install':
      return createShortcut()

    case '--squirrel-updated':
      return handleUpdated()

    case '--squirrel-uninstall':
      return handleUninstall()

    case '--squirrel-obsolete':
      return Promise.resolve()
  }

  return null
}

async function handleUpdated(): Promise<void> {
  try {
    updateShortcut().then(() => {}).catch(() => {})
  } catch (e) {

  }

  const binPath = await writeCLITrampoline()

  const paths = await getPathSegments()
  if (paths.indexOf(binPath) < 0) {
    await setPathSegments([ ...paths, binPath ])
  }
}

/**
 * Get the path for the `bin` directory which exists in our `AppData` but
 * outside path which includes the installed app version.
 */
function getBinPath(): string {
  const appFolder = Path.resolve(process.execPath, '..')
  const rootAppDir = Path.resolve(appFolder, '..')
  return Path.join(rootAppDir, 'bin')
}

/**
 * Here's the problem: our app's path contains its version number. So each time
 * we update, the path to our app changes. So it's Real Hard to add our path
 * directly to `Path`. We'd have to detect and remove stale entries, etc.
 *
 * So instead, we write a trampoline out to a fixed path, still inside our
 * `AppData` directory but outside the version-specific path. That trampoline
 * just launches the current version's CLI tool. Then, whenever we update, we
 * rewrite the trampoline to point to the new, version-specific path. Bingo
 * bango Bob's your uncle.<commit_msg>Remove that testing path<commit_after>import * as ChildProcess from 'child_process'
import * as Path from 'path'
import * as Fs from 'fs-extra'
import * as Os from 'os'

/**
 * Handle Squirrel.Windows app lifecycle events.
 *
 * Returns a promise which will resolve when the work is done.
 */
export function handleSquirrelEvent(eventName: string): Promise<void> | null {
  switch (eventName) {
    case '--squirrel-install':
      return createShortcut()

    case '--squirrel-updated':
      return handleUpdated()

    case '--squirrel-uninstall':
      return handleUninstall()

    case '--squirrel-obsolete':
      return Promise.resolve()
  }

  return null
}

async function handleUpdated(): Promise<void> {
  await updateShortcut()

  const binPath = await writeCLITrampoline()
  const paths = await getPathSegments()
  if (paths.indexOf(binPath) < 0) {
    await setPathSegments([ ...paths, binPath ])
  }
}

/**
 * Get the path for the `bin` directory which exists in our `AppData` but
 * outside path which includes the installed app version.
 */
function getBinPath(): string {
  const appFolder = Path.resolve(process.execPath, '..')
  const rootAppDir = Path.resolve(appFolder, '..')
  return Path.join(rootAppDir, 'bin')
}

/**
 * Here's the problem: our app's path contains its version number. So each time
 * we update, the path to our app changes. So it's Real Hard to add our path
 * directly to `Path`. We'd have to detect and remove stale entries, etc.
 *
 * So instead, we write a trampoline out to a fixed path, still inside our
 * `AppData` directory but outside the version-specific path. That trampoline
 * just launches the current version's CLI tool. Then, whenever we update, we
 * rewrite the trampoline to point to the new, version-specific path. Bingo
 * bango Bob's your uncle.
{'fraction_non_alphanumeric': 0.1079607415485278, 'fraction_numerical': 0.0005452562704471102, 'mean_word_length': 3.6209068010075565, 'pattern_counts': {'":': 0, '<': 9, '<?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': '3092467', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1057, 'n_words': 419}