diff --git a/settings.ts b/settings.ts index 6fd9ee0..b59908d 100644 --- a/settings.ts +++ b/settings.ts @@ -245,15 +245,18 @@ export class FreewritingPromptsSettingTab extends PluginSettingTab { const modelExists = this.availableModels.some(m => m.id === currentModel); if (modelExists) { this.modelDropdown.setValue(currentModel); - } else if (this.availableModels.length > 0) { + } else { // Fall back to first available model if current one is gone - this.plugin.settings.model = this.availableModels[0].id; - this.modelDropdown.setValue(this.availableModels[0].id); - new Notice('Your selected model is no longer available. Defaulting to ' + this.availableModels[0].displayName); + const fallbackModel = this.availableModels[0]; + if (fallbackModel) { + this.modelDropdown.setValue(fallbackModel.id); + this.plugin.settings.model = fallbackModel.id; + new Notice('Your selected model is no longer available. Defaulting to ' + fallbackModel.displayName); + } } } - // Save updated cache + // Persist any selection changes await this.plugin.saveSettings(); } catch (error) { console.error('Error refreshing models:', error);