Added persistent storage permissions when uploading maps or tokens

This commit is contained in:
Mitchell McCaffrey 2020-11-27 21:00:08 +11:00
parent 951c515334
commit 926f05f301
3 changed files with 24 additions and 1 deletions

View File

@ -91,6 +91,11 @@ function SelectMapModal({
const [imageLoading, setImageLoading] = useState(false);
async function handleImagesUpload(files) {
if (navigator.storage) {
// Attempt to enable persistant storage
await navigator.storage.persist();
}
for (let file of files) {
await handleImageUpload(file);
}

View File

@ -70,6 +70,11 @@ function SelectTokensModal({ isOpen, onRequestClose }) {
}
async function handleImagesUpload(files) {
if (navigator.storage) {
// Attempt to enable persistant storage
await navigator.storage.persist();
}
for (let file of files) {
await handleImageUpload(file);
}

View File

@ -28,8 +28,21 @@ function SettingsModal({ isOpen, onRequestClose }) {
const [storageEstimate, setStorageEstimate] = useState();
useEffect(() => {
async function estimateStorage() {
// Persisted data on firefox doesn't count towards the usage quota so ignore it
const persisted = await navigator.storage.persisted();
const isFirefox =
navigator.userAgent.toLowerCase().indexOf("firefox") > -1;
if (persisted && isFirefox) {
return;
}
const estimate = await navigator.storage.estimate();
setStorageEstimate(estimate);
}
if (isOpen && navigator.storage) {
navigator.storage.estimate().then(setStorageEstimate);
estimateStorage();
}
}, [isOpen]);