Skip to content

Commit

Permalink
Merge pull request #365 from ONLYOFFICE/bugfix/Bug52644
Browse files Browse the repository at this point in the history
Fix bug 52644: fixed download screen in ios pwa
  • Loading branch information
AlexeySafronov authored Oct 5, 2021
2 parents 46ff967 + 32e63d9 commit 0f59548
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion products/ASC.Files/Client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 27 additions & 0 deletions products/ASC.Files/Client/src/HOCs/withContextOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) =>
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0f59548

Please sign in to comment.