diff options
author | 2021-09-26 11:14:23 +0530 | |
---|---|---|
committer | 2021-09-26 11:14:23 +0530 | |
commit | 35b31dd0872ed81da7f004138e40b68a4b7e6b51 (patch) | |
tree | 6cfcd87ff4f19a1338134977859e3e2d80510084 /src | |
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')
-rw-r--r-- | src/api/server/LocalApi.ts | 13 | ||||
-rw-r--r-- | src/electron/ipc-api/index.ts | 2 | ||||
-rw-r--r-- | src/electron/ipc-api/sessionStorage.ts | 35 | ||||
-rw-r--r-- | src/stores/AppStore.js | 2 | ||||
-rw-r--r-- | src/stores/UserStore.js | 7 | ||||
-rw-r--r-- | src/webview/lib/RecipeWebview.js | 4 | ||||
-rw-r--r-- | src/webview/sessionHandler.ts | 13 |
7 files changed, 47 insertions, 29 deletions
diff --git a/src/api/server/LocalApi.ts b/src/api/server/LocalApi.ts index 9a6ab2a82..cc7822e78 100644 --- a/src/api/server/LocalApi.ts +++ b/src/api/server/LocalApi.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import { session } from '@electron/remote'; | ||
3 | import du from 'du'; | 2 | import du from 'du'; |
4 | 3 | ||
5 | import { getServicePartitionsDirectory } from '../../helpers/service-helpers'; | 4 | import { getServicePartitionsDirectory } from '../../helpers/service-helpers'; |
@@ -41,12 +40,7 @@ export default class LocalApi { | |||
41 | } | 40 | } |
42 | 41 | ||
43 | async clearCache(serviceId: string | null = null) { | 42 | async clearCache(serviceId: string | null = null) { |
44 | const s = serviceId | 43 | const targetsToClear = { |
45 | ? session.fromPartition(`persist:service-${serviceId}`) | ||
46 | : session.defaultSession; | ||
47 | |||
48 | debug('LocalApi::clearCache resolves', serviceId || 'clearAppCache'); | ||
49 | await s.clearStorageData({ | ||
50 | storages: [ | 44 | storages: [ |
51 | 'appcache', | 45 | 'appcache', |
52 | 'filesystem', | 46 | 'filesystem', |
@@ -57,7 +51,8 @@ export default class LocalApi { | |||
57 | 'cachestorage', | 51 | 'cachestorage', |
58 | ], | 52 | ], |
59 | quotas: ['temporary', 'persistent', 'syncable'], | 53 | quotas: ['temporary', 'persistent', 'syncable'], |
60 | }); | 54 | }; |
61 | return s.clearCache(); | 55 | ipcRenderer.send('clear-storage-data', { serviceId, targetsToClear }); |
56 | return ipcRenderer.invoke('clear-cache', { serviceId }); | ||
62 | } | 57 | } |
63 | } | 58 | } |
diff --git a/src/electron/ipc-api/index.ts b/src/electron/ipc-api/index.ts index 06c50be10..f03f61517 100644 --- a/src/electron/ipc-api/index.ts +++ b/src/electron/ipc-api/index.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { BrowserWindow, Tray } from 'electron'; | 1 | import { BrowserWindow, Tray } from 'electron'; |
2 | import autoUpdate from './autoUpdate'; | 2 | import autoUpdate from './autoUpdate'; |
3 | import settings from './settings'; | 3 | import settings from './settings'; |
4 | import sessionStorage from './sessionStorage'; | ||
4 | import appIndicator from './appIndicator'; | 5 | import appIndicator from './appIndicator'; |
5 | import download from './download'; | 6 | import download from './download'; |
6 | import localServer from './localServer'; | 7 | import localServer from './localServer'; |
@@ -14,6 +15,7 @@ export default (params: { | |||
14 | tray: Tray; | 15 | tray: Tray; |
15 | }) => { | 16 | }) => { |
16 | settings(params); | 17 | settings(params); |
18 | sessionStorage(); | ||
17 | autoUpdate(params); | 19 | autoUpdate(params); |
18 | appIndicator(params); | 20 | appIndicator(params); |
19 | download(params); | 21 | download(params); |
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 | }; | ||
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 85f74a91e..cb17447c0 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js | |||
@@ -258,7 +258,7 @@ export default class AppStore extends Store { | |||
258 | body: 'Have a wonderful day & happy messaging.', | 258 | body: 'Have a wonderful day & happy messaging.', |
259 | }); | 259 | }); |
260 | 260 | ||
261 | localStorage.setItem(CATALINA_NOTIFICATION_HACK_KEY, true); | 261 | localStorage.setItem(CATALINA_NOTIFICATION_HACK_KEY, 'true'); |
262 | } | 262 | } |
263 | } | 263 | } |
264 | 264 | ||
diff --git a/src/stores/UserStore.js b/src/stores/UserStore.js index e3d57c662..77dd28d7c 100644 --- a/src/stores/UserStore.js +++ b/src/stores/UserStore.js | |||
@@ -2,13 +2,13 @@ import { observable, computed, action } from 'mobx'; | |||
2 | import moment from 'moment'; | 2 | import moment from 'moment'; |
3 | import jwt from 'jsonwebtoken'; | 3 | import jwt from 'jsonwebtoken'; |
4 | import localStorage from 'mobx-localstorage'; | 4 | import localStorage from 'mobx-localstorage'; |
5 | import { session } from '@electron/remote'; | 5 | import { ipcRenderer } from 'electron'; |
6 | 6 | ||
7 | import { TODOS_PARTITION_ID } from '../config'; | ||
7 | import { isDevMode } from '../environment'; | 8 | import { isDevMode } from '../environment'; |
8 | import Store from './lib/Store'; | 9 | import Store from './lib/Store'; |
9 | import Request from './lib/Request'; | 10 | import Request from './lib/Request'; |
10 | import CachedRequest from './lib/CachedRequest'; | 11 | import CachedRequest from './lib/CachedRequest'; |
11 | import { TODOS_PARTITION_ID } from '../config'; | ||
12 | 12 | ||
13 | const debug = require('debug')('Ferdi:UserStore'); | 13 | const debug = require('debug')('Ferdi:UserStore'); |
14 | 14 | ||
@@ -256,8 +256,7 @@ export default class UserStore extends Store { | |||
256 | this.stores.services.allServicesRequest.invalidate().reset(); | 256 | this.stores.services.allServicesRequest.invalidate().reset(); |
257 | 257 | ||
258 | if (this.stores.todos.isTodosEnabled) { | 258 | if (this.stores.todos.isTodosEnabled) { |
259 | const sess = session.fromPartition(TODOS_PARTITION_ID); | 259 | ipcRenderer.send('clear-storage-data', { sessionId: TODOS_PARTITION_ID }); |
260 | sess.clearStorageData(); | ||
261 | } | 260 | } |
262 | } | 261 | } |
263 | 262 | ||
diff --git a/src/webview/lib/RecipeWebview.js b/src/webview/lib/RecipeWebview.js index 9c195a9f0..b2a9f3ee8 100644 --- a/src/webview/lib/RecipeWebview.js +++ b/src/webview/lib/RecipeWebview.js | |||
@@ -126,8 +126,8 @@ class RecipeWebview { | |||
126 | } | 126 | } |
127 | } | 127 | } |
128 | 128 | ||
129 | clearStorageData(storageLocations) { | 129 | clearStorageData(serviceId, targetsToClear) { |
130 | this.sessionHandler.clearStorageData(storageLocations); | 130 | ipcRenderer.send('clear-storage-data', { serviceId, targetsToClear }); |
131 | } | 131 | } |
132 | 132 | ||
133 | releaseServiceWorkers() { | 133 | releaseServiceWorkers() { |
diff --git a/src/webview/sessionHandler.ts b/src/webview/sessionHandler.ts index 4961da12b..0c6d23f23 100644 --- a/src/webview/sessionHandler.ts +++ b/src/webview/sessionHandler.ts | |||
@@ -1,19 +1,6 @@ | |||
1 | import { getCurrentWebContents } from '@electron/remote'; | ||
2 | |||
3 | const debug = require('debug')('Ferdi:Plugin:SessionHandler'); | 1 | const debug = require('debug')('Ferdi:Plugin:SessionHandler'); |
4 | 2 | ||
5 | export class SessionHandler { | 3 | export class SessionHandler { |
6 | clearStorageData(storageLocations: string[]) { | ||
7 | try { | ||
8 | debug('Clearing storageLocations:', storageLocations); | ||
9 | const { session } = getCurrentWebContents(); | ||
10 | session.flushStorageData(); | ||
11 | session.clearStorageData({ storages: storageLocations }); | ||
12 | } catch (error) { | ||
13 | debug(error); | ||
14 | } | ||
15 | } | ||
16 | |||
17 | async releaseServiceWorkers() { | 4 | async releaseServiceWorkers() { |
18 | try { | 5 | try { |
19 | const registrations = | 6 | const registrations = |