Beispiel #1
0
/**
 * 异常处理
 * @param  {Error} e 错误对象
 */
function errrHandler(e) {
	var msg = e.toString().replace(/\x1B\[\d+m/g, ""),
		msgbox = require("native-msg-box");
	if (!msgErrs[msg]) {
		msgErrs[msg] = msg;
		if (e.plugin === "gulp-less") {
			console.log(JSON.stringify(e, 0, 4).trim() || msg);
		}
		msgbox.prompt({
			msg: msg,
			title: "gulp throw a error"
		}, function() {
			msgErrs[msg] = null;
		});
	}
}
Beispiel #2
0
HFTPlayer.prototype.handleUpgrade = function(data) {
  var gameId = data.gameId;

  msgbox.prompt({
    msg: "Upgrade '" + gameId + "'?",
    title: "HappyFunTimes",
  }, function(err, result) {  // eslint-disable-line
    switch (result) {
      case msgbox.Result.YES:
        this.sendInstallProgress(gameId, 0, 0, "starting upgrade");
        this.download(gameId, true);
        break;
      case msgbox.Result.NO:
        this.sendCmd("installCancelled", {gameId: gameId});
        break;
    }
  }.bind(this));

};
Beispiel #3
0
HFTPlayer.prototype.handleInstall = function(data) {
  /*eslint no-unused-vars:0*/
  /*eslint handle-callback-err:0*/
  var gameId = data.gameId;

  msgbox.prompt({
    msg: "Install '" + gameId + "'?",
    title: "HappyFunTimes",
  }, function(err, result) {
    switch (result) {
      case msgbox.Result.YES:
        this.sendInstallProgress(gameId, 0, 0, "starting install");
        this.download(gameId);
        break;
      case msgbox.Result.NO:
        this.sendCmd("installCancelled", {gameId: gameId});
        break;
    }
  }.bind(this));

};
 req.busboy.on('file', function (fieldname, file, filename) {
   debug("receiving: " + filename);
   var safeishName = filename.replace(/[^a-zA-Z0-9-_. ]/g, '_').substring(0, 64);
   msgbox.prompt({
     msg: "Install '" + safeishName + "'?",
     title: "HappyFunTimes",
   }, function(err, result) {
     if (err) {
       result = msgbox.Result.NO;
     }
     switch (result) {
       case msgbox.Result.YES: {
           utils.getTempTempFilename({postfix: ".zip"})
           .then(function(_fileInfo) {
             fileInfo = _fileInfo;
             debug("streamfile: " + filename);
             return new Promise(function(resolve, reject) {
               var fstream = fs.createWriteStream(fileInfo.filename);
               file.pipe(fstream);
               fstream.on('close', function() {
                 resolve(fileInfo);
               });
               fstream.on('error', function(e) {
                 reject(e);
               });
             });
           })
           .then(function() {
             debug("installing: " + filename);
             return install.install(fileInfo.filename, undefined, { overwrite: true });
           })
           .then(function() {
             debug("installed: " + filename);
             fileInfo.cleanup();
             res.json({
               success: true,
               msg: "Installed",
             });
           })
           .catch(function(e) {
             debug("failed to install: " + filename);
             e = e ? e.toString() : "";
             fileInfo.cleanup();
             res.json({
               sucesss: false,
               msg: "Failed to install: " + e.replace(fileInfo.filename, filename),
             });
           });
         }
         break;
       case msgbox.Result.NO:
       default: {
           res.json({
             success: true,
             msg: "Installation Cancelled",
           });
         }
         break;
     }
   });
 });