Revert "Remove some polyfills"

This reverts commit 64644b57e3.
This commit is contained in:
timvisee 2022-09-04 12:26:12 +02:00
parent 073accfe65
commit 4ceac20623
No known key found for this signature in database
GPG key ID: B8DB720BC383E172
6 changed files with 163 additions and 27 deletions

View file

@ -45,7 +45,13 @@ async function checkCrypto() {
);
return true;
} catch (err) {
return false;
try {
window.asmCrypto = await import('asmcrypto.js');
await import('@dannycoates/webcrypto-liner/build/shim');
return true;
} catch (e) {
return false;
}
}
}
@ -60,12 +66,25 @@ function checkStreams() {
}
}
async function polyfillStreams() {
try {
await import('@mattiasbuelens/web-streams-polyfill');
return true;
} catch (e) {
return false;
}
}
export default async function getCapabilities() {
const browser = browserName();
const isMobile = /mobi|android/i.test(navigator.userAgent);
const serviceWorker = 'serviceWorker' in navigator && browser !== 'edge';
let crypto = await checkCrypto();
const nativeStreams = checkStreams();
let polyStreams = false;
if (!nativeStreams) {
polyStreams = await polyfillStreams();
}
let account = typeof AUTH_CONFIG !== 'undefined';
try {
account = account && !!localStorage;
@ -87,10 +106,10 @@ export default async function getCapabilities() {
account,
crypto,
serviceWorker,
streamUpload: nativeStreams,
streamUpload: nativeStreams || polyStreams,
streamDownload:
nativeStreams && serviceWorker && browser !== 'safari' && !mobileFirefox,
multifile: nativeStreams,
multifile: nativeStreams || polyStreams,
share,
standalone
};

View file

@ -48,7 +48,7 @@ class ECETransformer {
name: 'AES-GCM',
length: 128
},
false,
true, // Edge polyfill requires key to be extractable to encrypt :/
['encrypt', 'decrypt']
);
}

View file

@ -23,34 +23,39 @@ function locale() {
return document.querySelector('html').lang;
}
function loadShim(polyfill) {
return new Promise((resolve, reject) => {
const shim = document.createElement('script');
shim.src = polyfill;
shim.addEventListener('load', () => resolve(true));
shim.addEventListener('error', () => resolve(false));
document.head.appendChild(shim);
});
}
function isFile(id) {
return /^[0-9a-fA-F]{10,16}$/.test(id);
}
async function copyToClipboard(str) {
try {
await navigator.clipboard.writeText(str);
} catch {
// Older browsers or the clipboard API fails because of a missing permission
const aux = document.createElement('input');
aux.setAttribute('value', str);
aux.contentEditable = true;
aux.readOnly = true;
document.body.appendChild(aux);
if (navigator.userAgent.match(/iphone|ipad|ipod/i)) {
const range = document.createRange();
range.selectNodeContents(aux);
const sel = getSelection();
sel.removeAllRanges();
sel.addRange(range);
aux.setSelectionRange(0, str.length);
} else {
aux.select();
}
const result = document.execCommand('copy');
document.body.removeChild(aux);
return result;
function copyToClipboard(str) {
const aux = document.createElement('input');
aux.setAttribute('value', str);
aux.contentEditable = true;
aux.readOnly = true;
document.body.appendChild(aux);
if (navigator.userAgent.match(/iphone|ipad|ipod/i)) {
const range = document.createRange();
range.selectNodeContents(aux);
const sel = getSelection();
sel.removeAllRanges();
sel.addRange(range);
aux.setSelectionRange(0, str.length);
} else {
aux.select();
}
const result = document.execCommand('copy');
document.body.removeChild(aux);
return result;
}
const LOCALIZE_NUMBERS = !!(
@ -282,6 +287,7 @@ module.exports = {
copyToClipboard,
arrayToB64,
b64ToArray,
loadShim,
isFile,
openLinksInNewTab,
browserName,