MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / init

Function init

src/lib/devTools.js:35–93  ·  view source on GitHub ↗

* Initialize Eruda for developer mode * @param {boolean} showLoader - Whether to show a loading dialog * @returns {Promise }

(showLoader = false)

Source from the content-addressed store, hash-verified

33 * @returns {Promise<void>}
34 */
35 async init(showLoader = false) {
36 if (isInitialized) return;
37
38 try {
39 const erudaPath = Url.join(DATA_STORAGE, "eruda.js");
40 const fs = fsOperation(erudaPath);
41
42 if (!(await fs.exists())) {
43 if (showLoader) {
44 loader.create(
45 strings["downloading file"]?.replace("{file}", "eruda.js") ||
46 "Downloading eruda.js...",
47 strings["downloading..."] || "Downloading...",
48 );
49 }
50
51 try {
52 const erudaScript = await fsOperation(config.ERUDA_CDN).readFile(
53 "utf-8",
54 );
55 await fsOperation(DATA_STORAGE).createFile("eruda.js", erudaScript);
56 } catch {
57 } finally {
58 if (showLoader) loader.destroy();
59 }
60 }
61
62 const internalUri = await helpers.toInternalUri(erudaPath);
63
64 await new Promise((resolve, reject) => {
65 const script = document.createElement("script");
66 script.src = internalUri;
67 script.id = "eruda-script";
68 script.onload = resolve;
69 script.onerror = reject;
70 document.head.appendChild(script);
71 });
72
73 if (window.eruda) {
74 window.eruda.init({
75 useShadowDom: true,
76 autoScale: true,
77 defaults: {
78 displaySize: 50,
79 },
80 });
81
82 window.eruda._shadowRoot.querySelector(
83 ".eruda-entry-btn",
84 ).style.display = "none";
85
86 erudaInstance = window.eruda;
87 isInitialized = true;
88 }
89 } catch (error) {
90 console.error("Failed to initialize developer tools", error);
91 throw error;
92 }

Callers

nothing calls this directly

Calls 8

fsOperationFunction · 0.85
existsMethod · 0.65
createMethod · 0.65
createFileMethod · 0.65
readFileMethod · 0.45
destroyMethod · 0.45
initMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected