{"size": 1849, "ext": "js", "max_stars_repo_path": "views/scripts/main.view.script.js", "max_stars_repo_name": "tsvetilian-ty/21Connect", "max_stars_repo_stars_event_min_datetime": "2018-10-20T16:41:18.000Z", "max_stars_repo_stars_event_max_datetime": "2018-10-20T16:41:18.000Z", "max_issues_repo_path": "views/scripts/main.view.script.js", "max_issues_repo_name": "tsvetilian-ty/21Connect", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "views/scripts/main.view.script.js", "max_forks_repo_name": "tsvetilian-ty/21Connect", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.8793103448, "max_line_length": 89, "alphanum_fraction": 0.6533261222}
/* eslint-env browser */
const { generateToken } = require('../../models');
const electron = require('electron');
const { hostInfo } = require('../../utils');
const pcg = require('../../package.json');
const path = require('path');
const fs = require('fs');

const CaptureDesktop = () => {
  const saveScreenShotPath = path.join(__dirname, '../../', 'assets/tmp', 'desktop.png');

  const getScreenSize = electron.screen.getPrimaryDisplay().workAreaSize;
  const maximumDimentions = Math.max(getScreenSize.width, getScreenSize.height);

  const options = {
    types: ['screen'],
    thumbnailSize: {
      width: maximumDimentions * window.devicePixelRatio,
      height: maximumDimentions * window.devicePixelRatio,
    },
  };

  electron.desktopCapturer.getSources(options, (err, sources) => {
    if (err) console.log(err);
    sources.forEach((source) => {
      if (source.name === 'Entire screen' || source.name === 'Screen 1') {
        fs.writeFile(saveScreenShotPath, source.thumbnail.toPng(), (savingErr) => {
          if (savingErr) { console.log(savingErr); }
        });
      }
    });
  });
};

const appTitle = `${pcg.name}`;
document.getElementById('app_title').innerHTML += appTitle;

const appBuild = `Version: ${pcg.version}`;
document.getElementById('build').innerHTML += appBuild;

const instructions = `To connect your mobile device to ${hostInfo.name} scan the code!`;
document.getElementById('instructions').innerHTML += instructions;

const qrCodeGenerator = () => {
  generateToken((token) => {
    const qrcode = `connect21://${hostInfo.ip}/${hostInfo.name}?token=${token}`;
    console.log(qrcode);
    QRCode.toCanvas(document.getElementById('_canvas'), qrcode, (err) => {
      if (err) {
        electron.ipcRenderer.send('qr-generating-error', err);
      }
    });
  });
};

qrCodeGenerator();
CaptureDesktop();
