mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-29 16:07:40 +01:00
adjust setupPart timings and extension message preload
This commit is contained in:
parent
703dfc7434
commit
a91e2b6e2e
2 changed files with 12 additions and 3 deletions
|
@ -6,13 +6,22 @@ import {
|
|||
import { isAllowedExtensionVersion } from "@/backend/extension/compatibility";
|
||||
import { ExtensionMakeRequestResponse } from "@/backend/extension/plasmo";
|
||||
|
||||
// for some reason, about 500 ms is needed after
|
||||
// page load before the extension starts responding properly
|
||||
const isExtensionReady = new Promise<void>((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 500);
|
||||
});
|
||||
|
||||
let activeExtension = false;
|
||||
|
||||
function sendMessage<MessageKey extends keyof MessagesMetadata>(
|
||||
async function sendMessage<MessageKey extends keyof MessagesMetadata>(
|
||||
message: MessageKey,
|
||||
payload: MessagesMetadata[MessageKey]["req"] | undefined = undefined,
|
||||
timeout: number = -1,
|
||||
) {
|
||||
await isExtensionReady;
|
||||
return new Promise<MessagesMetadata[MessageKey]["res"] | null>((resolve) => {
|
||||
if (timeout >= 0) setTimeout(() => resolve(null), timeout);
|
||||
sendToBackgroundViaRelay<
|
||||
|
@ -54,7 +63,7 @@ export async function sendPage(
|
|||
export async function extensionInfo(): Promise<
|
||||
MessagesMetadata["hello"]["res"] | null
|
||||
> {
|
||||
const message = await sendMessage("hello", undefined, 300);
|
||||
const message = await sendMessage("hello", undefined, 500);
|
||||
return message;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ type SetupData = {
|
|||
|
||||
function testProxy(url: string) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
setTimeout(() => reject(new Error("Timed out!")), 1000);
|
||||
setTimeout(() => reject(new Error("Timed out!")), 3000);
|
||||
singularProxiedFetch(url, testUrl, {})
|
||||
.then((res) => {
|
||||
if (res.url !== testUrl) return reject(new Error("Not a proxy"));
|
||||
|
|
Loading…
Reference in a new issue