aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Vijay Aravamudhan <vraravam@users.noreply.github.com>2021-09-26 11:14:23 +0530
committerLibravatar GitHub <noreply@github.com>2021-09-26 11:14:23 +0530
commit35b31dd0872ed81da7f004138e40b68a4b7e6b51 (patch)
tree6cfcd87ff4f19a1338134977859e3e2d80510084
parentchore: tag the 'recipes' submodule when tagging the main repo - to help ident... (diff)
downloadferdium-app-35b31dd0872ed81da7f004138e40b68a4b7e6b51.tar.gz
ferdium-app-35b31dd0872ed81da7f004138e40b68a4b7e6b51.tar.zst
ferdium-app-35b31dd0872ed81da7f004138e40b68a4b7e6b51.zip
refactor: remove references to 'electron/remote' - part deux (#1987)
m---------recipes0
-rw-r--r--src/api/server/LocalApi.ts13
-rw-r--r--src/electron/ipc-api/index.ts2
-rw-r--r--src/electron/ipc-api/sessionStorage.ts35
-rw-r--r--src/stores/AppStore.js2
-rw-r--r--src/stores/UserStore.js7
-rw-r--r--src/webview/lib/RecipeWebview.js4
-rw-r--r--src/webview/sessionHandler.ts13
8 files changed, 47 insertions, 29 deletions
diff --git a/recipes b/recipes
Subproject a8115f7e952458329a657b49b23573163bc3c80 Subproject 882da387029a0026e4417aae4224bcf8df3ce26
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 @@
1import { ipcRenderer } from 'electron'; 1import { ipcRenderer } from 'electron';
2import { session } from '@electron/remote';
3import du from 'du'; 2import du from 'du';
4 3
5import { getServicePartitionsDirectory } from '../../helpers/service-helpers'; 4import { 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 @@
1import { BrowserWindow, Tray } from 'electron'; 1import { BrowserWindow, Tray } from 'electron';
2import autoUpdate from './autoUpdate'; 2import autoUpdate from './autoUpdate';
3import settings from './settings'; 3import settings from './settings';
4import sessionStorage from './sessionStorage';
4import appIndicator from './appIndicator'; 5import appIndicator from './appIndicator';
5import download from './download'; 6import download from './download';
6import localServer from './localServer'; 7import 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 @@
1import { ipcMain, Session, session } from 'electron';
2
3import { TODOS_PARTITION_ID } from '../../config';
4
5const debug = require('debug')('Ferdi:ipcApi:sessionStorage');
6
7function 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
14export 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';
2import moment from 'moment'; 2import moment from 'moment';
3import jwt from 'jsonwebtoken'; 3import jwt from 'jsonwebtoken';
4import localStorage from 'mobx-localstorage'; 4import localStorage from 'mobx-localstorage';
5import { session } from '@electron/remote'; 5import { ipcRenderer } from 'electron';
6 6
7import { TODOS_PARTITION_ID } from '../config';
7import { isDevMode } from '../environment'; 8import { isDevMode } from '../environment';
8import Store from './lib/Store'; 9import Store from './lib/Store';
9import Request from './lib/Request'; 10import Request from './lib/Request';
10import CachedRequest from './lib/CachedRequest'; 11import CachedRequest from './lib/CachedRequest';
11import { TODOS_PARTITION_ID } from '../config';
12 12
13const debug = require('debug')('Ferdi:UserStore'); 13const 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 @@
1import { getCurrentWebContents } from '@electron/remote';
2
3const debug = require('debug')('Ferdi:Plugin:SessionHandler'); 1const debug = require('debug')('Ferdi:Plugin:SessionHandler');
4 2
5export class SessionHandler { 3export 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 =