From 1fd61fcb7266a1794d66ad60318895839d58203e Mon Sep 17 00:00:00 2001 From: Justus Tumacder Date: Thu, 12 Jan 2023 16:49:59 +0800 Subject: [PATCH 1/4] Prevent mobile browsers from sleeping during transfer --- client/package-lock.json | 15 +++++++++++++-- client/package.json | 1 + .../app/components/providers/WormholeProvider.tsx | 11 +++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/client/package-lock.json b/client/package-lock.json index b620c091..4e68d28f 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -1,12 +1,12 @@ { "name": "winden", - "version": "0.5.2-beta", + "version": "0.5.3-beta", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "winden", - "version": "0.5.2-beta", + "version": "0.5.3-beta", "dependencies": { "@emotion/react": "^11.10.4", "@ionic/vue": "^5.4.0", @@ -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/components/providers/WormholeProvider.tsx b/client/src/app/components/providers/WormholeProvider.tsx index edf0effc..a44d016a 100644 --- a/client/src/app/components/providers/WormholeProvider.tsx +++ b/client/src/app/components/providers/WormholeProvider.tsx @@ -1,3 +1,4 @@ +import nosleep from "nosleep.js"; import React, { PropsWithChildren, useEffect, useRef, useState } from "react"; import { useCodeInput } from "../../hooks/useCodeInput"; import { useError } from "../../hooks/useError"; @@ -181,6 +182,16 @@ export default function WormholeProvider(props: Props) { ); }, []); + const noSleep = useRef(new nosleep()); + useEffect(() => { + // Prevent mobile browsers from sleeping during transfer + if (fileMeta && !done) { + noSleep.current.enable(); + } else { + noSleep.current.disable(); + } + }, [fileMeta, done]); + async function sendFile( file: File, opts?: TransferOptions From ce9d78f8461b368811b40ededcd982cb6375aea8 Mon Sep 17 00:00:00 2001 From: Justus Tumacder Date: Mon, 16 Jan 2023 14:26:52 +0800 Subject: [PATCH 2/4] Change NoSleep activation to be tied with user interaction event --- client/src/app/NoSleep.ts | 3 +++ client/src/app/components/Dropzone.tsx | 6 +++++- .../src/app/components/providers/WormholeProvider.tsx | 10 +++------- .../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 + 8 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 client/src/app/NoSleep.ts 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 = (