diff options
author | Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com> | 2021-09-08 19:49:12 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-08 19:49:12 +0530 |
commit | 1fab031b14f02037193e1b40dc92f3cf3d2d5c04 (patch) | |
tree | 2008a9165e3b651b959daff4308fe555b49a1166 | |
parent | New translations en-US.json (#1886) (diff) | |
download | ferdium-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)
-rw-r--r-- | src/webview/recipe.js | 7 | ||||
-rw-r--r-- | src/webview/sessionHandler.ts | 28 |
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'; | |||
23 | import Userscript from './lib/Userscript'; | 23 | import Userscript from './lib/Userscript'; |
24 | 24 | ||
25 | import { BadgeHandler } from './badge'; | 25 | import { BadgeHandler } from './badge'; |
26 | import { SessionHandler } from './sessionHandler'; | ||
26 | import contextMenu from './contextMenu'; | 27 | import contextMenu from './contextMenu'; |
27 | import { | 28 | import { |
28 | injectDarkModeStyle, | 29 | injectDarkModeStyle, |
@@ -50,6 +51,8 @@ const debug = require('debug')('Ferdi:Plugin'); | |||
50 | 51 | ||
51 | const badgeHandler = new BadgeHandler(); | 52 | const badgeHandler = new BadgeHandler(); |
52 | 53 | ||
54 | const sessionHandler = new SessionHandler(); | ||
55 | |||
53 | const notificationsHandler = new NotificationsHandler(); | 56 | const 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 @@ | |||
1 | import { getCurrentWebContents } from '@electron/remote'; | ||
2 | |||
3 | const debug = require('debug')('Ferdi:Plugin:SessionHandler'); | ||
4 | |||
5 | 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 (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 | } | ||