<commit_before>'use strict';

const {app, Menu, Tray} = require('electron');
const url = require('url');
const winston = require('winston');

const config = require('./config');
const prompts = require('./prompts');
const Pings = require('./pings');
const pingfile = require('./pingfile');

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

/**
 * Ensures only one instance of the app is running at a time.
 * On launch of second instance, it quits and the first instance
 * notifies the user.
 */
var singleInstance = function() {
  const secondInstance = app.makeSingleInstance((argv, cwd) => {
    // Runs in the existing app when another instance is launched
    const notify = require('electron-main-notification');
    notify(app.getName() + " is already running", {
      body :
          "You can't run multiple copies of TagTime, please quit first if you want to restart."
    });
  });
  if (secondInstance) {
    winston.warn("An instance of " + app.getName() +
                 " is already running, quitting...");
    app.quit();
  }
};

/**
 * Create a system tray icon with context menu
 */
function createTray() {
  winston.debug("Creating tray");
  tray = new Tray('resources/tagtime.png');
  tray.setToolTip(app.getName());
  tray.setContextMenu(Menu.buildFromTemplate([
    {label : 'Preferences', click : function() { return; }},
    {label : 'Edit Pings', click : function() { return; }},
    {label : 'Quit', click : app.quit},
  ]));
}

/**
 * Handle invocations in --test mode
 * @param {string} option The requested test mode
 */
var test = function(option) {
  switch(option) {
    case "prompt":
      app.on('ready', prompts.openPrompt);
      break;
    default:
      throw("Didn't recognise test option" + option);
  }
};

/**
 * Application init
 */
var main = function() {
  winston.level = config.user.get('loglevel');
  global.logger = winston; // expose the logger to renderer windows

  // Prevent second instance from running
  singleInstance();

  winston.debug(app.getName() + " v" + app.getVersion() + " starting up");

  var program = require('commander');
  program
    .version(process.env.npm_package_version)
    .option('--test [option]', "Development test mode")
    .parse(process.argv);

  global.pingFile = new pingfile(config.user.get('pingFilePath'));
  global.pings = new Pings(config.period(), config.user.get('seed'));

  if(program.test) {
    test(program.test);
  } else {
    // The tray doesn't count as a window, so don't quit when the other windows
    // are closed
    app.on('window-all-closed', () => {});

    // This method will be called when Electron has finished<commit_msg>Stop processing if 2nd instance<commit_after>'use strict';

const {app, Menu, Tray} = require('electron');
const url = require('url');
const winston = require('winston');

const config = require('./config');
const prompts = require('./prompts');
const Pings = require('./pings');
const pingfile = require('./pingfile');

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

/**
 * Ensures only one instance of the app is running at a time.
 * On launch of second instance, it quits and the first instance
 * notifies the user.
 * @return {bool} true if this is the only instance, false otherwise
 */
var singleInstance = function() {
  const secondInstance = app.makeSingleInstance((argv, cwd) => {
    // Runs in the existing app when another instance is launched
    const notify = require('electron-main-notification');
    notify(app.getName() + " is already running", {
      body :
          "You can't run multiple copies of TagTime, please quit first if you want to restart."
    });
  });
  if (secondInstance) {
    winston.warn("An instance of " + app.getName() +
                 " is already running, quitting...");
    app.quit();
	return false;
  }
  return true;
};

/**
 * Create a system tray icon with context menu
 */
function createTray() {
  winston.debug("Creating tray");
  tray = new Tray('resources/tagtime.png');
  tray.setToolTip(app.getName());
  tray.setContextMenu(Menu.buildFromTemplate([
    {label : 'Preferences', click : function() { return; }},
    {label : 'Edit Pings', click : function() { return; }},
    {label : 'Quit', click : app.quit},
  ]));
}

/**
 * Handle invocations in --test mode
 * @param {string} option The requested test mode
 */
var test = function(option) {
  switch(option) {
    case "prompt":
      app.on('ready', prompts.openPrompt);
      break;
    default:
      throw("Didn't recognise test option" + option);
  }
};

/**
 * Application init
 */
var main = function() {
  winston.level = config.user.get('loglevel');
  global.logger = winston; // expose the logger to renderer windows

  // Prevent second instance from running
  if (!singleInstance()) {
    return;
  }

  winston.debug(app.getName() + " v" + app.getVersion() + " starting up");

  var program = require('commander');
  program
    .version(process.env.npm_package_version)
    .option('--test [option]', "Development test mode")
    .parse(process.argv);

  global.pingFile = new pingfile(config.user.get('pingFilePath'));
  global.pings = new Pings(config.period(), config.user.get('seed'));

  if(program.test) {
    test(program.test);
  } else {
    // The tray doesn't count as a window, so don't quit when the other windows
    // are closed
    app.on('window-all-closed', () => {});

    // This method will be called when Electron has finished
{'fraction_non_alphanumeric': 0.14514407684098185, 'fraction_numerical': 0.00017787264318747776, 'mean_word_length': 3.3964034401876466, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5468276', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1614, 'n_words': 532}