diff options
author | Vijay Aravamudhan <vraravam@users.noreply.github.com> | 2021-09-26 11:14:23 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-26 11:14:23 +0530 |
commit | 35b31dd0872ed81da7f004138e40b68a4b7e6b51 (patch) | |
tree | 6cfcd87ff4f19a1338134977859e3e2d80510084 /src/electron/ipc-api/sessionStorage.ts | |
parent | chore: tag the 'recipes' submodule when tagging the main repo - to help ident... (diff) | |
download | ferdium-app-35b31dd0872ed81da7f004138e40b68a4b7e6b51.tar.gz ferdium-app-35b31dd0872ed81da7f004138e40b68a4b7e6b51.tar.zst ferdium-app-35b31dd0872ed81da7f004138e40b68a4b7e6b51.zip |
refactor: remove references to 'electron/remote' - part deux (#1987)
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 | }; | ||