aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com>2021-09-08 19:49:12 +0530
committerLibravatar GitHub <noreply@github.com>2021-09-08 19:49:12 +0530
commit1fab031b14f02037193e1b40dc92f3cf3d2d5c04 (patch)
tree2008a9165e3b651b959daff4308fe555b49a1166 /src
parentNew translations en-US.json (#1886) (diff)
downloadferdium-app-1fab031b14f02037193e1b40dc92f3cf3d2d5c04.tar.gz
ferdium-app-1fab031b14f02037193e1b40dc92f3cf3d2d5c04.tar.zst
ferdium-app-1fab031b14f02037193e1b40dc92f3cf3d2d5c04.zip
refactor: expose some more methods for session handling on the main repo (#1887)
Diffstat (limited to 'src')
-rw-r--r--src/webview/recipe.js7
-rw-r--r--src/webview/sessionHandler.ts28
2 files changed, 35 insertions, 0 deletions
diff --git a/src/webview/recipe.js b/src/webview/recipe.js
index b2cc55ad3..a3ae4513f 100644
--- a/src/webview/recipe.js
+++ b/src/webview/recipe.js
@@ -23,6 +23,7 @@ import RecipeWebview from './lib/RecipeWebview';
23import Userscript from './lib/Userscript'; 23import Userscript from './lib/Userscript';
24 24
25import { BadgeHandler } from './badge'; 25import { BadgeHandler } from './badge';
26import { SessionHandler } from './sessionHandler';
26import contextMenu from './contextMenu'; 27import contextMenu from './contextMenu';
27import { 28import {
28 injectDarkModeStyle, 29 injectDarkModeStyle,
@@ -50,6 +51,8 @@ const debug = require('debug')('Ferdi:Plugin');
50 51
51const badgeHandler = new BadgeHandler(); 52const badgeHandler = new BadgeHandler();
52 53
54const sessionHandler = new SessionHandler();
55
53const notificationsHandler = new NotificationsHandler(); 56const notificationsHandler = new NotificationsHandler();
54 57
55// Patching window.open 58// Patching window.open
@@ -107,6 +110,10 @@ contextBridge.exposeInMainWorld('ferdi', {
107 badgeHandler.safeParseInt(text), 110 badgeHandler.safeParseInt(text),
108 displayNotification: (title, options) => 111 displayNotification: (title, options) =>
109 notificationsHandler.displayNotification(title, options), 112 notificationsHandler.displayNotification(title, options),
113 clearStorageData: (storageLocations) =>
114 sessionHandler.clearStorageData(storageLocations),
115 releaseServiceWorkers: () =>
116 sessionHandler.releaseServiceWorkers(),
110 getDisplayMediaSelector, 117 getDisplayMediaSelector,
111 getCurrentWebContents, 118 getCurrentWebContents,
112 BrowserWindow, 119 BrowserWindow,
diff --git a/src/webview/sessionHandler.ts b/src/webview/sessionHandler.ts
new file mode 100644
index 000000000..6a7e62ac5
--- /dev/null
+++ b/src/webview/sessionHandler.ts
@@ -0,0 +1,28 @@
1import { getCurrentWebContents } from '@electron/remote';
2
3const debug = require('debug')('Ferdi:Plugin:SessionHandler');
4
5export 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 (err) {
13 debug(err);
14 }
15 }
16
17 async releaseServiceWorkers() {
18 try {
19 const registrations = await window.navigator.serviceWorker.getRegistrations();
20 registrations.forEach(r => {
21 r.unregister();
22 debug('ServiceWorker unregistered');
23 });
24 } catch (err) {
25 debug(err);
26 }
27 }
28}