Files
core/Common/js/desktop_fetch.js
2021-04-25 21:42:31 +03:00

38 lines
954 B
JavaScript

// correct fetch for desktop application
var printErr = undefined;
var print = undefined;
var fetch = self.fetch;
var getBinaryPromise = null;
if (self.AscDesktopEditor && document.currentScript && 0 == document.currentScript.src.indexOf("file:///"))
{
fetch = undefined; // fetch not support file:/// scheme
getBinaryPromise = function()
{
var wasmPath = "ascdesktop://zlib/" + wasmBinaryFile.substr(8);
return new Promise(function (resolve, reject)
{
var xhr = new XMLHttpRequest();
xhr.open('GET', wasmPath, true);
xhr.responseType = 'arraybuffer';
if (xhr.overrideMimeType)
xhr.overrideMimeType('text/plain; charset=x-user-defined');
else
xhr.setRequestHeader('Accept-Charset', 'x-user-defined');
xhr.onload = function ()
{
if (this.status == 200)
resolve(new Uint8Array(this.response));
};
xhr.send(null);
});
}
}
else
{
getBinaryPromise = function() { return getBinaryPromise2(); }
}