Check if RAM would be exceeded before using navigator.share()

This commit is contained in:
schlagmichdoch 2024-02-16 15:22:19 +01:00
parent f4a947527d
commit 74bd7dd406

View file

@ -1115,7 +1115,13 @@ class ReceiveFileDialog extends ReceiveDialog {
: `${ Localization.getTranslation("document-titles.file-received-plural", null, {count: this._data.files.length}) } - PairDrop`;
// If possible, share via menu - else download files
const shareViaMenu = this.canShareFilesViaMenu(this._data.files);
let shareViaMenu = this.canShareFilesViaMenu(this._data.files);
if (shareViaMenu && this._filesTooBigForRam()) {
// Files too big to share on iOS -> Download instead
shareViaMenu = false;
Events.fire('notify-user', Localization.getTranslation("notifications.error-sharing-size"));
}
this._parseFileData(
this._data.displayName,
@ -1142,6 +1148,11 @@ class ReceiveFileDialog extends ReceiveDialog {
Events.fire('set-progress', {peerId: this._data.peerId, progress: 0, status: "receive-complete"});
}
_filesTooBigForRam() {
// Pages crash on iOS if RAM exceeds 250 MB
return window.iOS && this._data.totalSize > 250000000;
}
_getDescriptor(files, imagesOnly) {
let descriptor;
if (files.length === 1) {
@ -1246,9 +1257,7 @@ class ReceiveFileDialog extends ReceiveDialog {
let zipName = "";
let sendAsZip = false;
const tooBigToZip = window.iOS && this._data.totalSize > 256000000;
if (this._data.files.length > 1 && !tooBigToZip) {
if (this._data.files.length > 1 && !this._filesTooBigForRam()) {
Events.fire('set-progress', {
peerId: this._data.peerId,
progress: 0,
@ -1373,7 +1382,7 @@ class ReceiveFileDialog extends ReceiveDialog {
let {sendAsZip, zipObjectUrl, zipName} = await this._processDataAsZip();
// If single file or zipping failed -> download files individually -> else download zip
// If single file or zipping failed or file size exceeds memory -> download files individually -> else download zip
if (sendAsZip) {
this._setDownloadButtonToZip(zipObjectUrl, zipName);
} else {