Skip to content

Commit 56dba29

Browse files
committed
Remove uninstalled plugins
1 parent 9ca1fcf commit 56dba29

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/settings/SettingsTab.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,7 @@ export class VareSettingTab extends PluginSettingTab {
1414
super(app, plugin);
1515
this.plugin = plugin;
1616

17-
const manifests = Object.entries(structuredClone(this.plugin.app.plugins.manifests));
18-
const pluginData = Object.entries(this.plugin.settings.plugins);
19-
this.pluginsList = manifests.map(manifest => {
20-
const info: PluginInfo = { ...(manifest[1] as PluginManifest), repo: '', releases: [] };
21-
const data = pluginData.filter(data => data[0] === manifest[0])[0];
22-
if (!data) {
23-
return info;
24-
}
25-
return Object.assign(info, data[1]);
26-
});
17+
this.loadPluginList();
2718
}
2819

2920
async display(): Promise<void> {
@@ -92,6 +83,7 @@ export class VareSettingTab extends PluginSettingTab {
9283
.setTooltip('Reload plugins')
9384
.onClick(() => {
9485
// Reload plugins
86+
this.loadPluginList();
9587
this.display();
9688
}));
9789

@@ -239,4 +231,26 @@ export class VareSettingTab extends PluginSettingTab {
239231
});
240232
});
241233
}
234+
235+
loadPluginList() {
236+
const manifests = Object.entries(structuredClone(this.plugin.app.plugins.manifests));
237+
const pluginData = Object.entries(structuredClone(this.plugin.settings.plugins));
238+
239+
// Remove unused plugins
240+
const upToDate = pluginData.filter(data => !manifests.every(entry => data[0] !== entry[0]));
241+
this.plugin.settings.plugins = {};
242+
upToDate.forEach(plugin => {
243+
this.plugin.settings.plugins[plugin[0]] = plugin[1] as PluginData;
244+
});
245+
246+
// Set plugin list
247+
this.pluginsList = manifests.map(manifest => {
248+
const info: PluginInfo = { ...(manifest[1] as PluginManifest), repo: '', releases: [] };
249+
const data = upToDate.filter(data => data[0] === manifest[0])[0];
250+
if (!data) {
251+
return info;
252+
}
253+
return Object.assign(info, data[1]);
254+
});
255+
}
242256
}

0 commit comments

Comments
 (0)