Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Use same check throughout

Manav Rathibef67b60b399
diff --git a/web/apps/photos/src/components/Export.tsx b/web/apps/photos/src/components/Export.tsx
index 589dd71386..b719165db2 100644
--- a/web/apps/photos/src/components/Export.tsx
+++ b/web/apps/photos/src/components/Export.tsx
@@ -1,3 +1,4 @@
+import { isDesktop } from "@/base/app";
import { EnteSwitch } from "@/base/components/EnteSwitch";
import type { ModalVisibilityProps } from "@/base/components/utils/modal";
import { ensureElectron } from "@/base/electron";
@@ -24,7 +25,6 @@ import {
styled,
} from "@mui/material";
import { t } from "i18next";
-import isElectron from "is-electron";
import { useEffect, useState } from "react";
import { Trans } from "react-i18next";
import exportService, {
@@ -62,7 +62,7 @@ export const Export: React.FC<ExportProps> = ({
// SIDE EFFECTS
// ====================
useEffect(() => {
- if (!isElectron()) {
+ if (!isDesktop) {
return;
}
try {
diff --git a/web/apps/photos/src/components/PhotoViewer/index.tsx b/web/apps/photos/src/components/PhotoViewer/index.tsx
index b0e6f4b6e7..5ccc3b4586 100644
--- a/web/apps/photos/src/components/PhotoViewer/index.tsx
+++ b/web/apps/photos/src/components/PhotoViewer/index.tsx
@@ -37,7 +37,6 @@ import {
} from "@mui/material";
import Notification from "components/Notification";
import { t } from "i18next";
-import isElectron from "is-electron";
import { GalleryContext } from "pages/gallery";
import Photoswipe from "photoswipe";
import PhotoswipeUIDefault from "photoswipe/dist/photoswipe-ui-default";
@@ -365,7 +364,7 @@ function PhotoViewer(props: PhotoViewerProps) {
function updateShowConvertBtn(file: EnteFile) {
const shouldShowConvertBtn =
- isElectron() &&
+ isDesktop &&
(file.metadata.fileType === FileType.video ||
file.metadata.fileType === FileType.livePhoto) &&
!file.isConverted &&
diff --git a/web/apps/photos/src/components/Sidebar/index.tsx b/web/apps/photos/src/components/Sidebar/index.tsx
index 65585b53dc..efbac7fb9b 100644
--- a/web/apps/photos/src/components/Sidebar/index.tsx
+++ b/web/apps/photos/src/components/Sidebar/index.tsx
@@ -74,7 +74,6 @@ import DeleteAccountModal from "components/DeleteAccountModal";
import { WatchFolder } from "components/WatchFolder";
import LinkButton from "components/pages/gallery/LinkButton";
import { t } from "i18next";
-import isElectron from "is-electron";
import { useRouter } from "next/router";
import { GalleryContext } from "pages/gallery";
import React, {
@@ -526,7 +525,7 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {
return (
<>
- {isElectron() && (
+ {isDesktop && (
<EnteMenuItem
onClick={showWatchFolder}
variant="secondary"
@@ -591,7 +590,7 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {
{...twoFactorVisibilityProps}
onRootClose={closeSidebar}
/>
- {isElectron() && (
+ {isDesktop && (
<WatchFolder
open={watchFolderView}
onClose={handleCloseWatchFolder}
diff --git a/web/apps/photos/src/components/Upload/Uploader.tsx b/web/apps/photos/src/components/Upload/Uploader.tsx
index b5fa00e9d5..a34f9a3e1f 100644
--- a/web/apps/photos/src/components/Upload/Uploader.tsx
+++ b/web/apps/photos/src/components/Upload/Uploader.tsx
@@ -1,3 +1,4 @@
+import { isDesktop } from "@/base/app";
import { useModalVisibility } from "@/base/components/utils/modal";
import { basename } from "@/base/file-name";
import log from "@/base/log";
@@ -22,7 +23,6 @@ import { CustomError } from "@ente/shared/error";
import DiscFullIcon from "@mui/icons-material/DiscFull";
import InfoOutlined from "@mui/icons-material/InfoRounded";
import { t } from "i18next";
-import isElectron from "is-electron";
import { GalleryContext } from "pages/gallery";
import { useContext, useEffect, useRef, useState } from "react";
import { Trans } from "react-i18next";
@@ -611,7 +611,7 @@ export default function Uploader({
uploaderName,
);
if (!wereFilesProcessed) closeUploadProgress();
- if (isElectron()) {
+ if (isDesktop) {
if (watcher.isUploadRunning()) {
await watcher.allFileUploadsDone(
uploadItemsWithCollection,
@@ -878,7 +878,7 @@ function getImportSuggestion(
uploadType: PICKED_UPLOAD_TYPE,
paths: string[],
): ImportSuggestion {
- if (isElectron() && uploadType === PICKED_UPLOAD_TYPE.FILES) {
+ if (isDesktop && uploadType === PICKED_UPLOAD_TYPE.FILES) {
return DEFAULT_IMPORT_SUGGESTION;
}
diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsx
index 640f0fa5b1..da95719921 100644
--- a/web/apps/photos/src/pages/_app.tsx
+++ b/web/apps/photos/src/pages/_app.tsx
@@ -1,4 +1,4 @@
-import { clientPackageName, staticAppTitle } from "@/base/app";
+import { clientPackageName, isDesktop, staticAppTitle } from "@/base/app";
import { CustomHead } from "@/base/components/Head";
import { AttributedMiniDialog } from "@/base/components/MiniDialog";
import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";
@@ -43,7 +43,6 @@ import { CssBaseline } from "@mui/material";
import { ThemeProvider } from "@mui/material/styles";
import Notification from "components/Notification";
import { t } from "i18next";
-import isElectron from "is-electron";
import type { AppProps } from "next/app";
import { useRouter } from "next/router";
import "photoswipe/dist/photoswipe.css";
@@ -128,7 +127,7 @@ export default function App({ Component, pageProps }: AppProps) {
}, []);
useEffect(() => {
- if (!isElectron()) {
+ if (!isDesktop) {
return;
}
const initExport = async () => {
diff --git a/web/apps/photos/src/services/upload/uploadManager.ts b/web/apps/photos/src/services/upload/uploadManager.ts
index 20d8435ed1..fb0956646d 100644
--- a/web/apps/photos/src/services/upload/uploadManager.ts
+++ b/web/apps/photos/src/services/upload/uploadManager.ts
@@ -1,3 +1,4 @@
+import { isDesktop } from "@/base/app";
import { createComlinkCryptoWorker } from "@/base/crypto";
import { type CryptoWorker } from "@/base/crypto/worker";
import { lowercaseExtension, nameAndExtension } from "@/base/file-name";
@@ -21,7 +22,6 @@ import {
import { wait } from "@/utils/promise";
import { CustomError } from "@ente/shared/error";
import { Canceler } from "axios";
-import isElectron from "is-electron";
import {
getLocalPublicFiles,
getPublicCollectionUID,
@@ -669,7 +669,7 @@ class UploadManager {
fileWithCollection: ClusteredUploadItem,
uploadedFile: EncryptedEnteFile,
) {
- if (isElectron()) {
+ if (isDesktop) {
if (watcher.isUploadRunning()) {
await watcher.onFileUpload(
fileUploadResult,
diff --git a/web/packages/base/app.ts b/web/packages/base/app.ts
index 3547357ddc..74b891a9c0 100644
--- a/web/packages/base/app.ts
+++ b/web/packages/base/app.ts
@@ -31,6 +31,12 @@ export const appName: AppName = process.env.appName as AppName;
* This is similar to checking for `globalThis.electron`, however the advantage
* of this check is that it will also work inside web workers (whose globalThis
* won't have an electron object defined).
+ *
+ * This check can still have false positives during dev mode if someone connects
+ * their browser to port where the desktop app's web app is being served from in
+ * dev mode. If in the future some code needs to definitely rule out those false
+ * positives, it'd need a runtime check of the form
+ * `navigator.userAgent.includes("Electron")`.
*/
export const isDesktop = process.env.isDesktop == "1";
diff --git a/web/packages/base/blob-cache.ts b/web/packages/base/blob-cache.ts
index 49a1fb91e7..0216ede4e4 100644
--- a/web/packages/base/blob-cache.ts
+++ b/web/packages/base/blob-cache.ts
@@ -1,4 +1,4 @@
-import isElectron from "is-electron";
+import { isDesktop } from "./app";
const blobCacheNames = [
"thumbs",
@@ -100,7 +100,7 @@ export const blobCache = async (
export const openBlobCache = async (
name: BlobCacheNamespace,
): Promise<BlobCache> =>
- isElectron() ? openOPFSCacheWeb(name) : openWebCache(name);
+ isDesktop ? openOPFSCacheWeb(name) : openWebCache(name);
/**
* [Note: ArrayBuffer vs Blob vs Uint8Array]
@@ -234,7 +234,7 @@ const openOPFSCacheWeb = async (name: BlobCacheNamespace) => {
*/
export const clearBlobCaches = async () => {
cachedCaches.clear();
- return isElectron() ? clearOPFSCaches() : clearWebCaches();
+ return isDesktop ? clearOPFSCaches() : clearWebCaches();
};
const clearWebCaches = () =>
diff --git a/web/packages/base/package.json b/web/packages/base/package.json
index 10d8ac452d..7d43fb6640 100644
--- a/web/packages/base/package.json
+++ b/web/packages/base/package.json
@@ -12,7 +12,6 @@
"i18next": "^23.16.6",
"i18next-resources-to-backend": "^1.2.1",
"idb": "^8.0.0",
- "is-electron": "^2.2.2",
"libsodium-wrappers-sumo": "^0.7.15",
"nanoid": "^5.0.8",
"next": "^14.2.9",
diff --git a/web/packages/new/photos/services/user-details.ts b/web/packages/new/photos/services/user-details.ts
index 29716d1b03..bff64742aa 100644
--- a/web/packages/new/photos/services/user-details.ts
+++ b/web/packages/new/photos/services/user-details.ts
@@ -1,3 +1,4 @@
+import { isDesktop } from "@/base/app";
import { authenticatedRequestHeaders, ensureOk } from "@/base/http";
import { getKV, setKV } from "@/base/kv";
import { apiURL, familyAppOrigin, paymentsAppOrigin } from "@/base/origins";
@@ -7,7 +8,6 @@ import {
nullToUndefined,
} from "@/utils/transform";
import { getData, LS_KEYS, setLSUser } from "@ente/shared/storage/localStorage";
-import isElectron from "is-electron";
import { z } from "zod";
/**
@@ -389,7 +389,7 @@ export const redirectToPaymentsApp = async (
* of the flow.
*/
const paymentCompletionRedirectURL = () =>
- isElectron()
+ isDesktop
? `${paymentsAppOrigin()}/desktop-redirect`
: `${window.location.origin}/gallery`;
diff --git a/web/yarn.lock b/web/yarn.lock
index fe0a018809..37ce68211b 100644
--- a/web/yarn.lock
+++ b/web/yarn.lock
@@ -2457,11 +2457,6 @@ is-date-object@^1.0.1, is-date-object@^1.0.5:
dependencies:
has-tostringtag "^1.0.0"
-is-electron@^2.2.2:
- version "2.2.2"
- resolved "https://registry.yarnpkg.com/is-electron/-/is-electron-2.2.2.tgz#3778902a2044d76de98036f5dc58089ac4d80bb9"
- integrity sha512-FO/Rhvz5tuw4MCWkpMzHFKWD2LsfHzIb7i6MdPYZ/KW7AlxawyLkqdy+jPZP1WubqEADE3O4FUENlJHDfQASRg==
-
is-extglob@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2"