aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview/sessionHandler.ts
blob: 4961da12b1549883886ca7278dcfa0b58f13c106 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { getCurrentWebContents } from '@electron/remote';

const debug = require('debug')('Ferdi:Plugin:SessionHandler');

export class SessionHandler {
  clearStorageData(storageLocations: string[]) {
    try {
      debug('Clearing storageLocations:', storageLocations);
      const { session } = getCurrentWebContents();
      session.flushStorageData();
      session.clearStorageData({ storages: storageLocations });
    } catch (error) {
      debug(error);
    }
  }

  async releaseServiceWorkers() {
    try {
      const registrations =
        await window.navigator.serviceWorker.getRegistrations();
      for (const registration of registrations) {
        registration.unregister();
        debug('ServiceWorker unregistered');
      }
    } catch (error) {
      debug(error);
    }
  }
}