firefox-meta-handler.ts raw

   1  /* eslint-disable @typescript-eslint/no-explicit-any */
   2  import { ExtensionSettings, SignerMetaHandler } from '@common';
   3  import browser from 'webextension-polyfill';
   4  
   5  export class FirefoxMetaHandler extends SignerMetaHandler {
   6    async loadFullData(): Promise<Partial<Record<string, any>>> {
   7      const dataWithPossibleAlienProperties = await browser.storage.local.get(
   8        null
   9      );
  10  
  11      if (Object.keys(dataWithPossibleAlienProperties).length === 0) {
  12        return dataWithPossibleAlienProperties;
  13      }
  14  
  15      const data: Partial<Record<string, any>> = {};
  16      this.metaProperties.forEach((property) => {
  17        data[property] = dataWithPossibleAlienProperties[property];
  18      });
  19  
  20      return data;
  21    }
  22  
  23    async saveFullData(data: ExtensionSettings): Promise<void> {
  24      await browser.storage.local.set(data as Record<string, any>);
  25    }
  26  
  27    async clearData(keep: string[]): Promise<void> {
  28      const toBeRemovedProperties: string[] = [];
  29  
  30      for (const property of this.metaProperties) {
  31        if (!keep.includes(property)) {
  32          toBeRemovedProperties.push(property);
  33        }
  34      }
  35  
  36      await browser.storage.local.remove(this.metaProperties);
  37    }
  38  }
  39