Skip to content

armgit / ente

Public Imported from GitHub
0

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

isDesktop

Manav Rathi6f073b007b03
diff --git a/web/packages/accounts/services/passkey.ts b/web/packages/accounts/services/passkey.ts
index d507c01c68..c13fe11c7c 100644
--- a/web/packages/accounts/services/passkey.ts
+++ b/web/packages/accounts/services/passkey.ts
@@ -1,7 +1,7 @@
import { clientPackageHeader } from "@/next/http";
import log from "@/next/log";
import { accountsAppOrigin, apiURL } from "@/next/origins";
-import { appName, clientPackageName } from "@/next/types/app";
+import { clientPackageName, isDesktop } from "@/next/types/app";
import { TwoFactorAuthorizationResponse } from "@/next/types/credentials";
import { ensure } from "@/utils/ensure";
import ComlinkCryptoWorker from "@ente/shared/crypto";
@@ -27,13 +27,13 @@ import { getToken } from "@ente/shared/storage/localStorage/helpers";
* verification session.
*/
export const passkeyVerificationRedirectURL = (passkeySessionID: string) => {
- const clientPackage = clientPackageName(appName);
+ const clientPackage = clientPackageName;
// Using `window.location.origin` will work both when we're running in a web
// browser, and in our desktop app. See: [Note: Using deeplinks to navigate
// in desktop app]
const redirect = `${window.location.origin}/passkeys/finish`;
// See: [Note: Conditional passkey recover option on accounts]
- const recoverOption: Record<string, string> = globalThis.electron
+ const recoverOption: Record<string, string> = isDesktop
? {}
: { recover: `${window.location.origin}/passkeys/recover` };
const params = new URLSearchParams({
diff --git a/web/packages/next/types/app.ts b/web/packages/next/types/app.ts
index ff9a211b9e..a66edbc8ef 100644
--- a/web/packages/next/types/app.ts
+++ b/web/packages/next/types/app.ts
@@ -27,6 +27,15 @@ export type AppName = (typeof appNames)[number];
*/
export const appName: AppName = process.env.appName as AppName;
+/**
+ * True if we're running in our desktop app.
+ *
+ * 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).
+ */
+export const isDesktop = process.env.isDesktop == "1";
+
/**
* Static (English) title for the app.
*
@@ -57,7 +66,7 @@ export const clientPackageNamePhotosDesktop = "io.ente.photos.desktop";
* app (currently only photos), this will be the platform specific package name.
*/
export const clientPackageName = (() => {
- if (process.env.isDesktop) {
+ if (isDesktop) {
if (appName != "photos")
throw new Error(`Unsupported desktop appName ${appName}`);
return clientPackageNamePhotosDesktop;