π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Cannot be a compile time constant
Manav Rathi01e6e7981965
diff --git a/web/apps/photos/src/components/PhotoViewer/FileInfo/MapBox.tsx b/web/apps/photos/src/components/PhotoViewer/FileInfo/MapBox.tsxindex 368c3787b6..c4d552fbc9 100644--- a/web/apps/photos/src/components/PhotoViewer/FileInfo/MapBox.tsx+++ b/web/apps/photos/src/components/PhotoViewer/FileInfo/MapBox.tsx@@ -6,8 +6,10 @@ import { MapButton } from "./MapButton";import { t } from "i18next";import "leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.webpack.css"; // Re-uses images from ~leaflet packageimport "leaflet/dist/leaflet.css";-haveWindow && require("leaflet-defaulticon-compatibility");-const L = haveWindow ? (require("leaflet") as typeof import("leaflet")) : null;+haveWindow() && require("leaflet-defaulticon-compatibility");+const L = haveWindow()+ ? (require("leaflet") as typeof import("leaflet"))+ : null;const LAYER_TILE_URL = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";const LAYER_TILE_ATTRIBUTION =diff --git a/web/apps/photos/src/services/machineLearning/machineLearningFactory.ts b/web/apps/photos/src/services/machineLearning/machineLearningFactory.tsindex 9e7cac60c6..b93474cb3b 100644--- a/web/apps/photos/src/services/machineLearning/machineLearningFactory.ts+++ b/web/apps/photos/src/services/machineLearning/machineLearningFactory.ts@@ -234,4 +234,4 @@ export class LocalMLSyncContext implements MLSyncContext {}export const getConcurrency = () =>- haveWindow && Math.max(2, Math.ceil(navigator.hardwareConcurrency / 2));+ haveWindow() && Math.max(2, Math.ceil(navigator.hardwareConcurrency / 2));diff --git a/web/apps/photos/src/utils/comlink/ComlinkConvertWorker.ts b/web/apps/photos/src/utils/comlink/ComlinkConvertWorker.tsindex c9cd9aef43..7136fbd62e 100644--- a/web/apps/photos/src/utils/comlink/ComlinkConvertWorker.ts+++ b/web/apps/photos/src/utils/comlink/ComlinkConvertWorker.ts@@ -16,7 +16,7 @@ class ComlinkConvertWorker {}export const getDedicatedConvertWorker = () => {- if (haveWindow) {+ if (haveWindow()) {const cryptoComlinkWorker = new ComlinkWorker<typeof DedicatedConvertWorker>(diff --git a/web/apps/photos/src/utils/comlink/ComlinkMLWorker.ts b/web/apps/photos/src/utils/comlink/ComlinkMLWorker.tsindex 83dfaf2861..f75c0f866a 100644--- a/web/apps/photos/src/utils/comlink/ComlinkMLWorker.ts+++ b/web/apps/photos/src/utils/comlink/ComlinkMLWorker.ts@@ -3,7 +3,7 @@ import { ComlinkWorker } from "@ente/shared/worker/comlinkWorker";import { DedicatedMLWorker } from "worker/ml.worker";export const getDedicatedMLWorker = (name: string) => {- if (haveWindow) {+ if (haveWindow()) {const cryptoComlinkWorker = new ComlinkWorker<typeof DedicatedMLWorker>(name ?? "ente-ml-worker",new Worker(new URL("worker/ml.worker.ts", import.meta.url)),diff --git a/web/apps/photos/src/utils/comlink/ComlinkSearchWorker.ts b/web/apps/photos/src/utils/comlink/ComlinkSearchWorker.tsindex f948440b03..b4ec05490f 100644--- a/web/apps/photos/src/utils/comlink/ComlinkSearchWorker.ts+++ b/web/apps/photos/src/utils/comlink/ComlinkSearchWorker.ts@@ -16,7 +16,7 @@ class ComlinkSearchWorker {}export const getDedicatedSearchWorker = () => {- if (haveWindow) {+ if (haveWindow()) {const cryptoComlinkWorker = new ComlinkWorker<typeof DedicatedSearchWorker>(diff --git a/web/apps/photos/src/utils/storage/mlIDbStorage.ts b/web/apps/photos/src/utils/storage/mlIDbStorage.tsindex 7dca2a68e5..f323603b0a 100644--- a/web/apps/photos/src/utils/storage/mlIDbStorage.ts+++ b/web/apps/photos/src/utils/storage/mlIDbStorage.ts@@ -1,4 +1,5 @@-import { haveWindow, inElectron } from "@/next/env";+import { haveWindow } from "@/next/env";+import isElectron from "is-electron";import { addLogLine } from "@ente/shared/logging";import { logError } from "@ente/shared/sentry";import {@@ -64,7 +65,7 @@ class MLIDbStorage {public _db: Promise<IDBPDatabase<MLDb>>;constructor() {- if (!haveWindow || !inElectron) {+ if (!haveWindow() || !isElectron()) {return;}diff --git a/web/packages/next/env.ts b/web/packages/next/env.tsindex 27cea6f161..ea145d892d 100644--- a/web/packages/next/env.ts+++ b/web/packages/next/env.ts@@ -1,5 +1,3 @@-import isElectron from "is-electron";-/*** A build is considered as a development build if either the NODE_ENV is* environment variable is set to 'development'.@@ -23,17 +21,17 @@ export const isDevBuild = process.env.NODE_ENV === "development";** > We can be running in a browser context either if the user has the page open* in a web browser, or if we're the renderer process of an Electron app.+ *+ * Note that this cannot be a constant, otherwise it'll get inlined during SSR+ * with the wrong value.*/-export const haveWindow = typeof window !== "undefined";+export const haveWindow = () => typeof window !== "undefined";/*** Return true if we are running in a [Web* Worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API)+ *+ * Note that this cannot be a constant, otherwise it'll get inlined during SSR+ * with the wrong value.*/-export const inWorker = typeof importScripts === "function";--/**- * Return true if we're running in an Electron app (either main or renderer- * process).- */-export const inElectron = isElectron();+export const inWorker = () => typeof importScripts === "function";diff --git a/web/packages/shared/electron/service.ts b/web/packages/shared/electron/service.tsindex b4f906c0c5..f926d20b2d 100644--- a/web/packages/shared/electron/service.ts+++ b/web/packages/shared/electron/service.ts@@ -17,7 +17,7 @@ class WorkerSafeElectronServiceImpl implements LimitedElectronAPIs {this.ready = this.init();}private async init() {- if (inWorker) {+ if (inWorker()) {const workerSafeElectronClient =wrap<typeof WorkerSafeElectronClient>(self);diff --git a/web/packages/shared/storage/localForage/index.ts b/web/packages/shared/storage/localForage/index.tsindex 81bbea6106..a3bb4442d0 100644--- a/web/packages/shared/storage/localForage/index.ts+++ b/web/packages/shared/storage/localForage/index.ts@@ -2,7 +2,7 @@ import { haveWindow } from "@/next/env";import localForage from "localforage";-if (haveWindow) {+if (haveWindow()) {localForage.config({name: "ente-files",version: 1.0,