const electron = require('electron');
const BrowserWindow = electron.BrowserWindow;
const appVersion = require('../package.json').version;
const request = require('request');
const ipcMain = electron.ipcMain;
const rootpath = process.cwd();
var url = 'http://versionsc.cloud.hoge.cn/index.php?m=Apiversion&c=index&a=show&bundle_id=workcall_pc&app_version='+ appVersion +'&client_type=ios&app_secret=bcf60b6c5cf689729060c20ebc34bd9f';
request(url, function (error, response, body) {
      if(!body) return;
      var info = JSON.parse( body );
      if( info.version != appVersion ){
            var win = new BrowserWindow({
                  width: 350,
                  height: 400,
                  title : '阿米协同',
                  frame : false,
                  resizable : false,
                  movable : false,
                  alwaysOnTop : true,
                  fullscreenable : false,
                  frame: false,
                  backgroundColor : '#eeeeee'
            });
            ipcMain.on('get-info', function(event, arg){
                  event.returnValue = body;
            })
            ipcMain.on('update-close', function(event, arg){
                  win.close();
            })
            win.loadURL('file://' + rootpath + '/update.html');
            win.focus();
      }
});
