🍙 Refactor removed pick from getExtensionSettings

This commit is contained in:
Shiba 2022-01-09 18:42:35 +00:00
parent 1e7293826a
commit 205a8fd151
4 changed files with 6 additions and 5 deletions

View file

@ -6,8 +6,9 @@ export interface ExtensionSettings {
export const DEFAULT_SETTINGS: ExtensionSettings = { redirect: true, targetPlatform: 'odysee', urlResolver: 'lbryInc' };
export function getExtensionSettingsAsync<K extends Array<keyof ExtensionSettings>>(...keys: K): Promise<Pick<ExtensionSettings, K[number]>> {
return new Promise(resolve => chrome.storage.local.get(keys, o => resolve(o as any)));
export function getExtensionSettingsAsync(): Promise<ExtensionSettings>
{
return new Promise(resolve => chrome.storage.local.get(o => resolve(o as any)));
}

View file

@ -2,7 +2,7 @@ import { DEFAULT_SETTINGS, ExtensionSettings, getExtensionSettingsAsync } from '
/** Reset settings to default value and update the browser badge text */
async function initSettings() {
const settings = await getExtensionSettingsAsync(...Object.keys(DEFAULT_SETTINGS) as Array<keyof ExtensionSettings>);
const settings = await getExtensionSettingsAsync();
// get all the values that aren't set and use them as a change set
const invalidEntries = (Object.entries(DEFAULT_SETTINGS) as Array<[keyof ExtensionSettings, ExtensionSettings[keyof ExtensionSettings]]>)

View file

@ -33,7 +33,7 @@ async function ctxFromURL(href: string): Promise<UpdateContext | void> {
const res = await resolveYT(descriptor)
if (!res) return // couldn't find it on lbry, so we're done
const { redirect, targetPlatform } = await getExtensionSettingsAsync('redirect', 'targetPlatform')
const { redirect, targetPlatform } = await getExtensionSettingsAsync()
return { descriptor, lbryPathname: res, redirect, targetPlatform }
})())
await promise

View file

@ -168,7 +168,7 @@ async function onPageLoad()
history.pushState = function(...params) { onPushState(); return originalPushState(...params) }
}
const settings = await getExtensionSettingsAsync('redirect', 'targetPlatform', 'urlResolver')
const settings = await getExtensionSettingsAsync()
// Listen Settings Change
chrome.storage.onChanged.addListener(async (changes, areaName) => {