Electron logout
This commit is contained in:
parent
4eb51061cb
commit
932f26684d
5 changed files with 40 additions and 6 deletions
|
@ -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));
|
||||
};
|
||||
|
|
|
@ -150,3 +150,7 @@ export const watchFindFiles = async (dirPath: string) => {
|
|||
}
|
||||
return paths;
|
||||
};
|
||||
|
||||
export const watchReset = async (watcher: FSWatcher) => {
|
||||
await watcher.close();
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue