From 094ef84f15f6ddbdfe45b3d0f56f0f4821ff972c Mon Sep 17 00:00:00 2001 From: Max Baumann Date: Tue, 15 Dec 2020 14:24:29 +0100 Subject: [PATCH] refactor(types): add StorageChangesObject type --- src/config.ts | 6 +++--- src/content.ts | 4 ++-- src/types.ts | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/config.ts b/src/config.ts index f2f8f479..4726ae4c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,5 @@ import * as CompileConfig from "../config.json"; -import { CategorySelection, CategorySkipOption, PreviewBarOption, SponsorTime } from "./types"; +import { CategorySelection, CategorySkipOption, PreviewBarOption, SponsorTime, StorageChangesObject } from "./types"; import Utils from "./utils"; const utils = new Utils(); @@ -59,7 +59,7 @@ interface SBConfig { } export interface SBObject { - configListeners: Array; + configListeners: Array<(changes: StorageChangesObject) => unknown>; defaults: SBConfig; localConfig: SBConfig; config: SBConfig; @@ -276,7 +276,7 @@ function decodeStoredItem(id: string, data: T): T | SBMap { + chrome.storage.onChanged.addListener((changes: {[key: string]: chrome.storage.StorageChange}) => { for (const key in changes) { Config.localConfig[key] = decodeStoredItem(key, changes[key].newValue); } diff --git a/src/content.ts b/src/content.ts index f176980a..1e5743b1 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1,6 +1,6 @@ import Config from "./config"; -import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse, VideoInfo } from "./types"; +import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse, VideoInfo, StorageChangesObject } from "./types"; import { ContentContainer } from "./types"; import Utils from "./utils"; @@ -179,7 +179,7 @@ function messageListener(request: any, sender: any, sendResponse: (response: any * * @param {String} changes */ -function contentConfigUpdateListener(changes) { +function contentConfigUpdateListener(changes: StorageChangesObject) { for (const key in changes) { switch(key) { case "hideVideoPlayerControls": diff --git a/src/types.ts b/src/types.ts index 423adf1e..1d282cbe 100644 --- a/src/types.ts +++ b/src/types.ts @@ -156,6 +156,8 @@ interface VideoInfo { type VideoID = string; +type StorageChangesObject = { [key: string]: chrome.storage.StorageChange }; + export { FetchResponse, VideoDurationResponse, @@ -169,4 +171,5 @@ export { Registration, BackgroundScriptContainer, VideoInfo, + StorageChangesObject, };