notarize button send to offscreen

This commit is contained in:
0xtsukino
2023-08-22 08:43:52 -07:00
committed by tsukino
parent cd561a7a53
commit 0af84cf1d6
5 changed files with 34 additions and 23 deletions

View File

@@ -5,7 +5,7 @@ import React, {
useEffect,
useState,
} from "react";
import { RequestLog } from "../../pages/Background/actionTypes";
import { BackgroundActiontype, RequestLog } from "../../pages/Background/actionTypes";
import classNames from "classnames";
import {
Navigate,
@@ -44,7 +44,15 @@ export default function RequestDetail(props: Props): ReactElement {
<RequestDetailsHeaderTab path="/response">
Response
</RequestDetailsHeaderTab>
<button className="absolute right-2 bg-primary/[0.9] text-white font-bold px-2 py-0.5 hover:bg-primary/[0.8] active:bg-primary">
<button
className="absolute right-2 bg-primary/[0.9] text-white font-bold px-2 py-0.5 hover:bg-primary/[0.8] active:bg-primary"
onClick={async () => {
await chrome.runtime.sendMessage({
type: BackgroundActiontype.test_wasm,
target: 'offscreen',
});
}}
>
Notarize
</button>
</div>
@@ -421,7 +429,7 @@ function RequestHeaders(props: Props): ReactElement {
</tr>
</thead>
<tbody className="">
{data?.requestHeaders.map((h) => (
{data?.requestHeaders?.map((h) => (
<tr key={h.name} className="border-b border-slate-200">
<td className="border border-slate-300 font-bold align-top py-1 px-2 whitespace-nowrap">
{h.name}

View File

@@ -2,6 +2,7 @@ export enum BackgroundActiontype {
get_requests = "get_requests",
clear_requests = "clear_requests",
push_action = "push_action",
test_wasm = "test_wasm",
}
export type BackgroundAction = {

View File

@@ -10,22 +10,13 @@ let RequestsLogs: {
const mutex = new Mutex();
let offscreen;
(async () => {
await new Promise(r => setTimeout(r, 1000));
if (offscreen) {
offscreen = null;
} else {
// @ts-ignore
offscreen = chrome.offscreen.createDocument({
url: "offscreen.html",
reasons: ["WORKERS"],
justification: "workers for multithreading",
});
await offscreen;
offscreen = null;
}
// @ts-ignore
chrome.offscreen.createDocument({
url: "offscreen.html",
reasons: ["WORKERS"],
justification: "workers for multithreading",
});
chrome.tabs.onActivated.addListener((tabs) => {
const tab = RequestsLogs[tabs.tabId];

View File

@@ -1,14 +1,25 @@
import React, { useEffect } from "react";
import * as Comlink from "comlink";
import { BackgroundActiontype } from "../Background/actionTypes";
const Offscreen = () => {
useEffect(() => {
(async function offscreenloaded() {
console.log("offscreen loaded - spawning worker from worker.ts");
const Wasm: any = Comlink.wrap(
new Worker(new URL("./worker.ts", import.meta.url))
);
await new Wasm();
chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
switch (request.type) {
case BackgroundActiontype.test_wasm: {
const Wasm: any = Comlink.wrap(
new Worker(new URL("./worker.ts", import.meta.url)));
await new Wasm();
return sendResponse();
}
default:
break;
}
})
})();
}, []);

View File

@@ -4,5 +4,5 @@ import { createRoot } from "react-dom/client";
import Offscreen from "./Offscreen";
const container = document.getElementById("app-container");
const root = createRoot(container!); // createRoot(container!) if you use TypeScript
const root = createRoot(container!);
root.render(<Offscreen />);