mirror of
https://github.com/sussy-code/smov.git
synced 2025-01-01 16:37:39 +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 { isAllowedExtensionVersion } from "@/backend/extension/compatibility";
|
||||||
import { ExtensionMakeRequestResponse } from "@/backend/extension/plasmo";
|
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;
|
let activeExtension = false;
|
||||||
|
|
||||||
function sendMessage<MessageKey extends keyof MessagesMetadata>(
|
async function sendMessage<MessageKey extends keyof MessagesMetadata>(
|
||||||
message: MessageKey,
|
message: MessageKey,
|
||||||
payload: MessagesMetadata[MessageKey]["req"] | undefined = undefined,
|
payload: MessagesMetadata[MessageKey]["req"] | undefined = undefined,
|
||||||
timeout: number = -1,
|
timeout: number = -1,
|
||||||
) {
|
) {
|
||||||
|
await isExtensionReady;
|
||||||
return new Promise<MessagesMetadata[MessageKey]["res"] | null>((resolve) => {
|
return new Promise<MessagesMetadata[MessageKey]["res"] | null>((resolve) => {
|
||||||
if (timeout >= 0) setTimeout(() => resolve(null), timeout);
|
if (timeout >= 0) setTimeout(() => resolve(null), timeout);
|
||||||
sendToBackgroundViaRelay<
|
sendToBackgroundViaRelay<
|
||||||
|
@ -54,7 +63,7 @@ export async function sendPage(
|
||||||
export async function extensionInfo(): Promise<
|
export async function extensionInfo(): Promise<
|
||||||
MessagesMetadata["hello"]["res"] | null
|
MessagesMetadata["hello"]["res"] | null
|
||||||
> {
|
> {
|
||||||
const message = await sendMessage("hello", undefined, 300);
|
const message = await sendMessage("hello", undefined, 500);
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ type SetupData = {
|
||||||
|
|
||||||
function testProxy(url: string) {
|
function testProxy(url: string) {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
setTimeout(() => reject(new Error("Timed out!")), 1000);
|
setTimeout(() => reject(new Error("Timed out!")), 3000);
|
||||||
singularProxiedFetch(url, testUrl, {})
|
singularProxiedFetch(url, testUrl, {})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.url !== testUrl) return reject(new Error("Not a proxy"));
|
if (res.url !== testUrl) return reject(new Error("Not a proxy"));
|
||||||
|
|
Loading…
Reference in a new issue