This repository has been archived on 2023-12-17. You can view files and clone it, but cannot push or open issues or pull requests.
2023-07-25 15:52:32 +00:00
|
|
|
import browser from "webextension-polyfill";
|
|
|
|
|
|
|
|
import { createClient } from "@lumeweb/kernel-swarm-client";
|
|
|
|
|
|
|
|
let swarmClient = createClient();
|
|
|
|
|
|
|
|
export async function queryBackground(method: string, data = {}) {
|
|
|
|
let resp;
|
|
|
|
try {
|
|
|
|
resp = await browser.runtime.sendMessage({
|
|
|
|
method,
|
|
|
|
data,
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function waitForBoot() {
|
|
|
|
await queryBackground("waitForBoot");
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function waitForConnected(cb?: Function) {
|
|
|
|
await waitForBoot();
|
|
|
|
await swarmClient.ready();
|
|
|
|
await cb?.();
|
|
|
|
}
|
2023-08-03 18:55:09 +00:00
|
|
|
|
|
|
|
export async function listenBootStatus(cb: (percent: number) => void) {
|
|
|
|
const port = browser.runtime.connect();
|
|
|
|
|
|
|
|
port.onMessage.addListener((data: any) => {
|
|
|
|
if (data?.method === "bootStatus") {
|
|
|
|
cb(data.data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|