-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.tsx
47 lines (39 loc) · 1.23 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { createRoot } from "react-dom/client";
import "@pages/panel/index.css";
import refreshOnUpdate from "virtual:reload-on-update-in-view";
import connect from "./devtools/connect";
import Panel from "./components/Panel";
refreshOnUpdate("pages/panel");
const bridge: BridgeFn = (code: string) => {
return new Promise((resolve, reject) => {
chrome.devtools.inspectedWindow.eval(code, (result, err) => {
if (err) {
if (err instanceof Error) {
reject(err);
}
console.log(code);
reject(new Error(err.value || err.description || err.code));
}
resolve(result as any);
});
});
};
function init() {
connect(bridge);
const appContainer = document.getElementById("app") as HTMLDivElement;
if (!appContainer) {
throw new Error("Can not find #app");
}
const root = createRoot(appContainer);
root.render(<Panel />);
// TODO: find a solution for firefox
// chrome.windows is not available on firefox
chrome.windows?.onFocusChanged.addListener(() => {
bridge(
"window.__KONVA_DEVTOOLS_GLOBAL_HOOK__ && window.__KONVA_DEVTOOLS_GLOBAL_HOOK__.selection.deactivate()"
);
});
}
init();
export type BridgeFn = <T>(code: string) => Promise<T>;
export { bridge };