mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-04 12:49:03 +00:00
fix: handle mod errors individually, soft fail
This commit is contained in:
parent
71ed1ddb1f
commit
493ab5aa63
25
src/init.js
25
src/init.js
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user