Skip to content

armgit / ente

Public Imported from GitHub
0

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

Electron logout

Manav Rathi932f26684de0
diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.ts
index 66cfddabd4..f59969202b 100644
--- a/desktop/src/main/ipc.ts
+++ b/desktop/src/main/ipc.ts
@@ -64,6 +64,7 @@ import {
watchFindFiles,
watchGet,
watchRemove,
+ watchReset,
watchUpdateIgnoredFiles,
watchUpdateSyncedFiles,
} from "./services/watch";
@@ -263,4 +264,6 @@ export const attachFSWatchIPCHandlers = (watcher: FSWatcher) => {
ipcMain.handle("watchFindFiles", (_, folderPath: string) =>
watchFindFiles(folderPath),
);
+
+ ipcMain.handle("watchReset", () => watchReset(watcher));
};
diff --git a/desktop/src/main/services/watch.ts b/desktop/src/main/services/watch.ts
index 975d8a7c35..e115239d34 100644
--- a/desktop/src/main/services/watch.ts
+++ b/desktop/src/main/services/watch.ts
@@ -150,3 +150,7 @@ export const watchFindFiles = async (dirPath: string) => {
}
return paths;
};
+
+export const watchReset = async (watcher: FSWatcher) => {
+ await watcher.close();
+};
diff --git a/desktop/src/preload.ts b/desktop/src/preload.ts
index 2b5eb8fcc3..2acd8fbffa 100644
--- a/desktop/src/preload.ts
+++ b/desktop/src/preload.ts
@@ -208,6 +208,13 @@ const watchOnRemoveDir = (f: (path: string, watch: FolderWatch) => void) => {
const watchFindFiles = (folderPath: string) =>
ipcRenderer.invoke("watchFindFiles", folderPath);
+const watchReset = () => {
+ ipcRenderer.removeAllListeners("watchAddFile");
+ ipcRenderer.removeAllListeners("watchRemoveFile");
+ ipcRenderer.removeAllListeners("watchRemoveDir");
+ return ipcRenderer.invoke("watchReset");
+};
+
// - Upload
const pathForFile = (file: File) => webUtils.getPathForFile(file);
@@ -323,12 +330,13 @@ contextBridge.exposeInMainWorld("electron", {
get: watchGet,
add: watchAdd,
remove: watchRemove,
+ updateSyncedFiles: watchUpdateSyncedFiles,
+ updateIgnoredFiles: watchUpdateIgnoredFiles,
onAddFile: watchOnAddFile,
onRemoveFile: watchOnRemoveFile,
onRemoveDir: watchOnRemoveDir,
findFiles: watchFindFiles,
- updateSyncedFiles: watchUpdateSyncedFiles,
- updateIgnoredFiles: watchUpdateIgnoredFiles,
+ reset: watchReset,
},
// - Upload
diff --git a/web/packages/accounts/services/user.ts b/web/packages/accounts/services/user.ts
index fb0e1c9290..8f6d6609a1 100644
--- a/web/packages/accounts/services/user.ts
+++ b/web/packages/accounts/services/user.ts
@@ -40,10 +40,18 @@ export const logoutUser = async () => {
} catch (e) {
log.error("Ignoring error when clearing files", e);
}
- try {
- globalThis.electron?.clearStores();
- } catch (e) {
- log.error("Ignoring error when clearing electron stores", e);
+ const electron = globalThis.electron;
+ if (electron) {
+ try {
+ await electron.watch.reset();
+ } catch (e) {
+ log.error("Ignoring error when resetting native folder watches", e);
+ }
+ try {
+ await electron.clearStores();
+ } catch (e) {
+ log.error("Ignoring error when clearing native stores", e);
+ }
}
try {
eventBus.emit(Events.LOGOUT);
diff --git a/web/packages/next/types/ipc.ts b/web/packages/next/types/ipc.ts
index fb72bcf5ca..4b05838fa1 100644
--- a/web/packages/next/types/ipc.ts
+++ b/web/packages/next/types/ipc.ts
@@ -462,6 +462,17 @@ export interface Electron {
* The returned paths are guaranteed to use POSIX separators ('/').
*/
findFiles: (folderPath: string) => Promise<string[]>;
+
+ /**
+ * Stop watching all existing folder watches and remove any callbacks.
+ *
+ * This function is meant to be called when the user logs out. It stops
+ * all existing folder watches and forgets about any "on*" callback
+ * functions that have been registered.
+ *
+ * The persisted state itself gets cleared via {@link clearStores}.
+ */
+ reset: () => Promise<void>;
};
// - Upload