From 35b31dd0872ed81da7f004138e40b68a4b7e6b51 Mon Sep 17 00:00:00 2001 From: Vijay Aravamudhan Date: Sun, 26 Sep 2021 11:14:23 +0530 Subject: refactor: remove references to 'electron/remote' - part deux (#1987) --- src/electron/ipc-api/sessionStorage.ts | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/electron/ipc-api/sessionStorage.ts (limited to 'src/electron/ipc-api/sessionStorage.ts') diff --git a/src/electron/ipc-api/sessionStorage.ts b/src/electron/ipc-api/sessionStorage.ts new file mode 100644 index 000000000..3eda568a1 --- /dev/null +++ b/src/electron/ipc-api/sessionStorage.ts @@ -0,0 +1,35 @@ +import { ipcMain, Session, session } from 'electron'; + +import { TODOS_PARTITION_ID } from '../../config'; + +const debug = require('debug')('Ferdi:ipcApi:sessionStorage'); + +function deduceSession(serviceId: string | undefined | null): Session { + if (serviceId) { + return session.fromPartition(serviceId === TODOS_PARTITION_ID ? TODOS_PARTITION_ID : `persist:service-${serviceId}`); + } + return session.defaultSession; +} + +export default async () => { + ipcMain.on('clear-storage-data', (_event, { serviceId, targetsToClear }) => { + try { + const serviceSession = deduceSession(serviceId); + serviceSession.flushStorageData(); + if (targetsToClear) { + debug('Clearing targets:', targetsToClear); + serviceSession.clearStorageData(targetsToClear); + } else { + debug('Clearing all targets'); + serviceSession.clearStorageData(); + } + } catch (error) { + debug(error); + } + }); + + ipcMain.handle('clear-cache', (_event, { serviceId }) => { + const serviceSession = deduceSession(serviceId); + return serviceSession.clearCache(); + }); +}; -- cgit v1.2.3-54-g00ecf