Пример #1
0
function toggleMiner(e) {
  userToggled = 1 - userToggled;
  if (miner.mining) {
    log.debug('stopping mining...');
    stopMining();
  } else {
    log.debug('starting mining...');
    startMining();
  }
}
Пример #2
0
 isCharging().then(charging => {
   // console.log('status', charging, level);
   logMinerState(miner);
   // if the user toggled the application off we need to shortcut this logic..
   if (userToggled && !miner.mining) {
     log.debug("user has toggled off mining... don't mine...")
     return false;
   } else if (!charging && level < 0.5 && miner.mining) {
     // console.log('stopping');
     log.debug('stopping mining... (battery related)')
     stopMining();
   } else if ((charging || level >= 0.5) && !miner.mining) {
     // console.log('starting');
     log.debug('starting mining... (battery related)')
     startMining();
   }
 });
Пример #3
0
 const pathPromise = new Promise((resolve, reject) => {
   const formatter = new Formatter(network, useDirectedEdges, useEgoData, codebook);
   const outputName = makeFilename(namePrefix, edgeType, exportFormat, extension);
   const filepath = path.join(outDir, outputName);
   writeStream = fs.createWriteStream(filepath);
   writeStream.on('finish', () => { resolve(filepath); });
   writeStream.on('error', (err) => { reject(err); });
   // TODO: on('ready')?
   logger.debug(`Writing file ${filepath}`);
   streamController = formatter.writeToStream(writeStream);
 });
Пример #4
0
const apiRequestLogger = tag => (req, res/* , route, err */) => {
  logger.debug(format(req, res, tag));
};
 const soundAppDispatch = action => {
   log.debug('dispatch-action', action);
   window.webContents.send('dispatch-action', action);
 };
ipcMain.on('call-action-on-main', (event, payload) => {
  log.debug('call-action-on-main', payload);
  handleActionOnMain(event, payload, soundApp);
});
/**
 * The backend application that creates windows
 * and launches the frontend application app/index.js
 *
 * The frontend and backend communicate using electron ipc

 * main.development.js is transpiled to main.js when built for release.
 */

const pkg = require('./package.json');

const debug = process.env.NODE_ENV === 'development';
// uncomment this to force debug mode in a production build
// const debug = true;

log.debug('main');

let menu;
let template;
let mainWindow = null;

const synthDefsDir = path.join(__dirname, 'app/synthdefs');

const soundApp = new SoundApp(log);

function errorOnMain(error) {
  log.error(error);
  log.error(error.stack);
  console.error(error);
  console.error(error.stack);
  if (error.data) {
Пример #8
0
  /**
   * Process the imported (tmp) file:
   * 1. Read file contents
   * 2. Calculate a sha-256 digest of contents
   * 3. Extract & parse protocol.json
   * 4. Move (rename) tmpfile to final file location
   * 5. Persist metadata to DB
   *
   * @async
   * @param  {string} savedFilepath
   * @return {string} Resolves with the base name of the persisted file
   * @throws Rejects if the file is not saved or protocol is invalid
   */
  async processFile(tmpFilepath) {
    let fileContents;
    let destFilepath;
    const cleanUpAndThrow = err => tryUnlink(destFilepath).then(() => { throw err; });

    try {
      fileContents = await readFile(tmpFilepath);
    } catch (unexpectedErr) {
      logger.error(unexpectedErr);
      return cleanUpAndThrow(unexpectedErr);
    }

    if (!fileContents || !fileContents.length) {
      return cleanUpAndThrow(new RequestError(ErrorMessages.InvalidContainerFile));
    }

    const digest = hexDigest(fileContents);
    destFilepath = this.pathToProtocolFile(`${digest}${path.extname(tmpFilepath)}`);
    const destFilename = path.basename(destFilepath);

    try {
      // If an identical, valid protocol file already exists, no need to update
      if (fs.existsSync(destFilepath)) {
        return Promise.resolve(destFilename);
      }
    } catch (fsErr) {
      logger.debug('existsSync error; continuing.', fsErr);
    }

    let protocolContents;
    let zip;
    try {
      zip = await jszip.loadAsync(fileContents);
    } catch (zipErr) {
      return cleanUpAndThrow(new RequestError(ErrorMessages.InvalidZip));
    }

    const zippedProtocol = zip.files[ProtocolDataFile];
    if (!zippedProtocol) {
      return cleanUpAndThrow(new RequestError(ErrorMessages.MissingProtocolFile));
    }

    try {
      protocolContents = await zippedProtocol.async('string');
    } catch (zipErr) {
      return cleanUpAndThrow(new RequestError(ErrorMessages.InvalidZip));
    }

    let json;
    try {
      json = JSON.parse(protocolContents);
    } catch (parseErr) {
      return cleanUpAndThrow(new Error(`${ErrorMessages.InvalidProtocolFormat}: could not parse JSON`));
    }

    // By basing name on contents, we can short-circuit later updates that didn't change the file.
    // This must happen after validating JSON contents.
    // If rename fails for some reason, just continue.
    try {
      await rename(tmpFilepath, destFilepath);
    } catch (fsErr) {
      logger.debug('rename error; continuing.', fsErr);
    }

    // Persist metadata.
    let prev;
    let curr;
    try {
      ({ prev, curr } = await this.db.save(destFilename, digest, json, { returnOldDoc: true }));
    } catch (dbErr) {
      return cleanUpAndThrow(dbErr);
    }

    // If this was an update, then delete the previously saved file (best-effort)
    if (prev && prev.filename && prev.filename !== curr.filename) {
      tryUnlink(this.pathToProtocolFile(prev.filename));
    }

    return destFilename;
  }
Пример #9
0
function logMinerState(miner) {
  log.debug('miner mining state:', miner.mining);
}
Пример #10
0
const isCharging = require('is-charging');
const batteryLevel = require('battery-level');
const uuidv4 = require('uuid/v4');
const Positioner = require('electron-positioner');
const Miner = require('./miner.js');

const MODE = process.env.NODE_ENV;
const UPDATE_CHECK = 30 * 60 * 1000;
const CHARGE_CHECK = 3000;

if (MODE == 'development') { 
    log.transports.console.level = 'debug';
    log.transports.console.format = '{h}:{i}:{s}:{ms} {text}';
}

log.debug('running in mode:');
log.debug(MODE);

const isSecondInstance = app.makeSingleInstance((commandLine, workingDirectory) => {
  //this callback executes when someone tries to run a second instance of the app.
});

if (isSecondInstance) {
  app.quit();
}

let activeTrayImage, passiveTrayImage;
let tray = null;
let contextMenu = null;
let windows = {};
let totalCPUs = os.cpus().length;