|
@@ -1,65 +1,3 @@
|
|
|
-import { APP_DOWNLOAD_URL } from "@ente/shared/constants/urls";
|
|
|
-import { CustomError } from "@ente/shared/error";
|
|
|
-import { isPromise } from "@ente/shared/utils";
|
|
|
-import isElectron from "is-electron";
|
|
|
-
|
|
|
-export function checkConnectivity() {
|
|
|
- if (navigator.onLine) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- throw new Error(CustomError.NO_INTERNET_CONNECTION);
|
|
|
-}
|
|
|
-
|
|
|
-export function runningInBrowser() {
|
|
|
- return typeof window !== "undefined";
|
|
|
-}
|
|
|
-
|
|
|
-export function runningInWorker() {
|
|
|
- return typeof importScripts === "function";
|
|
|
-}
|
|
|
-
|
|
|
-export function runningInElectron() {
|
|
|
- return isElectron();
|
|
|
-}
|
|
|
-
|
|
|
-export function runningInChrome(includeMobile: boolean) {
|
|
|
- try {
|
|
|
- const userAgentData = navigator["userAgentData"];
|
|
|
- const chromeBrand = userAgentData?.brands?.filter(
|
|
|
- (b) => b.brand === "Google Chrome" || b.brand === "Chromium",
|
|
|
- )?.[0];
|
|
|
- return chromeBrand && (includeMobile || userAgentData.mobile === false);
|
|
|
- } catch (error) {
|
|
|
- console.error("Error in runningInChrome: ", error);
|
|
|
- return false;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-export function offscreenCanvasSupported() {
|
|
|
- return !(typeof OffscreenCanvas === "undefined");
|
|
|
-}
|
|
|
-
|
|
|
-export function webglSupported() {
|
|
|
- try {
|
|
|
- const canvas = document.createElement("canvas");
|
|
|
- const gl = canvas.getContext("webgl");
|
|
|
- return gl && gl instanceof WebGLRenderingContext;
|
|
|
- } catch (error) {
|
|
|
- console.error("Error in webglSupported: ", error);
|
|
|
- return false;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-export function downloadApp() {
|
|
|
- openLink(APP_DOWNLOAD_URL, true);
|
|
|
-}
|
|
|
-
|
|
|
-export function reverseString(title: string) {
|
|
|
- return title
|
|
|
- ?.split(" ")
|
|
|
- .reduce((reversedString, currWord) => `${currWord} ${reversedString}`);
|
|
|
-}
|
|
|
-
|
|
|
export function initiateEmail(email: string) {
|
|
|
const a = document.createElement("a");
|
|
|
a.href = "mailto:" + email;
|
|
@@ -74,6 +12,7 @@ export const preloadImage = (imgBasePath: string) => {
|
|
|
}
|
|
|
new Image().srcset = srcSet.join(",");
|
|
|
};
|
|
|
+
|
|
|
export function openLink(href: string, newTab?: boolean) {
|
|
|
const a = document.createElement("a");
|
|
|
a.href = href;
|
|
@@ -84,16 +23,6 @@ export function openLink(href: string, newTab?: boolean) {
|
|
|
a.click();
|
|
|
}
|
|
|
|
|
|
-export async function waitAndRun(
|
|
|
- waitPromise: Promise<void>,
|
|
|
- task: () => Promise<void>,
|
|
|
-) {
|
|
|
- if (waitPromise && isPromise(waitPromise)) {
|
|
|
- await waitPromise;
|
|
|
- }
|
|
|
- await task();
|
|
|
-}
|
|
|
-
|
|
|
export function isClipboardItemPresent() {
|
|
|
return typeof ClipboardItem !== "undefined";
|
|
|
}
|
|
@@ -105,11 +34,3 @@ export function batch<T>(arr: T[], batchSize: number): T[][] {
|
|
|
}
|
|
|
return batches;
|
|
|
}
|
|
|
-
|
|
|
-export const mergeMaps = <K, V>(map1: Map<K, V>, map2: Map<K, V>) => {
|
|
|
- const mergedMap = new Map<K, V>(map1);
|
|
|
- map2.forEach((value, key) => {
|
|
|
- mergedMap.set(key, value);
|
|
|
- });
|
|
|
- return mergedMap;
|
|
|
-};
|