Forward
This commit is contained in:
@@ -150,10 +150,13 @@ const registerForEnteLinks = () => app.setAsDefaultProtocolClient("ente");
|
||||
|
||||
/** Sibling of {@link registerForEnteLinks}. */
|
||||
const handleEnteLinks = (mainWindow: BrowserWindow, url: string) => {
|
||||
// Both (a) our deeplink protocol, and (b) the protocol we're using to serve
|
||||
// our bundled web app, are the same ("ente://"), so the URL can directly be
|
||||
// loaded.
|
||||
mainWindow.webContents.loadURL(url);
|
||||
// Both
|
||||
//
|
||||
// - our deeplink protocol, and
|
||||
// - the protocol we're using to serve/ our bundled web app
|
||||
//
|
||||
// use the same scheme ("ente://"), so the URL can directly be forwarded.
|
||||
mainWindow.webContents.send("openURL", url);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -77,6 +77,11 @@ const onMainWindowFocus = (cb?: () => void) => {
|
||||
if (cb) ipcRenderer.on("mainWindowFocus", cb);
|
||||
};
|
||||
|
||||
const onOpenURL = (cb?: (url: string) => void) => {
|
||||
ipcRenderer.removeAllListeners("openURL");
|
||||
if (cb) ipcRenderer.on("openURL", (_, url: string) => cb(url));
|
||||
};
|
||||
|
||||
// - App update
|
||||
|
||||
const onAppUpdateAvailable = (
|
||||
@@ -307,6 +312,7 @@ contextBridge.exposeInMainWorld("electron", {
|
||||
encryptionKey,
|
||||
saveEncryptionKey,
|
||||
onMainWindowFocus,
|
||||
onOpenURL,
|
||||
|
||||
// - App update
|
||||
|
||||
|
||||
@@ -167,6 +167,17 @@ export default function App({ Component, pageProps }: AppProps) {
|
||||
const electron = globalThis.electron;
|
||||
if (!electron) return;
|
||||
|
||||
// Attach various listeners for events sent to us by the Node.js layer.
|
||||
// This is for events that we should listen for always, not just when
|
||||
// the user is logged in.
|
||||
|
||||
const handleOpenURL = (url: string) => {
|
||||
// `url` begins with "ente://", which is also the scheme our desktop
|
||||
// app uses to serve the bundled web app, so it can be directly
|
||||
// opened.
|
||||
window.location.href = url;
|
||||
};
|
||||
|
||||
const showUpdateDialog = (update: AppUpdate) => {
|
||||
if (update.autoUpdatable) {
|
||||
setDialogMessage(getUpdateReadyToInstallMessage(update));
|
||||
@@ -182,9 +193,14 @@ export default function App({ Component, pageProps }: AppProps) {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
electron.onOpenURL(handleOpenURL);
|
||||
electron.onAppUpdateAvailable(showUpdateDialog);
|
||||
|
||||
return () => electron.onAppUpdateAvailable(undefined);
|
||||
return () => {
|
||||
electron.onOpenURL(undefined);
|
||||
electron.onAppUpdateAvailable(undefined);
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -94,6 +94,23 @@ export interface Electron {
|
||||
*/
|
||||
onMainWindowFocus: (cb?: () => void) => void;
|
||||
|
||||
/**
|
||||
* Set or clear the callback {@link cb} to invoke whenever the app gets
|
||||
* asked to open a deeplink. This allows the Node.js layer to ask the
|
||||
* renderer to handle deeplinks and redirect itself to a new location if
|
||||
* needed.
|
||||
*
|
||||
* In particular, this is necessary for handling passkey authentication.
|
||||
* See: [Note: Passkey verification in the desktop app]
|
||||
*
|
||||
* Note: Setting a callback clears any previous callbacks.
|
||||
*
|
||||
* @param cb The function to call when the app gets asked to open a
|
||||
* "ente://" URL. The URL string (a.k.a. "deeplink") we were asked to open
|
||||
* is passed to the function verbatim.
|
||||
*/
|
||||
onOpenURL: (cb?: (url: string) => void) => void;
|
||||
|
||||
// - App update
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user