From 9bce5dc4db0822d2038761443fdd72369bee06c0 Mon Sep 17 00:00:00 2001 From: Justus Tumacder Date: Thu, 19 Jan 2023 15:20:25 +0800 Subject: [PATCH] Prevent mobile browsers from sleeping during transfer (#125) We use nosleep.js to provide sleep prevention by playing a video offscreen. Its activation is tied with user interaction events to work around browsers that block autoplay. --- client/package-lock.json | 11 +++++++++++ client/package.json | 1 + client/src/app/NoSleep.ts | 3 +++ client/src/app/components/Dropzone.tsx | 6 +++++- .../src/app/components/providers/WormholeProvider.tsx | 7 +++++++ .../components/screens/receive/ReceiveBeginScreen.tsx | 10 +++++++++- .../screens/receive/ReceiveConsentScreen.tsx | 2 ++ .../app/components/screens/send/SendBeginScreen.tsx | 5 +++++ client/src/app/index.development.tsx | 1 + client/src/app/index.production.tsx | 1 + 10 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 client/src/app/NoSleep.ts diff --git a/client/package-lock.json b/client/package-lock.json index 9b01a8bf..4e68d28f 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -18,6 +18,7 @@ "bowser": "^2.11.0", "classnames": "^2.3.1", "fastest-levenshtein": "^1.0.12", + "nosleep.js": "^0.12.0", "react": "^18.0.0", "react-dom": "^18.0.0", "react-dropzone": "^14.2.1", @@ -21337,6 +21338,11 @@ "node": ">=0.10.0" } }, + "node_modules/nosleep.js": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/nosleep.js/-/nosleep.js-0.12.0.tgz", + "integrity": "sha512-9d1HbpKLh3sdWlhXMhU6MMH+wQzKkrgfRkYV0EBdvt99YJfj0ilCJrWRDYG2130Tm4GXbEoTCx5b34JSaP+HhA==" + }, "node_modules/now-and-later": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/now-and-later/-/now-and-later-2.0.1.tgz", @@ -44076,6 +44082,11 @@ "integrity": "sha512-bdok/XvKII3nUpklnV6P2hxtMNrCboOjAcyBuQnWEhO665FwrSNRxU+AqpsyvO6LgGYPspN+lu5CLtw4jPRKNA==", "dev": true }, + "nosleep.js": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/nosleep.js/-/nosleep.js-0.12.0.tgz", + "integrity": "sha512-9d1HbpKLh3sdWlhXMhU6MMH+wQzKkrgfRkYV0EBdvt99YJfj0ilCJrWRDYG2130Tm4GXbEoTCx5b34JSaP+HhA==" + }, "now-and-later": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/now-and-later/-/now-and-later-2.0.1.tgz", diff --git a/client/package.json b/client/package.json index ee4dc300..4d274ed2 100644 --- a/client/package.json +++ b/client/package.json @@ -20,6 +20,7 @@ "bowser": "^2.11.0", "classnames": "^2.3.1", "fastest-levenshtein": "^1.0.12", + "nosleep.js": "^0.12.0", "react": "^18.0.0", "react-dom": "^18.0.0", "react-dropzone": "^14.2.1", diff --git a/client/src/app/NoSleep.ts b/client/src/app/NoSleep.ts new file mode 100644 index 00000000..64ec2f34 --- /dev/null +++ b/client/src/app/NoSleep.ts @@ -0,0 +1,3 @@ +import nosleep from "nosleep.js"; + +export const NoSleep = new nosleep(); diff --git a/client/src/app/components/Dropzone.tsx b/client/src/app/components/Dropzone.tsx index f2a3cf9a..1e510395 100644 --- a/client/src/app/components/Dropzone.tsx +++ b/client/src/app/components/Dropzone.tsx @@ -13,6 +13,7 @@ import classNames from "classnames"; import React from "react"; import { FileRejection, useDropzone } from "react-dropzone"; import { Plus } from "tabler-icons-react"; +import { NoSleep } from "../NoSleep"; import Link from "./Link"; const useStyles = createStyles((theme) => ({ @@ -96,7 +97,10 @@ export default function Dropzone(props: Props) { const button = (