From 1c1cba6ce53ba16e3f014caea311becfd83ae455 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Sat, 25 Oct 2025 10:46:20 +0200 Subject: [PATCH] Enhances model selection and caching in settings Improves model dropdown handling with debounced settings save Adds model list cache clearing functionality Handles edge cases for model availability and selection Introduces more robust error handling for model dropdowns Provides user control over model list refreshing --- settings.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/settings.ts b/settings.ts index bbd4650..d876d6e 100644 --- a/settings.ts +++ b/settings.ts @@ -176,9 +176,9 @@ export class FreewritingPromptsSettingTab extends PluginSettingTab { if (this.availableModels.length > 0) { dropdown.setValue(this.plugin.settings.model); } - dropdown.onChange(async (value) => { + dropdown.onChange((value) => { this.plugin.settings.model = value; - await this.plugin.saveSettings(); + this.debounceSaveSettings(); }); }); @@ -292,6 +292,18 @@ export class FreewritingPromptsSettingTab extends PluginSettingTab { const notice = new Notice('Cache cleared'); setTimeout(() => notice.hide(), 2000); })); + + new Setting(containerEl) + .setName('Clear Model List Cache') + .setDesc('Clear cached Claude model list to force a fresh fetch from the API') + .addButton(button => button + .setButtonText('Clear Models Cache') + .onClick(() => { + this.plugin.modelService.clearCache(); + // Show a temporary notice + const notice = new Notice('Model list cache cleared'); + setTimeout(() => notice.hide(), 2000); + })); } // MARK: - Model Loading @@ -338,7 +350,12 @@ export class FreewritingPromptsSettingTab extends PluginSettingTab { } else { // Fall back to first available model if current one is gone const fallbackModel = this.availableModels[0]; - if (fallbackModel && this.plugin.settings.model !== fallbackModel.id) { + if (!fallbackModel) { + // Edge case: both API and fallback returned empty + this.modelDropdown.setDisabled(true); + this.modelDropdown.selectEl.empty(); + this.modelDropdown.addOption('', 'No models available'); + } else if (this.plugin.settings.model !== fallbackModel.id) { this.modelDropdown.setValue(fallbackModel.id); this.plugin.settings.model = fallbackModel.id; await this.plugin.saveSettings();