<commit_before>var atom = require('app');
var path = require('path');
var spawn = require('child_process').spawn;
var BrowserWindow = require('browser-window');
var Menu = require('menu');
var shell = require('shell');
var versionCheck = require('./lib/version-check');
var log = require('./lib/log');
var node = path.resolve(path.join(__dirname, 'vendor', 'node'));
var script = path.resolve(path.join(__dirname, 'index-server.js'));
var logger = require('fastlog')('', 'debug', '<${timestamp}>');
var server = null
var serverPort = null;
var mainWindow = null;

if (process.platform === 'win32') {
    // HOME is undefined on windows
    process.env.HOME = process.env.USERPROFILE;
}

atom.on('window-all-closed', exit);
atom.on('ready', makeWindow);

process.on('exit', function(code) {
    logger.debug('Mapbox Studio exited ' + (undefined === code ? 'normally' : 'with ' + code));
});

process.on('uncaughtException', function(err) {
    logger.debug('Hit unexpected JS Error in server, please report this entire log to https://github.com/mapbox/mapbox-studio-classic/issues');
    if (err) {
      logger.debug(err);
    } else {
      logger.debug('no error reported');
    }
});

function exit() {
    if (server){ server.kill() };
    //atom.quit(); //is the way to do it: https://github.com/atom/atom-shell/blob/master/docs/api/app.md#app
    if (atom.listeners('window-all-closed').length == 1){ atom.quit(); }
};


var shellLog = path.join(process.env.HOME, '.mapbox-studio', 'shell.log');
// set up shell.log and log rotation
log(shellLog, 10e6, shellsetup);

function shellsetup(err){

    // Start the server child process.
    server = spawn(node, [script, '--shell=true'])
        .on('error', function(error){
            process.stdout.write('error spawning server process: ' + error + '\n');
        })
        .on('exit', exit);
    if(!server.pid){
        process.stdout.write('server process has no pid\n');
    } else {
        process.stdout.write('server process pid: ' + server.pid + '\n');
        server.stdout.once('data', function(data) {
            var matches = data.toString().match(/Mapbox Studio @ http:\/\/localhost:([0-9]+)\//);
            if (!matches) {
                console.warn('Server port not found');
                process.exit(1);//?? atom.quit();
            }
            serverPort = matches[1];
            logger.debug('Mapbox Studio @ http://localhost:'+serverPort+'/');
            loadURL();
        });

        // Report crashes to our server.
        require('crash-reporter').start();
    }
};

function makeWindow() {
    // Create the browser window.
    mainWindow = new BrowserWindow({
        width: 960,
        height: 600,
        'min-width': 720,
        'min-height': 480,
        title: 'Mapbox Studio',<commit_msg>change atom-shell windows title -> Classic<commit_after>var atom = require('app');
var path = require('path');
var spawn = require('child_process').spawn;
var BrowserWindow = require('browser-window');
var Menu = require('menu');
var shell = require('shell');
var versionCheck = require('./lib/version-check');
var log = require('./lib/log');
var node = path.resolve(path.join(__dirname, 'vendor', 'node'));
var script = path.resolve(path.join(__dirname, 'index-server.js'));
var logger = require('fastlog')('', 'debug', '<${timestamp}>');
var server = null
var serverPort = null;
var mainWindow = null;

if (process.platform === 'win32') {
    // HOME is undefined on windows
    process.env.HOME = process.env.USERPROFILE;
}

atom.on('window-all-closed', exit);
atom.on('ready', makeWindow);

process.on('exit', function(code) {
    logger.debug('Mapbox Studio exited ' + (undefined === code ? 'normally' : 'with ' + code));
});

process.on('uncaughtException', function(err) {
    logger.debug('Hit unexpected JS Error in server, please report this entire log to https://github.com/mapbox/mapbox-studio-classic/issues');
    if (err) {
      logger.debug(err);
    } else {
      logger.debug('no error reported');
    }
});

function exit() {
    if (server){ server.kill() };
    //atom.quit(); //is the way to do it: https://github.com/atom/atom-shell/blob/master/docs/api/app.md#app
    if (atom.listeners('window-all-closed').length == 1){ atom.quit(); }
};


var shellLog = path.join(process.env.HOME, '.mapbox-studio', 'shell.log');
// set up shell.log and log rotation
log(shellLog, 10e6, shellsetup);

function shellsetup(err){

    // Start the server child process.
    server = spawn(node, [script, '--shell=true'])
        .on('error', function(error){
            process.stdout.write('error spawning server process: ' + error + '\n');
        })
        .on('exit', exit);
    if(!server.pid){
        process.stdout.write('server process has no pid\n');
    } else {
        process.stdout.write('server process pid: ' + server.pid + '\n');
        server.stdout.once('data', function(data) {
            var matches = data.toString().match(/Mapbox Studio @ http:\/\/localhost:([0-9]+)\//);
            if (!matches) {
                console.warn('Server port not found');
                process.exit(1);//?? atom.quit();
            }
            serverPort = matches[1];
            logger.debug('Mapbox Studio @ http://localhost:'+serverPort+'/');
            loadURL();
        });

        // Report crashes to our server.
        require('crash-reporter').start();
    }
};

function makeWindow() {
    // Create the browser window.
    mainWindow = new BrowserWindow({
        width: 960,
        height: 600,
        'min-width': 720,
        'min-height': 480,
        title: 'Mapbox Studio Classic',
{'fraction_non_alphanumeric': 0.1783745331673484, 'fraction_numerical': 0.007825004446025253, 'mean_word_length': 2.9356193142057383, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 4, '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': '2679285', 'n_tokens_mistral': 1721, 'n_tokens_neox': 1662, 'n_words': 412}