fixes #76. 'File received' dialog not showing on iOS when big videos are sent.

This commit is contained in:
schlagmichdoch 2023-03-13 00:04:48 +01:00
parent 1093f4d246
commit 028752a809
2 changed files with 90 additions and 54 deletions

View file

@ -632,6 +632,7 @@ class ReceiveFileDialog extends ReceiveDialog {
createPreviewElement(file) {
return new Promise((resolve, reject) => {
try {
let mime = file.type.split('/')[0]
let previewElement = {
image: 'img',
@ -642,16 +643,23 @@ class ReceiveFileDialog extends ReceiveDialog {
if (Object.keys(previewElement).indexOf(mime) === -1) {
resolve(false);
} else {
console.log('the file is able to preview');
let element = document.createElement(previewElement[mime]);
element.src = URL.createObjectURL(file);
element.controls = true;
element.onload = _ => {
this.$previewBox.appendChild(element);
resolve(true)
resolve(true);
};
element.addEventListener('loadeddata', _ => resolve(true));
element.onerror = _ => reject(`${mime} preview could not be loaded from type ${file.type}`);
element.onloadeddata = _ => {
this.$previewBox.appendChild(element);
resolve(true);
};
element.onerror = _ => {
reject(`${mime} preview could not be loaded from type ${file.type}`);
};
element.src = URL.createObjectURL(file);
}
} catch (e) {
reject(`preview could not be loaded from type ${file.type}`);
}
});
}
@ -734,7 +742,6 @@ class ReceiveFileDialog extends ReceiveDialog {
setTimeout(_ => this.$downloadBtn.style.pointerEvents = "unset", 2000);
};
this.createPreviewElement(files[0]).finally(_ => {
document.title = files.length === 1
? 'File received - PairDrop'
: `${files.length} Files received - PairDrop`;
@ -742,12 +749,23 @@ class ReceiveFileDialog extends ReceiveDialog {
Events.fire('set-progress', {peerId: peerId, progress: 1, status: 'process'})
this.show();
setTimeout(_ => {
if (canShare) {
this.$shareBtn.click();
} else {
this.$downloadBtn.click();
}
}).catch(r => console.error(r));
}, 500);
this.createPreviewElement(files[0])
.then(canPreview => {
if (canPreview) {
console.log('the file is able to preview');
} else {
console.log('the file is not able to preview');
}
})
.catch(r => console.error(r));
}
_downloadFilesIndividually(files) {

View file

@ -633,6 +633,7 @@ class ReceiveFileDialog extends ReceiveDialog {
createPreviewElement(file) {
return new Promise((resolve, reject) => {
try {
let mime = file.type.split('/')[0]
let previewElement = {
image: 'img',
@ -643,16 +644,23 @@ class ReceiveFileDialog extends ReceiveDialog {
if (Object.keys(previewElement).indexOf(mime) === -1) {
resolve(false);
} else {
console.log('the file is able to preview');
let element = document.createElement(previewElement[mime]);
element.src = URL.createObjectURL(file);
element.controls = true;
element.onload = _ => {
this.$previewBox.appendChild(element);
resolve(true)
resolve(true);
};
element.addEventListener('loadeddata', _ => resolve(true));
element.onerror = _ => reject(`${mime} preview could not be loaded from type ${file.type}`);
element.onloadeddata = _ => {
this.$previewBox.appendChild(element);
resolve(true);
};
element.onerror = _ => {
reject(`${mime} preview could not be loaded from type ${file.type}`);
};
element.src = URL.createObjectURL(file);
}
} catch (e) {
reject(`preview could not be loaded from type ${file.type}`);
}
});
}
@ -735,7 +743,6 @@ class ReceiveFileDialog extends ReceiveDialog {
setTimeout(_ => this.$downloadBtn.style.pointerEvents = "unset", 2000);
};
this.createPreviewElement(files[0]).finally(_ => {
document.title = files.length === 1
? 'File received - PairDrop'
: `${files.length} Files received - PairDrop`;
@ -743,12 +750,23 @@ class ReceiveFileDialog extends ReceiveDialog {
Events.fire('set-progress', {peerId: peerId, progress: 1, status: 'process'})
this.show();
setTimeout(_ => {
if (canShare) {
this.$shareBtn.click();
} else {
this.$downloadBtn.click();
}
}).catch(r => console.error(r));
}, 500);
this.createPreviewElement(files[0])
.then(canPreview => {
if (canPreview) {
console.log('the file is able to preview');
} else {
console.log('the file is not able to preview');
}
})
.catch(r => console.error(r));
}
_downloadFilesIndividually(files) {