diff --git a/src/api/filesAPI.ts b/src/api/filesAPI.ts index b9fe76d..c7f725b 100644 --- a/src/api/filesAPI.ts +++ b/src/api/filesAPI.ts @@ -2,6 +2,7 @@ import { QueryFunctionContext } from "react-query"; import axios from "../axiosInterceptor"; import { getUserToken } from "./userAPI"; import getBackendURL from "../utils/getBackendURL"; +import { isPwa } from "../utils/PWAUtils"; interface QueryKeyParams { parent: string; @@ -71,12 +72,17 @@ export const downloadFileAPI = async (fileID: string) => { const url = `${getBackendURL()}/file-service/download/${fileID}`; - const link = document.createElement("a"); - document.body.appendChild(link); - link.href = url; - link.setAttribute("type", "hidden"); - link.setAttribute("download", "true"); - link.click(); + if (!isPwa()) { + const link = document.createElement("a"); + document.body.appendChild(link); + link.href = url; + link.setAttribute("type", "hidden"); + link.setAttribute("download", "true"); + link.click(); + } else { + alert("PWA"); + window.open(url); + } }; export const getVideoTokenAPI = async () => { diff --git a/src/utils/PWAUtils.ts b/src/utils/PWAUtils.ts new file mode 100644 index 0000000..8a736b9 --- /dev/null +++ b/src/utils/PWAUtils.ts @@ -0,0 +1,6 @@ +export const isPwa = () => { + return ["fullscreen", "standalone", "minimal-ui"].some( + (displayMode) => + window.matchMedia("(display-mode: " + displayMode + ")").matches + ); +};