Skip to content

armgit / ente

Public Imported from GitHub
0

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

onMainWindowFocus

Manav Rathi3c7277a0b124
diff --git a/desktop/src/main.ts b/desktop/src/main.ts
index 246b6da1bc..764c2be521 100644
--- a/desktop/src/main.ts
+++ b/desktop/src/main.ts
@@ -142,9 +142,10 @@ const deleteLegacyDiskCacheDirIfExists = async () => {
};
const attachEventHandlers = (mainWindow: BrowserWindow) => {
- // Let ipcRenderer know when mainWindow is in the foreground.
+ // Let ipcRenderer know when mainWindow is in the foreground so that it can
+ // in turn inform the renderer process.
mainWindow.on("focus", () =>
- mainWindow.webContents.send("app-in-foreground"),
+ mainWindow.webContents.send("onMainWindowFocus"),
);
};
diff --git a/desktop/src/preload.ts b/desktop/src/preload.ts
index f3e3412e29..5e0ed1b450 100644
--- a/desktop/src/preload.ts
+++ b/desktop/src/preload.ts
@@ -69,9 +69,9 @@ const encryptionKey = (): Promise<string | undefined> =>
const saveEncryptionKey = (encryptionKey: string): Promise<void> =>
ipcRenderer.invoke("saveEncryptionKey", encryptionKey);
-const registerForegroundEventListener = (onForeground: () => void) => {
- ipcRenderer.removeAllListeners("app-in-foreground");
- ipcRenderer.on("app-in-foreground", onForeground);
+const onMainWindowFocus = (cb?: () => void) => {
+ ipcRenderer.removeAllListeners("onMainWindowFocus");
+ if (cb) ipcRenderer.on("onMainWindowFocus", cb);
};
const fsExists = (path: string): Promise<boolean> =>
@@ -307,7 +307,7 @@ contextBridge.exposeInMainWorld("electron", {
clearStores,
encryptionKey,
saveEncryptionKey,
- registerForegroundEventListener,
+ onMainWindowFocus,
// - App update
updateAndRestart,
diff --git a/web/apps/photos/src/pages/gallery/index.tsx b/web/apps/photos/src/pages/gallery/index.tsx
index b772771c49..bdbccedfba 100644
--- a/web/apps/photos/src/pages/gallery/index.tsx
+++ b/web/apps/photos/src/pages/gallery/index.tsx
@@ -363,16 +363,14 @@ export default function Gallery() {
}, SYNC_INTERVAL_IN_MICROSECONDS);
if (electron) {
void clipService.setupOnFileUploadListener();
- electron.registerForegroundEventListener(() => {
- syncWithRemote(false, true);
- });
+ electron.onMainWindowFocus(() => syncWithRemote(false, true));
}
};
main();
return () => {
clearInterval(syncInterval.current);
if (electron) {
- electron.registerForegroundEventListener(() => {});
+ electron.onMainWindowFocus(undefined);
clipService.removeOnFileUploadListener();
}
};
diff --git a/web/packages/next/types/ipc.ts b/web/packages/next/types/ipc.ts
index 5093e25545..f9656ad3e2 100644
--- a/web/packages/next/types/ipc.ts
+++ b/web/packages/next/types/ipc.ts
@@ -85,7 +85,17 @@ export interface Electron {
*/
saveEncryptionKey: (encryptionKey: string) => Promise<void>;
- registerForegroundEventListener: (onForeground: () => void) => void;
+ /**
+ * Set or clear the callback {@link cb} to invoke whenever the app comes
+ * into the foreground. More precisely, the callback gets invoked when the
+ * main window gets focus.
+ *
+ * Note: Setting a callback clears any previous callbacks.
+ *
+ * @param cb The function to call when the main window gets focus. Pass
+ * `undefined` to clear the callback.
+ */
+ onMainWindowFocus: (cb?: () => void) => void;
/**
* A subset of filesystem access APIs.