Skip to content

Commit

Permalink
fix: prune deleted properties on save
Browse files Browse the repository at this point in the history
related to #6
  • Loading branch information
gfxholo committed Jun 20, 2024
1 parent 6bb4074 commit a6b728f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/IconicPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,10 +710,19 @@ export default class IconicPlugin extends Plugin {
}

/**
* Save settings to storage.
* Save settings to storage, pruning any deleted items if necessary.
* Item IDs are sorted for human-readability.
*/
async saveSettings(): Promise<void> {
if (!this.settings.rememberDeletedItems) {
// @ts-expect-error (Private API)
const propIds = Object.keys(this.app.metadataTypeManager?.properties ?? {});
for (const propId in this.settings.propertyIcons) {
if (!propIds.includes(propId)) {
delete this.settings.propertyIcons[propId];
}
}
}
this.settings.appIcons = Object.fromEntries(Object.entries(this.settings.appIcons).sort());
this.settings.tabIcons = Object.fromEntries(Object.entries(this.settings.tabIcons).sort());
this.settings.fileIcons = Object.fromEntries(Object.entries(this.settings.fileIcons).sort());
Expand Down

0 comments on commit a6b728f

Please sign in to comment.