Fix bug 52644: fixed download screen in ios pwa

This commit is contained in:
Viktor Fomin 2021-10-01 00:23:14 +03:00
parent 24224a7437
commit d9ebd6a61b
3 changed files with 34 additions and 1 deletions

View File

@ -15,7 +15,8 @@
"extends @appserver/browserslist-config-asc"
],
"dependencies": {
"copy-to-clipboard": "^3.3.1"
"copy-to-clipboard": "^3.3.1",
"file-saver": "^2.0.5"
},
"devDependencies": {
"@babel/core": "^7.15.5",

View File

@ -5,6 +5,7 @@ import { combineUrl } from "@appserver/common/utils";
import { FileAction, AppServerConfig } from "@appserver/common/constants";
import toastr from "@appserver/components/toast/toastr";
import config from "../../package.json";
import saveAs from "file-saver";
export default function withContextOptions(WrappedComponent) {
class WithContextOptions extends React.Component {
@ -147,10 +148,36 @@ export default function withContextOptions(WrappedComponent) {
openDocEditor(id, providerKey, tab, urlFormation);
};
isPwa = () => {
return ["fullscreen", "standalone", "minimal-ui"].some(
(displayMode) =>
window.matchMedia("(display-mode: " + displayMode + ")").matches
);
};
onClickDownload = () => {
const { item, downloadAction, t } = this.props;
const { fileExst, contentLength, viewUrl } = item;
const isFile = !!fileExst && contentLength;
if (this.isPwa()) {
const xhr = new XMLHttpRequest();
xhr.open("GET", viewUrl);
xhr.responseType = "blob";
xhr.onload = () => {
saveAs(xhr.response, item.title);
};
xhr.onerror = () => {
console.error("download failed", viewUrl);
};
xhr.send();
return;
}
isFile
? window.open(viewUrl, "_self")
: downloadAction(t("Translations:ArchivingData")).catch((err) =>

View File

@ -8899,6 +8899,11 @@ file-loader@^6.2.0:
loader-utils "^2.0.0"
schema-utils "^3.0.0"
file-saver@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-2.0.5.tgz#d61cfe2ce059f414d899e9dd6d4107ee25670c38"
integrity sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA==
file-selector@^0.2.2:
version "0.2.4"
resolved "https://registry.yarnpkg.com/file-selector/-/file-selector-0.2.4.tgz#7b98286f9dbb9925f420130ea5ed0a69238d4d80"