diff --git a/src/lib/installPlugin.js b/src/lib/installPlugin.js index f0eeeac1..7faada3c 100644 --- a/src/lib/installPlugin.js +++ b/src/lib/installPlugin.js @@ -17,6 +17,7 @@ export default async function installPlugin(id, name, purchaseToken) { const loaderDialog = loader.create(title, strings.installing); let pluginDir; let pluginUrl; + let state; try { if (!(await fsOperation(PLUGIN_DIR).exists())) { @@ -71,7 +72,7 @@ export default async function installPlugin(id, name, purchaseToken) { pluginDir = Url.join(PLUGIN_DIR, id); } - const state = await InstallState.new(id); + state = await InstallState.new(id); if (!(await fsOperation(pluginDir).exists())) { await fsOperation(PLUGIN_DIR).createDirectory(id); @@ -115,9 +116,15 @@ export default async function installPlugin(id, name, purchaseToken) { } } catch (err) { try { - await fsOperation(pluginDir).delete(); - } catch (error) { - // ignore + // Clear the install state if installation fails + if (state) await state.clear(); + + // Delete the plugin directory if it was created + if (pluginDir && (await fsOperation(pluginDir).exists())) { + await fsOperation(pluginDir).delete(); + } + } catch (cleanupError) { + console.error("Cleanup failed:", cleanupError); } throw err; } finally { diff --git a/src/lib/installState.js b/src/lib/installState.js index 3130ea09..6a027d32 100644 --- a/src/lib/installState.js +++ b/src/lib/installState.js @@ -82,6 +82,16 @@ export default class InstallState { await fsOperation(url).delete(); } } + + async clear() { + try { + this.store = {}; + this.updatedStore = {}; + await fsOperation(this.storeUrl).writeFile("{}"); + } catch (error) { + console.error("Failed to clear install state:", error); + } + } } /**