diff options
author | Vijay A <avijayr@protonmail.com> | 2021-08-15 17:15:09 +0530 |
---|---|---|
committer | Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com> | 2021-08-15 13:54:00 +0000 |
commit | bc76d19c6f5687dd18c96db249e0abe7ad79a673 (patch) | |
tree | d4e977f99be77d723ce93bb3866468d8b63ec038 /src/api/server/LocalApi.ts | |
parent | chore: npm upgrades (diff) | |
download | ferdium-app-bc76d19c6f5687dd18c96db249e0abe7ad79a673.tar.gz ferdium-app-bc76d19c6f5687dd18c96db249e0abe7ad79a673.tar.zst ferdium-app-bc76d19c6f5687dd18c96db249e0abe7ad79a673.zip |
chore: typescript conversion of some minor utilities
Also removed 'targz' unused package from runtime.
Diffstat (limited to 'src/api/server/LocalApi.ts')
-rw-r--r-- | src/api/server/LocalApi.ts | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/api/server/LocalApi.ts b/src/api/server/LocalApi.ts new file mode 100644 index 000000000..71721bb0f --- /dev/null +++ b/src/api/server/LocalApi.ts | |||
@@ -0,0 +1,63 @@ | |||
1 | import { ipcRenderer } from 'electron'; | ||
2 | import { session } from '@electron/remote'; | ||
3 | import du from 'du'; | ||
4 | |||
5 | import { getServicePartitionsDirectory } from '../../helpers/service-helpers'; | ||
6 | |||
7 | const debug = require('debug')('Ferdi:LocalApi'); | ||
8 | |||
9 | export default class LocalApi { | ||
10 | // Settings | ||
11 | getAppSettings(type: any) { | ||
12 | return new Promise(resolve => { | ||
13 | ipcRenderer.once('appSettings', (_event, resp) => { | ||
14 | debug('LocalApi::getAppSettings resolves', resp.type, resp.data); | ||
15 | resolve(resp); | ||
16 | }); | ||
17 | |||
18 | ipcRenderer.send('getAppSettings', type); | ||
19 | }); | ||
20 | } | ||
21 | |||
22 | async updateAppSettings(type: any, data: any) { | ||
23 | debug('LocalApi::updateAppSettings resolves', type, data); | ||
24 | ipcRenderer.send('updateAppSettings', { | ||
25 | type, | ||
26 | data, | ||
27 | }); | ||
28 | } | ||
29 | |||
30 | // Services | ||
31 | async getAppCacheSize() { | ||
32 | const partitionsDir = getServicePartitionsDirectory(); | ||
33 | return new Promise((resolve, reject) => { | ||
34 | du(partitionsDir, (err: Error | null, size?: number | undefined) => { | ||
35 | if (err) reject(err); | ||
36 | |||
37 | debug('LocalApi::getAppCacheSize resolves', size); | ||
38 | resolve(size); | ||
39 | }); | ||
40 | }); | ||
41 | } | ||
42 | |||
43 | async clearCache(serviceId: string | null = null) { | ||
44 | const s = serviceId | ||
45 | ? session.fromPartition(`persist:service-${serviceId}`) | ||
46 | : session.defaultSession; | ||
47 | |||
48 | debug('LocalApi::clearCache resolves', serviceId || 'clearAppCache'); | ||
49 | await s.clearStorageData({ | ||
50 | storages: [ | ||
51 | 'appcache', | ||
52 | 'filesystem', | ||
53 | 'indexdb', | ||
54 | 'shadercache', | ||
55 | 'websql', | ||
56 | 'serviceworkers', | ||
57 | 'cachestorage', | ||
58 | ], | ||
59 | quotas: ['temporary', 'persistent', 'syncable'], | ||
60 | }); | ||
61 | return s.clearCache(); | ||
62 | } | ||
63 | } | ||