From 52ea9de4c0c39f2fd57cfc5b4c5e026d7f28b956 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Fri, 24 Oct 2025 13:46:25 +0200 Subject: [PATCH] Improves model fallback and settings handling Enhances model selection resilience by adding detailed fallback notifications Adds model ID check before changing default model to prevent unnecessary updates Improves user experience with more informative model unavailability notices Removes redundant API key update and settings save operations Supports dynamic model management on model refresh --- settings.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/settings.ts b/settings.ts index b7db14e..b3c7819 100644 --- a/settings.ts +++ b/settings.ts @@ -109,7 +109,8 @@ export class FreewritingPromptsSettingTab extends PluginSettingTab { .onChange(async (value) => { this.plugin.settings.apiKey = value; await this.plugin.saveSettings(); - this.plugin.promptGenerator.updateApiKey(value); + // Note: updateApiKey is called by saveSettings only if key changed + // This avoids clearing the prompt cache twice // Clear any existing debounce timer if (this.apiKeyDebounceTimer !== null) { @@ -309,10 +310,11 @@ export class FreewritingPromptsSettingTab extends PluginSettingTab { } else { // Fall back to first available model if current one is gone const fallbackModel = this.availableModels[0]; - if (fallbackModel) { + if (fallbackModel && this.plugin.settings.model !== fallbackModel.id) { this.modelDropdown.setValue(fallbackModel.id); this.plugin.settings.model = fallbackModel.id; await this.plugin.saveSettings(); + new Notice(`Your selected model is no longer available. Defaulting to ${fallbackModel.displayName} (${fallbackModel.id})`); } } } @@ -380,16 +382,15 @@ export class FreewritingPromptsSettingTab extends PluginSettingTab { } else { // Fall back to first available model if current one is gone const fallbackModel = this.availableModels[0]; - if (fallbackModel) { + if (fallbackModel && this.plugin.settings.model !== fallbackModel.id) { this.modelDropdown.setValue(fallbackModel.id); this.plugin.settings.model = fallbackModel.id; - new Notice('Your selected model is no longer available. Defaulting to ' + fallbackModel.displayName); + new Notice(`Your selected model is no longer available. Defaulting to ${fallbackModel.displayName} (${fallbackModel.id})`); + // Save only if model actually changed + await this.plugin.saveSettings(); } } } - - // Persist any selection changes - await this.plugin.saveSettings(); } catch (error) { console.error('Error refreshing models:', error); // Error already shown by ModelService via Notice