Skip to content

Commit

Permalink
[FIX] Remove uninstalled plugins (#3)
Browse files Browse the repository at this point in the history
Remove uninstalled plugins
  • Loading branch information
4Source authored Mar 18, 2024
1 parent 9ca1fcf commit 75cdaf2
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/settings/SettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@ export class VareSettingTab extends PluginSettingTab {
super(app, plugin);
this.plugin = plugin;

const manifests = Object.entries(structuredClone(this.plugin.app.plugins.manifests));
const pluginData = Object.entries(this.plugin.settings.plugins);
this.pluginsList = manifests.map(manifest => {
const info: PluginInfo = { ...(manifest[1] as PluginManifest), repo: '', releases: [] };
const data = pluginData.filter(data => data[0] === manifest[0])[0];
if (!data) {
return info;
}
return Object.assign(info, data[1]);
});
this.loadPluginList();
}

async display(): Promise<void> {
Expand Down Expand Up @@ -92,6 +83,7 @@ export class VareSettingTab extends PluginSettingTab {
.setTooltip('Reload plugins')
.onClick(() => {
// Reload plugins
this.loadPluginList();
this.display();
}));

Expand Down Expand Up @@ -239,4 +231,26 @@ export class VareSettingTab extends PluginSettingTab {
});
});
}

loadPluginList() {
const manifests = Object.entries(structuredClone(this.plugin.app.plugins.manifests));
const pluginData = Object.entries(structuredClone(this.plugin.settings.plugins));

// Remove unused plugins
const upToDate = pluginData.filter(data => !manifests.every(entry => data[0] !== entry[0]));
this.plugin.settings.plugins = {};
upToDate.forEach(plugin => {
this.plugin.settings.plugins[plugin[0]] = plugin[1] as PluginData;
});

// Set plugin list
this.pluginsList = manifests.map(manifest => {
const info: PluginInfo = { ...(manifest[1] as PluginManifest), repo: '', releases: [] };
const data = upToDate.filter(data => data[0] === manifest[0])[0];
if (!data) {
return info;
}
return Object.assign(info, data[1]);
});
}
}

0 comments on commit 75cdaf2

Please sign in to comment.