Add protocol

This commit is contained in:
Manav Rathi
2024-06-11 11:33:48 +05:30
parent 4569ae01df
commit 9de5f01727
3 changed files with 32 additions and 12 deletions

View File

@@ -6,6 +6,9 @@ files:
extraFiles:
- from: build
to: resources
protocols:
- name: Ente
schemes: ["ente"]
win:
target:
- target: nsis

View File

@@ -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();

View File

@@ -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;
};
/**