|
@@ -1,6 +1,7 @@
|
|
|
import { APP_DOWNLOAD_URL } from "@ente/shared/constants/urls";
|
|
|
import { CustomError } from "@ente/shared/error";
|
|
|
import isElectron from "is-electron";
|
|
|
+import { isPromise } from "@ente/shared/utils";
|
|
|
|
|
|
export function checkConnectivity() {
|
|
|
if (navigator.onLine) {
|
|
@@ -49,12 +50,6 @@ export function webglSupported() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export async function sleep(time: number) {
|
|
|
- await new Promise((resolve) => {
|
|
|
- setTimeout(() => resolve(null), time);
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
export function downloadApp() {
|
|
|
openLink(APP_DOWNLOAD_URL, true);
|
|
|
}
|
|
@@ -71,27 +66,6 @@ export function initiateEmail(email: string) {
|
|
|
a.rel = "noreferrer noopener";
|
|
|
a.click();
|
|
|
}
|
|
|
-export const promiseWithTimeout = async <T>(
|
|
|
- request: Promise<T>,
|
|
|
- timeout: number,
|
|
|
-): Promise<T> => {
|
|
|
- const timeoutRef = { current: null };
|
|
|
- const rejectOnTimeout = new Promise<null>((_, reject) => {
|
|
|
- timeoutRef.current = setTimeout(
|
|
|
- () => reject(Error(CustomError.WAIT_TIME_EXCEEDED)),
|
|
|
- timeout,
|
|
|
- );
|
|
|
- });
|
|
|
- const requestWithTimeOutCancellation = async () => {
|
|
|
- const resp = await request;
|
|
|
- clearTimeout(timeoutRef.current);
|
|
|
- return resp;
|
|
|
- };
|
|
|
- return await Promise.race([
|
|
|
- requestWithTimeOutCancellation(),
|
|
|
- rejectOnTimeout,
|
|
|
- ]);
|
|
|
-};
|
|
|
|
|
|
export const preloadImage = (imgBasePath: string) => {
|
|
|
const srcSet = [];
|
|
@@ -120,14 +94,6 @@ export async function waitAndRun(
|
|
|
await task();
|
|
|
}
|
|
|
|
|
|
-function isPromise(p: any) {
|
|
|
- if (typeof p === "object" && typeof p.then === "function") {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
-}
|
|
|
-
|
|
|
export function isClipboardItemPresent() {
|
|
|
return typeof ClipboardItem !== "undefined";
|
|
|
}
|