Skip to content

Commit 06f146a

Browse files
committed
add: uninstalling
1 parent d79b421 commit 06f146a

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

client/src/addon_manager/commands/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import getAddonsPage from "./getAddonsPage";
55
import refreshAddons from "./refreshAddons";
66
import openLog from "./openLog";
77
import update from "./update";
8+
import uninstall from "./uninstall";
89

910
export const commands = {
1011
enable,
@@ -14,4 +15,5 @@ export const commands = {
1415
refreshAddons,
1516
openLog,
1617
update,
18+
uninstall
1719
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as vscode from "vscode";
2+
import addonManagerService from "../services/addonManager.service";
3+
4+
export default async (
5+
context: vscode.ExtensionContext,
6+
message: { data: { name: string } }
7+
) => {
8+
const addon = addonManagerService.addons.get(message.data.name);
9+
addon.uninstall();
10+
};

client/src/addon_manager/models/addon.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ export class Addon {
2626
#enabled?: boolean[];
2727
/** Whether or not this addon has an update available from git. */
2828
#hasUpdate?: boolean;
29+
/** Whether or not this addon is installed */
30+
#installed: boolean;
2931

3032
constructor(name: string, path: vscode.Uri) {
3133
this.name = name;
3234
this.uri = path;
3335

3436
this.#enabled = [];
3537
this.#hasUpdate = false;
38+
this.#installed = false;
3639
}
3740

3841
/** Fetch addon info from `info.json` */
@@ -106,6 +109,10 @@ export class Addon {
106109
(entry) => (this.#enabled[entry.folder.index] = entry.enabled)
107110
);
108111

112+
this.#installed = await filesystem.exists(
113+
vscode.Uri.joinPath(this.uri, "module")
114+
);
115+
109116
return folderStates;
110117
}
111118

@@ -192,22 +199,24 @@ export class Addon {
192199
return;
193200
}
194201

195-
// Remove submodule
196-
// try {
197-
// const moduleURI = vscode.Uri.joinPath(this.uri, "module");
198-
// await filesystem.deleteFile(moduleURI, {
199-
// recursive: true,
200-
// useTrash: false,
201-
// });
202-
// } catch (e) {
203-
// localLogger.error(`Failed to uninstall "${this.name}"`);
204-
// return;
205-
// }
206-
207202
this.#enabled[folder.index] = false;
208203
localLogger.info(`Disabled "${this.name}"`);
209204
}
210205

206+
public async uninstall() {
207+
for (const folder of vscode.workspace.workspaceFolders) {
208+
await this.disable(folder);
209+
}
210+
const moduleURI = vscode.Uri.joinPath(this.uri, "module");
211+
await filesystem.deleteFile(moduleURI, {
212+
recursive: true,
213+
useTrash: false,
214+
});
215+
localLogger.info(`Uninstalled ${this.name}`);
216+
this.#installed = false;
217+
this.setLock(false);
218+
}
219+
211220
/** Convert this addon to an object ready for sending to WebVue. */
212221
public async toJSON() {
213222
await this.getEnabled();
@@ -227,6 +236,7 @@ export class Addon {
227236
size,
228237
hasUpdate,
229238
processing: this.#processing,
239+
installed: this.#installed,
230240
};
231241
}
232242

0 commit comments

Comments
 (0)