mirror of
https://github.com/LBRYFoundation/Watch-on-LBRY.git
synced 2025-08-23 17:47:26 +00:00
🍙 Refactor removed pick from getExtensionSettings
This commit is contained in:
parent
1e7293826a
commit
205a8fd151
4 changed files with 6 additions and 5 deletions
|
@ -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)));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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]]>)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue