<commit_before>/* eslint global-require: 1 */

/**
 * This module executes inside of electron's main process. You can start
 * electron renderer process from here and communicate with the other processes
 * through IPC.
 *
 * When running `npm run build` or `npm run build-main`, this file is compiled to
 * `./app/main.prod.js` using webpack. This gives us some performance wins.
 *
 */

import { app, BrowserWindow, ipcMain, session } from 'electron';
import child_process from 'child_process';
import path from 'path';
import url from 'url';
import windowStateKeeper from 'electron-window-state';

import MenuBuilder from './menu';
import packageInfo from '../package';


let mainWindow = null;
let pluginName;
const pluginDir = 'plugins';
let spawnOptions;
let webrecorderProcess;

const projectDir = path.join(__dirname, '../');
const stdio = ['ignore', 'pipe', 'ignore'];
const wrConfig = {};


switch (process.platform) {
  case 'win32':
    pluginName = 'pepflashplayer.dll';
    spawnOptions = { detached: true, stdio };
    break;
  case 'darwin':
    pluginName = 'PepperFlashPlayer.plugin';
    spawnOptions = { detached: true, stdio };
    break;
  case 'linux':
    pluginName = 'libpepflashplayer.so';
    spawnOptions = { detached: true, stdio };
    break;
  default:
    console.log('platform unsupported');
    break;
}

app.commandLine.appendSwitch('ignore-certificate-errors');
app.commandLine.appendSwitch(
  'ppapi-flash-path',
  path.join(projectDir, pluginDir, pluginName)
);

const registerOpenWarc = function () {
  const webrecorder = path.join(projectDir, 'python-binaries', 'webrecorder');

  // get versions for stack
  child_process.execFile(webrecorder, ['--version'], (err, stdout, stderr) => {
    const electronVersion = `electron ${process.versions.electron}<BR>
                             chrome ${process.versions.chrome}`;
    Object.assign(wrConfig, {
      version: `webrecorder player ${packageInfo.version}<BR>
                ${stdout.replace('\n', '<BR>')}<BR>${electronVersion}`
    });
  });

  ipcMain.on('open-warc', (event, argument) => {
    const warc = argument;
    console.log(`warc file: ${warc}`);

    // notify renderer that we are initializing webrecorder binary
    mainWindow.webContents.send('initializing');

    // if a previous webrecorder player is running, kill it
    if (webrecorderProcess) {
      if (process.platform === 'win32') {
        child_process.execSync(
          `taskkill /F /PID ${webrecorderProcess.pid} /T`
        );
      } else {
        webrecorderProcess.kill('SIGINT');
      }
    }

    webrecorderProcess = child_process.spawn(
        webrecorder,
        ['--no-browser', '--loglevel', 'error', '--port', 0, warc],
        spawnOptions
      );

    let port;

    const findPort = function (buff) {
      if (!buff) {
        return;
      }

      buff = buff.toString();<commit_msg>app: add --cache-dir _warc_cache to enable cacheing appveyor: use separate 32-bit and 64-bit flash plugin files<commit_after>/* eslint global-require: 1 */

/**
 * This module executes inside of electron's main process. You can start
 * electron renderer process from here and communicate with the other processes
 * through IPC.
 *
 * When running `npm run build` or `npm run build-main`, this file is compiled to
 * `./app/main.prod.js` using webpack. This gives us some performance wins.
 *
 */

import { app, BrowserWindow, ipcMain, session } from 'electron';
import child_process from 'child_process';
import path from 'path';
import url from 'url';
import windowStateKeeper from 'electron-window-state';

import MenuBuilder from './menu';
import packageInfo from '../package';


let mainWindow = null;
let pluginName;
const pluginDir = 'plugins';
let spawnOptions;
let webrecorderProcess;

const projectDir = path.join(__dirname, '../');
const stdio = ['ignore', 'pipe', 'ignore'];
const wrConfig = {};


switch (process.platform) {
  case 'win32':
    pluginName = 'pepflashplayer.dll';
    spawnOptions = { detached: true, stdio };
    break;
  case 'darwin':
    pluginName = 'PepperFlashPlayer.plugin';
    spawnOptions = { detached: true, stdio };
    break;
  case 'linux':
    pluginName = 'libpepflashplayer.so';
    spawnOptions = { detached: true, stdio };
    break;
  default:
    console.log('platform unsupported');
    break;
}

app.commandLine.appendSwitch('ignore-certificate-errors');
app.commandLine.appendSwitch(
  'ppapi-flash-path',
  path.join(projectDir, pluginDir, pluginName)
);

const registerOpenWarc = function () {
  const webrecorder = path.join(projectDir, 'python-binaries', 'webrecorder');

  // get versions for stack
  child_process.execFile(webrecorder, ['--version'], (err, stdout, stderr) => {
    const electronVersion = `electron ${process.versions.electron}<BR>
                             chrome ${process.versions.chrome}`;
    Object.assign(wrConfig, {
      version: `webrecorder player ${packageInfo.version}<BR>
                ${stdout.replace('\n', '<BR>')}<BR>${electronVersion}`
    });
  });

  ipcMain.on('open-warc', (event, argument) => {
    const warc = argument;
    console.log(`warc file: ${warc}`);

    // notify renderer that we are initializing webrecorder binary
    mainWindow.webContents.send('initializing');

    // if a previous webrecorder player is running, kill it
    if (webrecorderProcess) {
      if (process.platform === 'win32') {
        child_process.execSync(
          `taskkill /F /PID ${webrecorderProcess.pid} /T`
        );
      } else {
        webrecorderProcess.kill('SIGINT');
      }
    }

    webrecorderProcess = child_process.spawn(
        webrecorder,
        ['--no-browser', '--loglevel', 'error', '--cache-dir', '_warc_cache', '--port', 0, warc],
        spawnOptions
      );

    let port;

    const findPort = function (buff) {
      if (!buff) {
        return;
      }

      buff = buff.toString();
{'fraction_non_alphanumeric': 0.13656387665198239, 'fraction_numerical': 0.0027109454422229754, 'mean_word_length': 3.2528818443804033, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '754730', 'n_tokens_mistral': 1840, 'n_tokens_neox': 1753, 'n_words': 484}