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
This commit is contained in:
1 file changed
+20
-3
+20
-3
@@ -176,9 +176,9 @@ export class FreewritingPromptsSettingTab extends PluginSettingTab {
|
|||||||
if (this.availableModels.length > 0) {
|
if (this.availableModels.length > 0) {
|
||||||
dropdown.setValue(this.plugin.settings.model);
|
dropdown.setValue(this.plugin.settings.model);
|
||||||
}
|
}
|
||||||
dropdown.onChange(async (value) => {
|
dropdown.onChange((value) => {
|
||||||
this.plugin.settings.model = 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');
|
const notice = new Notice('Cache cleared');
|
||||||
setTimeout(() => notice.hide(), 2000);
|
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
|
// MARK: - Model Loading
|
||||||
@@ -338,7 +350,12 @@ export class FreewritingPromptsSettingTab extends PluginSettingTab {
|
|||||||
} else {
|
} else {
|
||||||
// Fall back to first available model if current one is gone
|
// Fall back to first available model if current one is gone
|
||||||
const fallbackModel = this.availableModels[0];
|
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.modelDropdown.setValue(fallbackModel.id);
|
||||||
this.plugin.settings.model = fallbackModel.id;
|
this.plugin.settings.model = fallbackModel.id;
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
|
|||||||
Reference in new issue
Block a user