From 92fbdd727d35bfb423586476211fcea89f84cd03 Mon Sep 17 00:00:00 2001 From: Shiba <44804845+DeepDoge@users.noreply.github.com> Date: Tue, 25 Jan 2022 16:42:19 +0000 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=8D=98=20updater=20wasn't=20working?= =?UTF-8?q?=20on=20settings=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scripts/ytContent.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/scripts/ytContent.tsx b/src/scripts/ytContent.tsx index 482c602..6888d5e 100644 --- a/src/scripts/ytContent.tsx +++ b/src/scripts/ytContent.tsx @@ -95,6 +95,7 @@ async function requestLbryPathname(videoId: string) { if (areaName !== 'local') return Object.assign(settings, Object.fromEntries(Object.entries(changes).map(([key, change]) => [key, change.newValue]))) if (changes.redirect) await onModeChange() + await updater() }) /* @@ -174,8 +175,6 @@ async function requestLbryPathname(videoId: string) { updateButton(mountPoint, target) } } - - await updater() } await onModeChange() From b17f2f4e2eddaae3a68d024722e70c8bdfc8bd60 Mon Sep 17 00:00:00 2001 From: Shiba <44804845+DeepDoge@users.noreply.github.com> Date: Wed, 26 Jan 2022 18:22:43 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=8D=99=20updater=20wasn't=20working?= =?UTF-8?q?=20on=20start?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scripts/ytContent.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/scripts/ytContent.tsx b/src/scripts/ytContent.tsx index 6888d5e..fa5e6ed 100644 --- a/src/scripts/ytContent.tsx +++ b/src/scripts/ytContent.tsx @@ -175,7 +175,6 @@ async function requestLbryPathname(videoId: string) { updateButton(mountPoint, target) } } + await updater() } - - await onModeChange() })() \ No newline at end of file From bb0dc3c4f475ae69e1354f7a23f2ecb78e824244 Mon Sep 17 00:00:00 2001 From: Shiba <44804845+DeepDoge@users.noreply.github.com> Date: Thu, 27 Jan 2022 11:17:00 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=8D=98=20bug=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - lbry-url parser disabled because it was returning empty array and it just works without it - content script wasnt starting to work - background error on content script was being handled wrong - background lbryPathnameFromVideoId wasnt ending well on error --- src/common/yt/urlCache.ts | 2 ++ src/scripts/background.ts | 35 +++++++++++++++++++++++------------ src/scripts/ytContent.tsx | 6 ++++-- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/common/yt/urlCache.ts b/src/common/yt/urlCache.ts index b3a21f2..a6a334e 100644 --- a/src/common/yt/urlCache.ts +++ b/src/common/yt/urlCache.ts @@ -53,6 +53,7 @@ async function put(url: string | null, id: string): Promise { const store = db?.transaction("store", "readwrite").objectStore("store") if (!store) return resolve() const request = store.put({ value: url, expireAt: !url ? new Date(Date.now() + 1 * 60 * 60 * 1000) : new Date(Date.now() + 15 * 24 * 60 * 60 * 1000) }, id) + console.log('caching', id, url) request.addEventListener('success', () => resolve()) request.addEventListener('error', () => reject(request.error)) }) @@ -76,6 +77,7 @@ async function get(id: string): Promise { await clearExpired() return undefined } + console.log('cache found', id, response.value) return response.value } diff --git a/src/scripts/background.ts b/src/scripts/background.ts index ffe4467..859ab39 100644 --- a/src/scripts/background.ts +++ b/src/scripts/background.ts @@ -1,23 +1,34 @@ -import { parseProtocolUrl } from '../common/lbry-url' import { resolveById, YtIdResolverDescriptor } from '../common/yt/urlResolve' async function resolveYT(descriptor: YtIdResolverDescriptor) { - const lbryProtocolUrl: string | null = await resolveById([descriptor]).then(a => a[0]) - const segments = parseProtocolUrl(lbryProtocolUrl || '', { encode: true }) - if (segments.length === 0) return - return segments.join('/') + const lbryProtocolUrl: string | null = (await resolveById([descriptor]).then(a => a[0])) ?? null + if (!lbryProtocolUrl) return null + return lbryProtocolUrl.replaceAll('#', ':') + /* const segments = parseProtocolUrl(lbryProtocolUrl || '', { encode: true }) + if (segments.length === 0) throw new Error() + return segments.join('/') */ } -const onGoingLbryPathnameRequest: Record> = {} -async function lbryPathnameFromVideoId(videoId: string): Promise { +const onGoingLbryPathnameRequest: Record> = {} +async function lbryPathnameFromVideoId(videoId: string): Promise { // Don't create a new Promise for same ID until on going one is over. - const promise = onGoingLbryPathnameRequest[videoId] ?? (onGoingLbryPathnameRequest[videoId] = resolveYT({ id: videoId, type: 'video' })) - await promise - delete onGoingLbryPathnameRequest[videoId] - return await promise + try { + const promise = onGoingLbryPathnameRequest[videoId] ?? (onGoingLbryPathnameRequest[videoId] = resolveYT({ id: videoId, type: 'video' })) + console.log('lbrypathname request', videoId, await promise) + return await promise + } catch (error) { + throw error + } + finally { + delete onGoingLbryPathnameRequest[videoId] + } } chrome.runtime.onMessage.addListener(({ videoId }: { videoId: string }, sender, sendResponse) => { - lbryPathnameFromVideoId(videoId).then((lbryPathname) => sendResponse(lbryPathname)).catch((err) => sendResponse(err)) + lbryPathnameFromVideoId(videoId).then((lbryPathname) => sendResponse(lbryPathname)).catch((err) => + { + sendResponse('error') + console.error(err) + }) return true }) diff --git a/src/scripts/ytContent.tsx b/src/scripts/ytContent.tsx index fa5e6ed..5a0de20 100644 --- a/src/scripts/ytContent.tsx +++ b/src/scripts/ytContent.tsx @@ -80,8 +80,8 @@ async function findVideoElement() { // We should get this from background, so the caching works and we don't get errors in the future if yt decides to impliment CORS async function requestLbryPathname(videoId: string) { - const response = await new Promise((resolve) => chrome.runtime.sendMessage({ videoId }, resolve)) - if (response instanceof Error) throw response + const response = await new Promise((resolve) => chrome.runtime.sendMessage({ videoId }, resolve)) + if (response === 'error') throw new Error("Background error.") return response } @@ -177,4 +177,6 @@ async function requestLbryPathname(videoId: string) { } await updater() } + + await onModeChange() })() \ No newline at end of file From 3692ccba891de3517cfe8d81a8efd94b4af19ee6 Mon Sep 17 00:00:00 2001 From: Shiba <44804845+DeepDoge@users.noreply.github.com> Date: Thu, 27 Jan 2022 11:24:35 +0000 Subject: [PATCH 4/4] ... --- src/common/yt/urlCache.ts | 5 +++-- src/scripts/background.ts | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/common/yt/urlCache.ts b/src/common/yt/urlCache.ts index a6a334e..8adcc63 100644 --- a/src/common/yt/urlCache.ts +++ b/src/common/yt/urlCache.ts @@ -52,8 +52,9 @@ async function put(url: string | null, id: string): Promise { return await new Promise((resolve, reject) => { const store = db?.transaction("store", "readwrite").objectStore("store") if (!store) return resolve() - const request = store.put({ value: url, expireAt: !url ? new Date(Date.now() + 1 * 60 * 60 * 1000) : new Date(Date.now() + 15 * 24 * 60 * 60 * 1000) }, id) - console.log('caching', id, url) + const expireAt = !url ? new Date(Date.now() + 1 * 60 * 60 * 1000) : new Date(Date.now() + 15 * 24 * 60 * 60 * 1000) + const request = store.put({ value: url, expireAt }, id) + console.log('caching', id, url, 'until:', expireAt) request.addEventListener('success', () => resolve()) request.addEventListener('error', () => reject(request.error)) }) diff --git a/src/scripts/background.ts b/src/scripts/background.ts index 859ab39..c30af4f 100644 --- a/src/scripts/background.ts +++ b/src/scripts/background.ts @@ -1,4 +1,5 @@ import { resolveById, YtIdResolverDescriptor } from '../common/yt/urlResolve' + async function resolveYT(descriptor: YtIdResolverDescriptor) { const lbryProtocolUrl: string | null = (await resolveById([descriptor]).then(a => a[0])) ?? null if (!lbryProtocolUrl) return null