Skip to content

Commit 10b4fa0

Browse files
authored
fix: clean broken or half installed plugins on start (#1121)
1 parent df66862 commit 10b4fa0

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/lib/loadPlugins.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import loadPlugin from "./loadPlugin";
55
export default async function loadPlugins() {
66
const plugins = await fsOperation(PLUGIN_DIR).lsDir();
77
const results = [];
8+
const failedPlugins = [];
89

910
if (plugins.length > 0) {
1011
toast(strings["loading plugins"]);
@@ -20,10 +21,31 @@ export default async function loadPlugins() {
2021
window.log("error", `Failed to load plugin: ${pluginId}`);
2122
window.log("error", error);
2223
toast(`Failed to load plugin: ${pluginId}`);
24+
failedPlugins.push(pluginId);
2325
results.push(false);
2426
}
2527
});
2628

2729
await Promise.allSettled(loadPromises);
30+
if (failedPlugins.length > 0) {
31+
setTimeout(() => {
32+
cleanupFailedPlugins(failedPlugins).catch((error) => {
33+
console.error("Failed to cleanup plugins:", error);
34+
});
35+
}, 1000);
36+
}
2837
return results.filter(Boolean).length;
2938
}
39+
40+
async function cleanupFailedPlugins(pluginIds) {
41+
for (const pluginId of pluginIds) {
42+
try {
43+
const pluginDir = Url.join(PLUGIN_DIR, pluginId);
44+
if (await fsOperation(pluginDir).exists()) {
45+
await fsOperation(pluginDir).delete();
46+
}
47+
} catch (error) {
48+
window.log("error", `Failed to cleanup plugin ${pluginId}:`, error);
49+
}
50+
}
51+
}

src/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ async function loadApp() {
426426

427427
// Check for app updates
428428
if (navigator.onLine) {
429-
fetch("https://api.github.com/repos/deadlyjack/Acode/releases/latest")
429+
fetch("https://api.github.com/repos/Acode-Foundation/Acode/releases/latest")
430430
.then((res) => res.json())
431431
.then((release) => {
432432
// assuming version is in format v1.2.3

0 commit comments

Comments
 (0)