<commit_before>import { app, BrowserWindow, Menu, shell } from 'electron';
import { getCfg } from './config.js';

let menu;
let template;
let mainWindow = null;

if (process.env.NODE_ENV === 'production') {
  const sourceMapSupport = require('source-map-support'); // eslint-disable-line
  sourceMapSupport.install();
}

if (process.env.NODE_ENV === 'development') {
  require('electron-debug')(); // eslint-disable-line global-require
  const path = require('path'); // eslint-disable-line
  const p = path.join(__dirname, '..', 'app', 'node_modules'); // eslint-disable-line
  require('module').globalPaths.push(p); // eslint-disable-line
}

var cfg = getCfg();

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') app.quit();
});

function appDataDirectory() {
  const path = require('path');
  const os = require('os');

  if (process.platform === 'darwin') {
    return path.join(os.homedir(), 'Library','Application Data','Decrediton');
  }

  return path.join(os.homedir(),'.decrediton');
}

function RPCWalletPort() {
  if (cfg.network == "mainnet") {
    return cfg.wallet_port
  }
  return cfg.wallet_port_testnet
}

const installExtensions = async () => {
  if (process.env.NODE_ENV === 'development') {
    const installer = require('electron-devtools-installer'); // eslint-disable-line global-require

    const extensions = [
      'REACT_DEVELOPER_TOOLS',
      'REDUX_DEVTOOLS'
    ];
    const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
    for (const name of extensions) { // eslint-disable-line
      try {
        await installer.default(installer[name], forceDownload);
      } catch (e) {} // eslint-disable-line
    }
  }
};

const launchDCRD = () => {
  var spawn = require('child_process').spawn;
  var args = ['--rpcuser='+cfg.rpc_user,'--rpcpass='+cfg.rpc_pass];

  // The spawn() below opens a pipe on fd 3
  args.push('--piperx=3');

  if (cfg.network == "testnet") {
     args.push('--testnet');
  }

  console.log(`Starting dcrd with ${args}`);
  var dcrd = spawn('dcrd', args, { detached: true, stdio: [ 'ignore', 'pipe', 'pipe', 'pipe' ] });

  dcrd.on('error', function (err) {
    console.log('error starting dcrd: ' + err);
  });

  dcrd.on('close', (code) => {
    console.log(`dcrd exited with code ${code}`);
  });

  dcrd.stdout.on('data', (data) => {
    process.stdout.write(`${data}`);
  });

  dcrd.stderr.on('data', (data) => {
    process.stderr.write(`${data}`);
  });

  dcrd.unref();
}

