From bd5321b69e85663ccce2fd94f8ccbf704d0d12bc Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Fri, 24 Oct 2025 15:18:30 +0200 Subject: [PATCH] Improves plugin settings loading and command registration Refactors settings loading to exclude model cache from persisted settings Modifies command registration to use prefixed ID for better stability and collision prevention Enhances type safety and plugin configuration management --- main.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/main.ts b/main.ts index 4534672..e2ed165 100644 --- a/main.ts +++ b/main.ts @@ -65,13 +65,18 @@ export default class FreewritingCleanupPlugin extends Plugin { * Loads plugin settings from Obsidian storage * * Merges stored settings with defaults to ensure all required fields exist. + * Excludes modelCache from settings object to keep types clean. * Returns the raw data for reuse in cache loading. * * @returns Raw plugin data including settings and optional cache, or null if no data exists */ async loadSettings(): Promise { const data = await this.loadData() as FreewritingCleanupData | null; - this.settings = Object.assign({}, DEFAULT_SETTINGS, data); + const { modelCache, ...persisted } = data ?? {}; + this.settings = { + ...DEFAULT_SETTINGS, + ...(persisted as Partial) + }; return data; } @@ -101,11 +106,12 @@ export default class FreewritingCleanupPlugin extends Plugin { * Registers the cleanup command with Obsidian * * Creates the "Clean up text" command with editor callback that executes - * the cleanup operation on selected text. + * the cleanup operation on selected text. Command ID is prefixed with plugin + * ID to avoid future collisions and maintain stability post-release. */ private registerCommand() { this.addCommand({ - id: 'cleanup-text', + id: 'freewriting-cleanup-cleanup-text', name: 'Clean up text', editorCallback: async (editor: Editor, view: MarkdownView) => { await this.executeCleanupCommand(editor, view);