fix: handle mod errors individually, soft fail

This commit is contained in:
dragonwocky 2024-05-27 22:06:14 +10:00
parent 71ed1ddb1f
commit 493ab5aa63
Signed by: dragonwocky
GPG Key ID: 7998D08F7D7BD7A8
2 changed files with 17 additions and 11 deletions

View File

@ -6,12 +6,13 @@
"use strict"; "use strict";
const isElectron = () => { const coreId = "0f0bf8b6-eae6-4273-b307-8fc43f2ee082",
try { isElectron = () => {
return typeof module !== "undefined"; try {
} catch {} return typeof module !== "undefined";
return false; } catch {}
}; return false;
};
if (isElectron()) { if (isElectron()) {
require("./api/system.js"); require("./api/system.js");
@ -38,8 +39,8 @@ if (isElectron()) {
// register user-provided javascript for execution in-app // register user-provided javascript for execution in-app
if (target === ".webpack/renderer/tab_browser_view/preload.js") { if (target === ".webpack/renderer/tab_browser_view/preload.js") {
const { webFrame } = require("electron"), const db = await modDatabase(coreId),
db = await modDatabase("0f0bf8b6-eae6-4273-b307-8fc43f2ee082"), { webFrame } = require("electron"),
customScript = (await db.get("customScript"))?.content; customScript = (await db.get("customScript"))?.content;
if (customScript) webFrame.executeJavaScript(customScript); if (customScript) webFrame.executeJavaScript(customScript);
} }
@ -52,8 +53,12 @@ if (isElectron()) {
const db = await modDatabase(mod.id); const db = await modDatabase(mod.id);
for (let [scriptTarget, script] of mod.electronScripts ?? []) { for (let [scriptTarget, script] of mod.electronScripts ?? []) {
if (target !== scriptTarget) continue; if (target !== scriptTarget) continue;
script = require(`./${mod._src}/${script}`); try {
script(__getApi(), db, __exports, __eval); script = require(`./${mod._src}/${script}`);
script(__getApi(), db, __exports, __eval);
} catch (err) {
console.error(err);
}
} }
} }
}; };

View File

@ -72,7 +72,8 @@ export default (async () => {
Promise.resolve(isCore || API_LOADED) Promise.resolve(isCore || API_LOADED)
.then(() => import(enhancerUrl(`${mod._src}/${script}`))) .then(() => import(enhancerUrl(`${mod._src}/${script}`)))
.then((script) => script.default(globalThis.__enhancerApi, db)) .then((script) => script.default(globalThis.__enhancerApi, db))
.then(() => !isCore || globalThis.__enhancerApi.onReady?.()); .then(() => !isCore || globalThis.__enhancerApi.onReady?.())
.catch((err) => console.error(err));
} }
} }