Skip to content

Commit dd6d99f

Browse files
committed
Revert "removed fs test for plugin.main, use try/catch instead"
This reverts commit 1ff70a5.
1 parent 1ff70a5 commit dd6d99f

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/lib/loadPlugin.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,27 @@ export default async function loadPlugin(pluginId, justInstalled = false) {
1212
Url.join(PLUGIN_DIR, pluginId, "plugin.json"),
1313
).readFile("json");
1414

15+
let mainUrl;
16+
if (
17+
await fsOperation(Url.join(PLUGIN_DIR, pluginId, pluginJson.main)).exists()
18+
) {
19+
mainUrl = Url.join(baseUrl, pluginJson.main);
20+
} else {
21+
mainUrl = Url.join(baseUrl, "main.js");
22+
}
23+
1524
return new Promise((resolve, reject) => {
16-
const onerror = (error) => {
25+
const $script = <script src={mainUrl}></script>;
26+
27+
$script.onerror = (error) => {
1728
reject(
1829
new Error(
1930
`Failed to load script for plugin ${pluginId}: ${error.message || error}`,
2031
),
2132
);
2233
};
2334

24-
const onload = async () => {
35+
$script.onload = async () => {
2536
const $page = Page("Plugin");
2637
$page.show = () => {
2738
actionStack.push({
@@ -53,17 +64,6 @@ export default async function loadPlugin(pluginId, justInstalled = false) {
5364
}
5465
};
5566

56-
const $script = <script src={Url.join(baseUrl, pluginJson.main)}></script>;
57-
$script.onload = onload;
58-
$script.onerror = onerror;
59-
60-
try {
61-
document.head.append($script);
62-
} catch (_) {
63-
const $script = <script src={Url.join(baseUrl, "main.js")}></script>;
64-
$script.onload = onload;
65-
$script.onerror = onerror;
66-
document.head.append($script);
67-
}
67+
document.head.append($script);
6868
});
6969
}

0 commit comments

Comments
 (0)