Skip to content

Commit 06e6d65

Browse files
committed
feat(Service): Add method to clear cache
1 parent fe69274 commit 06e6d65

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

src/electron/ipc-api/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import focusState from './focusState';
99
import serviceWebView from '../../features/serviceWebview/ipc';
1010
import fullscreenStatus from './fullscreen';
1111
import subscriptionWindow from './subscriptionWindow';
12+
import serviceCache from './serviceCache';
1213

1314
export default (params) => {
1415
settings(params);
@@ -22,4 +23,5 @@ export default (params) => {
2223
serviceWebView(params);
2324
fullscreenStatus(params);
2425
subscriptionWindow(params);
26+
serviceCache();
2527
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ipcMain } from 'electron';
2+
3+
const debug = require('debug')('Franz:ipcApi:serviceCache');
4+
5+
export default () => {
6+
ipcMain.handle('clearServiceCache', ({ sender: webContents }) => {
7+
debug('Clearing cache for service');
8+
const { session } = webContents;
9+
10+
session.flushStorageData();
11+
session.clearStorageData({
12+
storages: ['appcache', 'serviceworkers', 'cachestorage', 'websql', 'indexdb'],
13+
});
14+
});
15+
};

src/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,29 @@ ipcMain.on('modifyRequestHeaders', (e, { modifiedRequestHeaders, serviceId }) =>
418418
});
419419
});
420420

421+
ipcMain.on('cleanServiceCache', (e, { modifiedRequestHeaders, serviceId }) => {
422+
debug('Received modifyRequestHeaders', modifiedRequestHeaders, serviceId);
423+
modifiedRequestHeaders.forEach((headerFilterSet) => {
424+
const { headers, requestFilters } = headerFilterSet;
425+
session.fromPartition(`persist:service-${serviceId}`).webRequest.onBeforeSendHeaders(requestFilters, (details, callback) => {
426+
for (const key in headers) {
427+
if (Object.prototype.hasOwnProperty.call(headers, key)) {
428+
const value = headers[key];
429+
if (value === 'RefererHost') {
430+
if (Object.prototype.hasOwnProperty.call(details.requestHeaders, 'Referer')) {
431+
const { hostname } = new URL(details.requestHeaders.Referer);
432+
details.requestHeaders[key] = `https://${hostname}`;
433+
}
434+
} else {
435+
details.requestHeaders[key] = value;
436+
}
437+
}
438+
}
439+
callback({ requestHeaders: details.requestHeaders });
440+
});
441+
});
442+
});
443+
421444
ipcMain.on('feature-basic-auth-cancel', () => {
422445
debug('Cancel basic auth');
423446

src/webview/lib/RecipeWebview.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class RecipeWebview {
1919
// communicating with the client
2020
ipcRenderer.sendToHost('alive');
2121
});
22+
23+
window.FranzAPI = {
24+
clearCache: RecipeWebview.clearCache,
25+
};
2226
}
2327

2428
loopFunc = () => null;
@@ -76,6 +80,7 @@ class RecipeWebview {
7680
});
7781
}
7882

83+
7984
onNotify(fn) {
8085
if (typeof fn === 'function') {
8186
window.Notification.prototype.onNotify = fn;
@@ -87,6 +92,10 @@ class RecipeWebview {
8792
fn();
8893
}
8994
}
95+
96+
static clearCache() {
97+
ipcRenderer.invoke('clearServiceCache');
98+
}
9099
}
91100

92101
module.exports = RecipeWebview;

src/webview/recipe.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { DEFAULT_APP_SETTINGS_VANILLA } from '../configVanilla';
1515

1616
const debug = require('debug')('Franz:Plugin');
1717

18+
window.FranzAPI = {};
19+
1820
class RecipeController {
1921
@observable settings = {
2022
app: DEFAULT_APP_SETTINGS_VANILLA,

0 commit comments

Comments
 (0)