<commit_before>const os = require('os');
const path = require('path');
const electron = require('electron');
const fs = require('fs');
const hidefile = require('hidefile');
const ipcMain = electron.ipcMain;
// Module to control application life.
const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;

const int_postage_port = parseInt(Math.random().toString().substring(2)) % (65535 - 1024) + 1024;

const child_process = require('child_process');
var proc = null;

try {
	fs.statSync(os.homedir() + '/.postage/');
	fs.statSync(os.homedir() + '/.postage/postage.conf');
	fs.statSync(os.homedir() + '/.postage/postage-connections.conf');
} catch (e) {
	fs.mkdirSync(os.homedir() + '/.postage/');
	hidefile.hideSync(os.homedir() + '/.postage/');

	console.log('copying config');
	fs.writeFileSync(os.homedir() + '/.postage/postage.conf', fs.readFileSync('postage/config/postage.conf', 'utf8'), 'utf8');
	fs.writeFileSync(os.homedir() + '/.postage/postage-connections.conf', fs.readFileSync('postage/config/postage-connections.conf', 'utf8'), 'utf8');
}

function spawnPostage() {
	proc = child_process.spawn(
		'postage/postage' + (process.platform == 'win32' ? '.exe' : ''),
		[
			'-c', path.normalize(os.homedir() + '/.postage/postage.conf'),
			'-d', path.normalize(os.homedir() + '/.postage/postage-connections.conf'),
			'-r', __dirname + path.normalize('/postage/web_root'),
			'-x', 't',
			'-p', int_postage_port
		], {
			detached: true
		}
	);

	proc.stdout.on('data', function (data) {
		console.log('got data:\n' + data);
	});
	proc.stderr.on('data', function (data) {
		console.log('got data:\n' + data);
	});
	proc.on('close', function (code) {
		console.log(proc.pid + ' closed with code ' + code);
	});
}
spawnPostage();

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow = null;
let configWindow = null;

ipcMain.on('postage', function (event, arg) {
	if (arg === 'restart') {
		proc.kill();
		spawnPostage();
		mainWindow.webContents.executeJavaScript('window.location.reload();');
	} else if (arg === 'edit_config') {
		configWindow = new BrowserWindow({ width: 1024, height: 768 });
		configWindow.loadURL('file://' + __dirname + '/postage/web_root/postage/app/config.html',  { 'extraHeaders': 'pragma: no-cache\n' });
		configWindow.setMenu(null);
	}

})

app.on('quit', function () {
	console.log('quitting');
	proc.kill();
});

function createWindow() {
	// Create the browser window.
	mainWindow = new BrowserWindow({ width: 1024, height: 768 });

	// Open the DevTools.
	mainWindow.webContents.openDevTools();

	mainWindow.loadURL('http://127.0.0.1:' + int_postage_port + '/postage/index.html',  { 'extraHeaders': 'pragma: no-cache\n' });

	mainWindow.setMenu(null);

	// Emitted when the window is closed.
	mainWindow.on('closed', function () {
		// Dereference the window object, usually you would store windows
		// in an array if your app supports multi windows, this is the time
		// when you should delete the corresponding element.
		mainWindow = null;
	});
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);

// Quit when all windows are closed.
app.on('window-all-closed', function () {
	// On OS X it is common for applications and their menu bar
	// to stay active until the user quits explicitly with Cmd + Q
	if (process.platform !== 'darwin') {
		app.quit();
	}
});

app.on('activate', function () {
	// On OS X it's common to re-create a window in the app when the
	// dock icon is clicked and there are no other windows open.
	if (mainWindow === null) {
		createWindow();
	}
});

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
<commit_msg>don;t open dev tools on open<commit_after>const os = require('os');
const path = require('path');
const electron = require('electron');
const fs = require('fs');
const hidefile = require('hidefile');
const ipcMain = electron.ipcMain;
// Module to control application life.
const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;

const int_postage_port = parseInt(Math.random().toString().substring(2)) % (65535 - 1024) + 1024;

const child_process = require('child_process');
var proc = null;

try {
	fs.statSync(os.homedir() + '/.postage/');
	fs.statSync(os.homedir() + '/.postage/postage.conf');
	fs.statSync(os.homedir() + '/.postage/postage-connections.conf');
} catch (e) {
	fs.mkdirSync(os.homedir() + '/.postage/');
	hidefile.hideSync(os.homedir() + '/.postage/');

	console.log('copying config');
	fs.writeFileSync(os.homedir() + '/.postage/postage.conf', fs.readFileSync('postage/config/postage.conf', 'utf8'), 'utf8');
	fs.writeFileSync(os.homedir() + '/.postage/postage-connections.conf', fs.readFileSync('postage/config/postage-connections.conf', 'utf8'), 'utf8');
}

function spawnPostage() {
	proc = child_process.spawn(
		'postage/postage' + (process.platform == 'win32' ? '.exe' : ''),
		[
			'-c', path.normalize(os.homedir() + '/.postage/postage.conf'),
			'-d', path.normalize(os.homedir() + '/.postage/postage-connections.conf'),
			'-r', __dirname + path.normalize('/postage/web_root'),
			'-x', 't',
			'-p', int_postage_port
		], {
			detached: true
		}
	);

	proc.stdout.on('data', function (data) {
		console.log('got data:\n' + data);
	});
	proc.stderr.on('data', function (data) {
		console.log('got data:\n' + data);
	});
	proc.on('close', function (code) {
		console.log(proc.pid + ' closed with code ' + code);
	});
}
spawnPostage();

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow = null;
let configWindow = null;

ipcMain.on('postage', function (event, arg) {
	if (arg === 'restart') {
		proc.kill();
		spawnPostage();
		mainWindow.webContents.executeJavaScript('window.location.reload();');
	} else if (arg === 'edit_config') {
		configWindow = new BrowserWindow({ width: 1024, height: 768 });
		configWindow.loadURL('file://' + __dirname + '/postage/web_root/postage/app/config.html',  { 'extraHeaders': 'pragma: no-cache\n' });
		configWindow.setMenu(null);
	}

})

app.on('quit', function () {
	console.log('quitting');
	proc.kill();
});

function createWindow() {
	// Create the browser window.
	mainWindow = new BrowserWindow({ width: 1024, height: 768 });

	// Open the DevTools.
	//mainWindow.webContents.openDevTools();

	mainWindow.loadURL('http://127.0.0.1:' + int_postage_port + '/postage/index.html',  { 'extraHeaders': 'pragma: no-cache\n' });

	mainWindow.setMenu(null);

	// Emitted when the window is closed.
	mainWindow.on('closed', function () {
		// Dereference the window object, usually you would store windows
		// in an array if your app supports multi windows, this is the time
		// when you should delete the corresponding element.
		mainWindow = null;
	});
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);

// Quit when all windows are closed.
app.on('window-all-closed', function () {
	// On OS X it is common for applications and their menu bar
	// to stay active until the user quits explicitly with Cmd + Q
	if (process.platform !== 'darwin') {
		app.quit();
	}
});

app.on('activate', function () {
	// On OS X it's common to re-create a window in the app when the
	// dock icon is clicked and there are no other windows open.
	if (mainWindow === null) {
		createWindow();
	}
});

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

{'fraction_non_alphanumeric': 0.16614887535727602, 'fraction_numerical': 0.009941593140300733, 'mean_word_length': 4.093670886075949, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2849808', 'n_tokens_mistral': 2779, 'n_tokens_neox': 2602, 'n_words': 731}