Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add protocol

Manav Rathi9de5f0172719
diff --git a/desktop/electron-builder.yml b/desktop/electron-builder.yml
index 347aabe631..6e3df57656 100644
--- a/desktop/electron-builder.yml
+++ b/desktop/electron-builder.yml
@@ -6,6 +6,9 @@ files:
extraFiles:
- from: build
to: resources
+protocols:
+ - name: Ente
+ schemes: ["ente"]
win:
target:
- target: nsis
diff --git a/desktop/src/main.ts b/desktop/src/main.ts
index afbf4eccd3..c795e938c2 100644
--- a/desktop/src/main.ts
+++ b/desktop/src/main.ts
@@ -137,6 +137,22 @@ const registerPrivilegedSchemes = () => {
]);
};
+/**
+ * Register a handler for deeplinks, for the "ente://" protocol.
+ *
+ * See: [Note: Passkey verification in the desktop app].
+ *
+ * Implementation notes:
+ * - https://www.electronjs.org/docs/latest/tutorial/launch-app-from-url-in-another-app
+ * - This works only when the app is packaged.
+ */
+const handleEnteLinks = () => {
+ app.setAsDefaultProtocolClient("ente");
+ app.on("open-url", (_, url) => {
+ log.info(`open-url: ${url}`);
+ });
+};
+
/**
* Create an return the {@link BrowserWindow} that will form our app's UI.
*
@@ -451,6 +467,7 @@ const main = () => {
initLogging();
logStartupBanner();
+ handleEnteLinks();
// The order of the next two calls is important
setupRendererServer();
registerPrivilegedSchemes();
diff --git a/web/packages/accounts/services/passkey.ts b/web/packages/accounts/services/passkey.ts
index ae455638a0..793464f6b9 100644
--- a/web/packages/accounts/services/passkey.ts
+++ b/web/packages/accounts/services/passkey.ts
@@ -29,13 +29,6 @@ export const redirectUserToPasskeyVerificationFlow = (
passkeySessionID: string,
) => {
const clientPackage = clientPackageName[appName];
- const redirect = `${window.location.origin}/passkeys/finish`;
- const params = new URLSearchParams({
- clientPackage,
- passkeySessionID,
- redirect,
- });
- const url = `${accountsAppURL()}/passkeys/verify?${params.toString()}`;
// [Note: Passkey verification in the desktop app]
//
// Our desktop app bundles the web app and serves it over a custom protocol.
@@ -54,11 +47,18 @@ export const redirectUserToPasskeyVerificationFlow = (
// protocol and provide that as a return path redirect. Passkey
// authentication happens at accounts.ente.io, and on success there is
// redirected back to the desktop app.
- if (globalThis.electron) {
- window.open(url);
- } else {
- window.location.href = url;
- }
+ const redirectOrigin = globalThis.electron
+ ? "ente://"
+ : window.location.origin;
+ const redirect = `${redirectOrigin}/passkeys/finish`;
+ const params = new URLSearchParams({
+ clientPackage,
+ passkeySessionID,
+ redirect,
+ });
+ const url = `${accountsAppURL()}/passkeys/verify?${params.toString()}`;
+ if (globalThis.electron) window.open(url);
+ else window.location.href = url;
};
/**