Repository URL to install this package:
|
Version:
1.2.0-1346 ▾
|
!function(e){"use strict";e="default"in e?e.default:e;var r=require("path"),t=require("electron"),n=t.remote,o=require("fs"),i=require("adm-zip"),a=require("fs-extra"),s=require("os").tmpdir(),p=r.resolve(s,"ndm-"),c=require(r.resolve(__dirname,"..","package.json"));e.module("ndm-updater",[]).constant("updateUrl","https://api.github.com/repos/720kb/ndm/releases/latest").controller("ShellController",["$scope","$document","$log","updateUrl",function(e,t,s,d){var u=this,l=function(r){var t=void 0,n=void 0;"darwin"===process.platform?n="mac.zip":"win32"===process.platform&&(n="win.zip"),e.$apply(function(){if(u.checking=!1,!r.target.responseText)return u.error="No response",void(u.errorChecking=!0);try{t=JSON.parse(r.target.responseText),s.info("Github Fetched Metas",t)}catch(e){return u.error=e,void(u.errorChecking=!0)}if(t.tag_name==="v"+c.version||-1===t.tag_name.indexOf("v"))return void(u.toUpdate=!1);u.nextVesion=t.name.replace("v",""),u.toUpdate=!0,u.url=t.assets.filter(function(e){return e.name.indexOf(n)>-1}).reduce(function(e){return e}).browser_download_url})},f=function(){e.$apply(function(){u.checking=!1,u.errorChecking=!0})},g=function(){e.$apply(function(){u.checking=!1,u.errorUpdating=!0,u.progress=100})},h=function(e){o.mkdtemp(p,function(t,p){var c=r.resolve(p,"npm_"+(new Date).getTime()),d=void 0;if("darwin"===process.platform?d=r.resolve(p,r.join("ndm.app","Contents","Resources","app")):"win32"===process.platform&&(d=r.resolve(p,r.join("win-ia32-unpacked","resources","app"))),t)throw t;o.appendFile(c,new Buffer(e.target.response),function(e){if(e)throw e;try{new i(c).extractAllTo(p,!0)}catch(e){s.warn(e)}a.move(d,n.app.getAppPath(),{overwrite:!0},function(e){if(e)throw e;n.app.relaunch(),n.app.exit(0)})})})},v=function(r){e.$apply(function(){r.lengthComputable?u.progress=r.loaded/r.total*100:u.progress=(u.progress+10)%100})};this.checkNow=function(){if(!u.checking){u.errorChecking=!1,u.checking=!0;var e=new window.XMLHttpRequest;delete u.toUpdate,e.addEventListener("load",l),e.addEventListener("error",f),e.open("GET",d),e.send()}},this.updateIt=function(){if(!u.updating){u.errorUpdating=!1,u.updating=!0;var e=new window.XMLHttpRequest;delete u.toUpdate,e.addEventListener("load",h),e.addEventListener("error",g),e.addEventListener("progress",v),e.open("GET",u.url),e.responseType="arraybuffer",e.send()}},this.currentVersion=c.version,this.checkNow(),t[0].addEventListener("visibilitychange",function(){"visible"!==t[0].visibilityState||u.checking||u.updating||u.checkNow()})}])}(angular);