const launchDCRWallet = () => {
  var spawn = require('child_process').spawn;
  var args = ['--noinitialload','--tlscurve=P-256','--onetimetlskey'];

  // RPC
  args.push('--username=USER');
  args.push('--password=PASSWORD');

  // The spawn() below opens a pipe on fd 4
  args.push('--piperx=4');

  args.push('--appdata=' + appDataDirectory());
  args.push('--experimentalrpclisten=127.0.0.1:' + RPCWalletPort());
  if (cfg.network == "testnet") {
     args.push('--testnet');
  }
  console.log(`Starting dcrwallet with ${args}`);
  var dcrwallet = spawn('dcrwallet', args, { detached: true, stdio: [ 'ignore', 'pipe', 'pipe', 'ignore', 'pipe'  ] });

  dcrwallet.on('error', function (err) {
    console.log('error starting dcrwallet: ' + err);
  });

  dcrwallet.on('close', (code) => {
    console.log(`dcrwallet exited with code ${code}`);
  });

  dcrwallet.stdout.on('data', (data) => {
    process.stdout.write(`${data}`);
  });

  dcrwallet.stderr.on('data', (data) => {
    process.stderr.write(`${data}`);<commit_msg>Explicitly set rpc ports for dcrd.<commit_after>import { app, BrowserWindow, Menu, shell } from 'electron';
import { getCfg } from './config.js';

let menu;
let template;
let mainWindow = null;

if (process.env.NODE_ENV === 'production') {
  const sourceMapSupport = require('source-map-support'); // eslint-disable-line
  sourceMapSupport.install();
}

if (process.env.NODE_ENV === 'development') {
  require('electron-debug')(); // eslint-disable-line global-require
  const path = require('path'); // eslint-disable-line
  const p = path.join(__dirname, '..', 'app', 'node_modules'); // eslint-disable-line
  require('module').globalPaths.push(p); // eslint-disable-line
}

var cfg = getCfg();

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') app.quit();
});

function appDataDirectory() {
  const path = require('path');
  const os = require('os');

  if (process.platform === 'darwin') {
    return path.join(os.homedir(), 'Library','Application Data','Decrediton');
  }

  return path.join(os.homedir(),'.decrediton');
}

function GRPCWalletPort() {
  if (cfg.network == "mainnet") {
    return cfg.wallet_port
  }
  return cfg.wallet_port_testnet
}

function RPCDaemonPort() {
  if (cfg.network == "mainnet") {
    return cfg.daemon_port
  }
  return cfg.daemon_port_testnet
}

const installExtensions = async () => {
  if (process.env.NODE_ENV === 'development') {
    const installer = require('electron-devtools-installer'); // eslint-disable-line global-require

    const extensions = [
      'REACT_DEVELOPER_TOOLS',
      'REDUX_DEVTOOLS'
    ];
    const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
    for (const name of extensions) { // eslint-disable-line
      try {
        await installer.default(installer[name], forceDownload);
      } catch (e) {} // eslint-disable-line
    }
  }
};

const launchDCRD = () => {
  var spawn = require('child_process').spawn;
  var args = ['--rpcuser='+cfg.rpc_user,'--rpcpass='+cfg.rpc_pass];

  // The spawn() below opens a pipe on fd 3
  args.push('--piperx=3');

  if (cfg.network == "testnet") {
     args.push('--testnet');
  }

  args.push('--rpclisten=127.0.0.1:' + RPCDaemonPort());

  console.log(`Starting dcrd with ${args}`);
  var dcrd = spawn('dcrd', args, { detached: true, stdio: [ 'ignore', 'pipe', 'pipe', 'pipe' ] });

  dcrd.on('error', function (err) {
    console.log('error starting dcrd: ' + err);
  });

  dcrd.on('close', (code) => {
    console.log(`dcrd exited with code ${code}`);
  });

  dcrd.stdout.on('data', (data) => {
    process.stdout.write(`${data}`);
  });

  dcrd.stderr.on('data', (data) => {
    process.stderr.write(`${data}`);
  });

  dcrd.unref();
}

const launchDCRWallet = () => {
  var spawn = require('child_process').spawn;
  var args = ['--noinitialload','--tlscurve=P-256','--onetimetlskey'];

  // RPC
  args.push('--username=USER');
  args.push('--password=PASSWORD');

  // The spawn() below opens a pipe on fd 4
  args.push('--piperx=4');

  args.push('--appdata=' + appDataDirectory());
  args.push('--experimentalrpclisten=127.0.0.1:' + GRPCWalletPort());
  if (cfg.network == "testnet") {
     args.push('--testnet');
  }
  console.log(`Starting dcrwallet with ${args}`);
  var dcrwallet = spawn('dcrwallet', args, { detached: true, stdio: [ 'ignore', 'pipe', 'pipe', 'ignore', 'pipe'  ] });

  dcrwallet.on('error', function (err) {
    console.log('error starting dcrwallet: ' + err);
  });

  dcrwallet.on('close', (code) => {
    console.log(`dcrwallet exited with code ${code}`);
  });

  dcrwallet.stdout.on('data', (data) => {
    process.stdout.write(`${data}`);
  });

  dcrwallet.stderr.on('data', (data) => {
    process.stderr.write(`${data}`);
{'fraction_non_alphanumeric': 0.20280594527017642, 'fraction_numerical': 0.004445061814140853, 'mean_word_length': 3.7151277013752457, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '201550', 'n_tokens_mistral': 2575, 'n_tokens_neox': 2494, 'n_words': 479}