50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
// correct fetch for desktop application
|
|
|
|
var printErr = undefined;
|
|
var print = undefined;
|
|
|
|
var fetch = ("undefined" !== typeof window) ? window.fetch : (("undefined" !== typeof self) ? self.fetch : null);
|
|
var getBinaryPromise = null;
|
|
|
|
function internal_isLocal()
|
|
{
|
|
if (window.navigator && window.navigator.userAgent.toLowerCase().indexOf("ascdesktopeditor") < 0)
|
|
return false;
|
|
if (window.location && window.location.protocol == "file:")
|
|
return true;
|
|
if (window.document && window.document.currentScript && 0 == window.document.currentScript.src.indexOf("file:///"))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
if (internal_isLocal())
|
|
{
|
|
fetch = undefined; // fetch not support file:/// scheme
|
|
getBinaryPromise = function()
|
|
{
|
|
var wasmPath = "ascdesktop://fonts/" + 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.apply(undefined, arguments); }
|
|
}
|