cordova-app-loader
Version:
Cordova App Loader - remote update your cordova app
1 lines • 6.19 kB
JavaScript
var CordovaPromiseFS=function(n){function e(r){if(t[r])return t[r].exports;var o=t[r]={exports:{},id:r,loaded:!1};return n[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var t={};return e.m=n,e.c=t,e.p="",e(0)}([function(n){function e(n,t,r,o){n.getDirectory(t[0],{create:!0},function(n){t.length>1?e(n,t.slice(1),r,o):r(n)},o)}function t(n){return n=n.substr(0,n.lastIndexOf("/")+1),"/"===n[0]&&(n=n.substr(1)),n}function r(n){return n.substr(n.lastIndexOf("/")+1)}function o(n){return n=n||"","/"===n[0]&&(n=n.substr(1)),n&&n.indexOf(".")<0&&"/"!==n[n.length-1]&&(n+="/"),"./"===n&&(n=""),n}var i=[],u=0;n.exports=function(n){function f(n){return new L(function(e){return e(n)})}function s(n){return new L(function(t,r){return q.then(function(o){n?(n=n.split("/").filter(function(n){return n&&n.length>0&&"."!==n&&".."!==n}),e(o.root,n,t,r)):t(o.root)},r)})}function c(n,e){return new L(function(t,r){return"object"==typeof n?t(n):(n=o(n),e=e||{},q.then(function(o){o.root.getFile(n,e,t,r)},r))})}function a(n,e){return n=o(n),e=e||{},new L(function(t,r){return q.then(function(o){n&&"/"!==n?o.root.getDirectory(n,e,t,r):t(o.root)},r)})}function l(n,e){e=e||"";var t=e.indexOf("r")>-1,r=e.indexOf("e")>-1,o=e.indexOf("f")>-1,i=e.indexOf("d")>-1;return o&&i&&(o=!1,i=!1),new L(function(e,u){return a(n).then(function(n){var s=n.createReader();s.readEntries(function(n){var s=[f(n)];t&&n.filter(function(n){return n.isDirectory}).forEach(function(n){s.push(l(n.fullPath,"re"))}),L.all(s).then(function(n){var t=[];t=t.concat.apply(t,n),o&&(t=t.filter(function(n){return n.isFile})),i&&(t=t.filter(function(n){return n.isDirectory})),r||(t=t.map(function(n){return n.fullPath})),e(t)},u)},u)},u)})}function d(n){return new L(function(e,t){c(n).then(function(n){e(n)},function(n){1===n.code?e(!1):t(n)})})}function p(n){return s(t(n)).then(function(){return c(n,{create:!0})})}function y(n){return c(n).then(function(n){return n.toURL()})}function h(n,e){return e=e||"readAsText",c(n).then(function(n){return new L(function(t,r){n.file(function(n){var r=new FileReader;r.onloadend=function(){t(this.result)},r[e](n)},r)})})}function w(n){return h(n,"readAsDataURL")}function v(n){return h(n).then(JSON.parse)}function m(n,e,r){return s(t(n)).then(function(){return c(n,{create:!0})}).then(function(n){return new L(function(t,o){n.createWriter(function(n){n.onwriteend=t,n.onerror=o,"string"==typeof e?e=new Blob([e],{type:r||"text/plain"}):e instanceof Blob!=!0&&(e=new Blob([JSON.stringify(e,null,4)],{type:r||"application/json"})),n.write(e)},o)})})}function g(n,e){return s(t(e)).then(function(t){return c(n).then(function(n){return new L(function(o,i){n.moveTo(t,r(e),o,i)})})})}function S(n,e){return s(t(e)).then(function(t){return c(n).then(function(n){return new L(function(o,i){n.copyTo(t,r(e),o,i)})})})}function b(n,e){var t=e?c:d;return new L(function(e,r){t(n).then(function(n){n!==!1?n.remove(e,r):e(1)},r)}).then(function(n){return 1===n?!1:!0})}function x(n){return a(n).then(function(n){return new L(function(e,t){n.removeRecursively(e,t)})})}function F(){for(;i.length>0&&u<n.concurrency;){u++;var e=i.pop(),t=e.shift(),r=e.shift(),o=e.shift(),f=e.shift(),s=e.shift(),c=e.shift(),a=e.shift(),l=e.shift();t._aborted?u--:r?(t.download.call(t,o,f,s,c,a,l),t.onprogress&&t.onprogress(new ProgressEvent)):t.upload.call(t,f,o,s,c,l,a)}}function R(n){return u--,F(),n}function O(e,t,o,f,s){"function"==typeof f&&(s=f,f={}),U&&o.indexOf("://")<0&&(o=C(o)),f=f||{},f.retry&&f.retry.length||(f.retry=n.retry),f.retry=f.retry.concat(),f.file||e||(f.fileName=r(o));var c=new FileTransfer;s=s||f.onprogress,"function"==typeof s&&(c.onprogress=s);var a=new L(function(n,r){var s=function(u){if(0===f.retry.length)r(u);else{i.unshift([c,e,t,o,n,s,f.trustAllHosts||!1,f]);var a=f.retry.shift();a>0?setTimeout(R,a):R()}};f.retry.unshift(0),u++,s()});return a.then(R,R),a.progress=function(n){return c.onprogress=n,a},a.abort=function(){return c._aborted=!0,c.abort(),a},a}function E(n,e,t,r){return O(!0,n,e,t,r)}function T(n,e,t,r){return O(!1,e,n,t,r)}var L=n.Promise||window.Promise;if("undefined"==typeof L)throw new Error("No Promise library given in options.Promise");this.options=n=n||{},n.persistent=void 0!==n.persistent?n.persistent:!0,n.storageSize=n.storageSize||20971520,n.concurrency=n.concurrency||3,n.retry=n.retry||[];var P,U="undefined"!=typeof cordova;U?P=new L(function(n,e){document.addEventListener("deviceready",n,!1),setTimeout(function(){e(new Error("deviceready has not fired after 5 seconds."))},5100)}):(P=f(!0),"undefined"!=typeof webkitRequestFileSystem?(window.requestFileSystem=webkitRequestFileSystem,window.FileTransfer=function(){},FileTransfer.prototype.download=function(n,e,t,r){var o=new XMLHttpRequest;return o.open("GET",n),o.responseType="blob",o.onreadystatechange=function(){4==o.readyState&&(200===o.status?m(e,o.response).then(t,r):r(o.status))},o.send(),o},window.ProgressEvent=function(){},window.FileEntry=function(){}):window.requestFileSystem=function(n,e,t,r){r(new Error("requestFileSystem not supported!"))});var q=new L(function(e,t){P.then(function(){var r=n.persistent?1:0;"number"==typeof n.fileSystem&&(r=n.fileSystem),!U&&r>1&&(console.warn('Chrome does not support fileSystem "'+r+'". Falling back on "0" (temporary).'),r=0),window.requestFileSystem(r,n.storageSize,e,t),setTimeout(function(){t(new Error("Could not retrieve FileSystem after 5 seconds."))},5100)},t)});q.then(function(n){window.__fs=n},function(n){console.error("Could not get Cordova FileSystem:",n)});var D,C;return U?(C=function(e){return e=o(e),e.indexOf("://")<0?"cdvfile://localhost/"+(n.persistent?"persistent/":"temporary/")+e:e},D=function(n){return c(n).then(function(n){return n.toInternalURL()})}):(C=function(e){return e=o(e),"filesystem:"+location.origin+(n.persistent?"/persistent/":"/temporary/")+e},D=function(n){return c(n).then(function(n){return n.toURL()})}),{fs:q,normalize:o,file:c,filename:r,dir:a,dirname:t,create:p,read:h,readJSON:v,write:m,move:g,copy:S,remove:b,removeDir:x,list:l,ensure:s,exists:d,download:E,upload:T,toURL:y,isCordova:U,toInternalURLSync:C,toInternalURL:D,toDataURL:w,deviceready:P,options:n,Promise:L}}}]);