<commit_before>require('crash-reporter').start();
var app = require('app');
var BrowserWindow = require('browser-window');
var {MenuManager} = require('./MenuManager');
var Config = require('../package.json');
var _ = require('lodash');
var ipc = require('ipc');
var fs = require('fs');
var dialog = require('dialog');

var windowCache = {};
var dockNotificationCache = {};
var menuManagerCache = {};
var windowCount = 0;

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

app.on('browser-window-blur', function(event, window) {
  window.$focus = false;
});

app.on('browser-window-focus', function(event, window) {
  window.$focus = true;
  dockNotificationCache[window.id] = 0;
  if (process.platform === 'darwin') {
    app.dock.setBadge('');
  }
});

app.on('ready', onReady);
app.on('activate-with-no-open-windows', onReady);

ipc.on('application:message-box', function(event, options) {
  dialog.showMessageBox(BrowserWindow.getFocusedWindow(), options);
});

ipc.on('application:download', function(event, buffer) {
  let filename = dialog.showSaveDialog(BrowserWindow.getFocusedWindow(), {
    title: 'Download to File…',
    filters: [
      { name: 'All Files', extensions: ['*'] }
    ]
  });
  if(filename) {
    fs.writeFile(filename, buffer, (err) => {
      let options = { buttons: ['Close'] };
      if(err) {
        options = _.extend(options, {
          title: 'Download Error',
          type: 'error',
          message: err.name || 'Export Error',
          detail: err.toString()
        });
      } else {
        options = _.extend(options, {
          title: 'Download Success',
          type: 'info',
          message: `Saved to ${filename}`
        });
      }
      dialog.showMessageBox(BrowserWindow.getFocusedWindow(), options);
    });
  }
});

ipc.on('application:dock-message-notification', function(event, id) {
  dockNotificationCache[id] = dockNotificationCache[id] + 1;
  if (process.platform === 'darwin') {
    app.dock.setBadge(`${dockNotificationCache[id]}`);
    app.dock.bounce();
  }
});

function onReady() {
  var {width, height} = require('screen').getPrimaryDisplay().workAreaSize;

  let mainWindow = new BrowserWindow({
    width: width * 0.75,
    height: height * 0.75,
    'min-height': height * 0.5,
    'min-width': width * 0.5,
    resizable: true,
    'web-preferences': {
			'overlay-scrollbars': true,
      'plugins': true,
      'experimental-features': true,
      'experimental-canvas-features': true,
      'webgl': true
		},
    show: false,
  });

  windowCache[mainWindow.id] = mainWindow;
  let menuManager = menuManagerCache[mainWindow.id] = new MenuManager();

  mainWindow.loadUrl('file://' + __dirname + '/../index.html');
  mainWindow.flashFrame(true);
  mainWindow.setTitle(`${_.capitalize(Config.name)} - REPL(${windowCount})`);
  windowCount += 1;

  mainWindow.on('closed', function() {
    delete windowCache[mainWindow.id];
    delete menuManagerCache[mainWindow.id];
  });

  mainWindow.webContents.on('did-finish-load', function() {
    let totalActiveWindows = _.keys(windowCache).length;
    if(totalActiveWindows > 1) {
      let fixPos = (axis, adj) => {
        let naxis = axis + adj;
        return naxis <= 0 ? axis : naxis;
      };
      let [x,y] = mainWindow.getPosition();
      let adj = parseInt(Math.random() * 50) * (Math.random() > 0.3 ? -1: 1);
      let [nx, ny] = [fixPos(x, adj), fixPos(y, adj)];<commit_msg>Add support for application icon in Linux<commit_after>require('crash-reporter').start();
var app = require('app');
var path = require('path')
var BrowserWindow = require('browser-window');
var {MenuManager} = require('./MenuManager');
var Config = require('../package.json');
var _ = require('lodash');
var ipc = require('ipc');
var fs = require('fs');
var dialog = require('dialog');

var windowCache = {};
var dockNotificationCache = {};
var menuManagerCache = {};
var windowCount = 0;

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

app.on('browser-window-blur', function(event, window) {
  window.$focus = false;
});

app.on('browser-window-focus', function(event, window) {
  window.$focus = true;
  dockNotificationCache[window.id] = 0;
  if (process.platform === 'darwin') {
    app.dock.setBadge('');
  }
});

app.on('ready', onReady);
app.on('activate-with-no-open-windows', onReady);

ipc.on('application:message-box', function(event, options) {
  dialog.showMessageBox(BrowserWindow.getFocusedWindow(), options);
});

ipc.on('application:download', function(event, buffer) {
  let filename = dialog.showSaveDialog(BrowserWindow.getFocusedWindow(), {
    title: 'Download to File…',
    filters: [
      { name: 'All Files', extensions: ['*'] }
    ]
  });
  if(filename) {
    fs.writeFile(filename, buffer, (err) => {
      let options = { buttons: ['Close'] };
      if(err) {
        options = _.extend(options, {
          title: 'Download Error',
          type: 'error',
          message: err.name || 'Export Error',
          detail: err.toString()
        });
      } else {
        options = _.extend(options, {
          title: 'Download Success',
          type: 'info',
          message: `Saved to ${filename}`
        });
      }
      dialog.showMessageBox(BrowserWindow.getFocusedWindow(), options);
    });
  }
});

ipc.on('application:dock-message-notification', function(event, id) {
  dockNotificationCache[id] = dockNotificationCache[id] + 1;
  if (process.platform === 'darwin') {
    app.dock.setBadge(`${dockNotificationCache[id]}`);
    app.dock.bounce();
  }
});

function onReady() {
  var {width, height} = require('screen').getPrimaryDisplay().workAreaSize;
  var options = {
    width: width * 0.75,
    height: height * 0.75,
    'min-height': height * 0.5,
    'min-width': width * 0.5,
    resizable: true,
    'web-preferences': {
			'overlay-scrollbars': true,
      'plugins': true,
      'experimental-features': true,
      'experimental-canvas-features': true,
      'webgl': true
		},
    show: false,
  }
  if(process.platform === 'linux') {
    options.icon = path.resolve(__dirname, '..', 'icons', 'mancy.png');
  }
  let mainWindow = new BrowserWindow(options);

  windowCache[mainWindow.id] = mainWindow;
  let menuManager = menuManagerCache[mainWindow.id] = new MenuManager();

  mainWindow.loadUrl('file://' + __dirname + '/../index.html');
  mainWindow.flashFrame(true);
  mainWindow.setTitle(`${_.capitalize(Config.name)} - REPL(${windowCount})`);
  windowCount += 1;

  mainWindow.on('closed', function() {
    delete windowCache[mainWindow.id];
    delete menuManagerCache[mainWindow.id];
  });

  mainWindow.webContents.on('did-finish-load', function() {
    let totalActiveWindows = _.keys(windowCache).length;
    if(totalActiveWindows > 1) {
      let fixPos = (axis, adj) => {
        let naxis = axis + adj;
        return naxis <= 0 ? axis : naxis;
      };
      let [x,y] = mainWindow.getPosition();
      let adj = parseInt(Math.random() * 50) * (Math.random() > 0.3 ? -1: 1);
      let [nx, ny] = [fixPos(x, adj), fixPos(y, adj)];
{'fraction_non_alphanumeric': 0.17911702873160476, 'fraction_numerical': 0.006166783461807989, 'mean_word_length': 3.4240545567265963, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7345808', 'n_tokens_mistral': 2329, 'n_tokens_neox': 2261, 'n_words': 460}