{"size": 1729, "ext": "js", "max_stars_repo_path": "src/main/index.js", "max_stars_repo_name": "icezeros/ice-proxy", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/main/index.js", "max_issues_repo_name": "icezeros/ice-proxy", "max_issues_repo_issues_event_min_datetime": "2021-01-28T21:21:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T19:12:18.000Z", "max_forks_repo_path": "src/main/index.js", "max_forks_repo_name": "icezeros/ice-proxy", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 22.1666666667, "max_line_length": 66, "alphanum_fraction": 0.6130711394}
import { app } from 'electron';
import is from 'electron-is';

import logger from './logger';
import Application from './Application';
import { IProxy } from './services/proxy';

import handleQuit from './event/quit';
import handleMessage from './event';
if (process.env.NODE_ENV !== 'development') {
  global.__static = require('path')
    .join(__dirname, '/static')
    .replace(/\\/g, '\\\\');
}

// if (is.windows()) {
//   app.setAppUserModelId(appId);
// }
const application = new Application();
global.application = application;
global.proxy = new IProxy();

function makeSingleInstance(callback) {
  if (is.mas()) {
    callback();
    return;
  }

  const gotSingleLock = app.requestSingleInstanceLock();
  if (!gotSingleLock) {
    app.quit();
  } else {
    app.on('second-instance', (event, argv, workingDirectory) => {
      logger.warn('second-instance====>', argv, workingDirectory);
      application.showPage('main');
      if (!is.macOS() && argv.length > 1) {
        this.handleAppLaunchArgv(argv);
      }
    });

    callback();
  }
}

function init() {
  handelAppReady();
}
function handelAppReady() {
  app.on('ready', () => {
    application.showPage('main');

    global.application.on('ready', () => {
      //   this.sendUrlToApplication();
      //   this.sendFileToApplication();
    });
    handleQuit();
    handleMessage();
  });

  app.on('activate', () => {
    if (global.application) {
      logger.info('[Motrix] activate');
      global.application.showPage('index');
    }
  });
}

function handleAppWillQuit() {
  app.on('will-quit', () => {
    logger.info('[Motrix] will-quit');
    if (global.application) {
      global.application.stop();
    }
  });
}

makeSingleInstance(init);
