diff options
Diffstat (limited to 'src/electron/ipc-api/sessionStorage.ts')
-rw-r--r-- | src/electron/ipc-api/sessionStorage.ts | 35 |
1 files changed, 35 insertions, 0 deletions
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 @@ | |||
1 | import { ipcMain, Session, session } from 'electron'; | ||
2 | |||
3 | import { TODOS_PARTITION_ID } from '../../config'; | ||
4 | |||
5 | const debug = require('debug')('Ferdi:ipcApi:sessionStorage'); | ||
6 | |||
7 | function deduceSession(serviceId: string | undefined | null): Session { | ||
8 | if (serviceId) { | ||
9 | return session.fromPartition(serviceId === TODOS_PARTITION_ID ? TODOS_PARTITION_ID : `persist:service-${serviceId}`); | ||
10 | } | ||
11 | return session.defaultSession; | ||
12 | } | ||
13 | |||
14 | export default async () => { | ||
15 | ipcMain.on('clear-storage-data', (_event, { serviceId, targetsToClear }) => { | ||
16 | try { | ||
17 | const serviceSession = deduceSession(serviceId); | ||
18 | serviceSession.flushStorageData(); | ||
19 | if (targetsToClear) { | ||
20 | debug('Clearing targets:', targetsToClear); | ||
21 | serviceSession.clearStorageData(targetsToClear); | ||
22 | } else { | ||
23 | debug('Clearing all targets'); | ||
24 | serviceSession.clearStorageData(); | ||
25 | } | ||
26 | } catch (error) { | ||
27 | debug(error); | ||
28 | } | ||
29 | }); | ||
30 | |||
31 | ipcMain.handle('clear-cache', (_event, { serviceId }) => { | ||
32 | const serviceSession = deduceSession(serviceId); | ||
33 | return serviceSession.clearCache(); | ||
34 | }); | ||
35 | }; | ||