feat: consolidate ComfyUI settings and add custom words autocomplete toggle

Create unified settings.js extension to centralize all Lora Manager ComfyUI
settings registration, eliminating code duplication across multiple files.

Add new setting "Enable Custom Words Autocomplete in Prompt Nodes" (enabled
by default) to control custom words autocomplete in prompt node text widgets.
When disabled, only 'emb:' prefix triggers embeddings autocomplete.

Changes:
- Create web/comfyui/settings.js with all three settings:
  * Trigger Word Wheel Sensitivity (existing)
  * Auto path correction (existing)
  * Enable Custom Words Autocomplete in Prompt Nodes (new)
- Refactor autocomplete.js to respect the new setting
- Update trigger_word_toggle.js to import from settings.js
- Update usage_stats.js to import from settings.js
This commit is contained in:
Will Miao
2026-01-25 12:53:41 +08:00
parent d5a2bd1e24
commit 6142b3dc0c
4 changed files with 151 additions and 89 deletions

View File

@@ -2,6 +2,7 @@
import { app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js";
import { showToast } from "./utils.js";
import { getAutoPathCorrectionPreference } from "./settings.js";
// Define target nodes and their widget configurations
const PATH_CORRECTION_TARGETS = [
@@ -17,48 +18,9 @@ const PATH_CORRECTION_TARGETS = [
{ comfyClass: "easy loraStack", widgetNamePattern: "lora_\\d+_name", modelType: "loras" }
];
const AUTO_PATH_CORRECTION_SETTING_ID = "loramanager.auto_path_correction";
const AUTO_PATH_CORRECTION_DEFAULT = true;
const getAutoPathCorrectionPreference = (() => {
let settingsUnavailableLogged = false;
return () => {
const settingManager = app?.extensionManager?.setting;
if (!settingManager || typeof settingManager.get !== "function") {
if (!settingsUnavailableLogged) {
console.warn("LoRA Manager: settings API unavailable, defaulting auto path correction to enabled.");
settingsUnavailableLogged = true;
}
return AUTO_PATH_CORRECTION_DEFAULT;
}
try {
const value = settingManager.get(AUTO_PATH_CORRECTION_SETTING_ID);
return value ?? AUTO_PATH_CORRECTION_DEFAULT;
} catch (error) {
if (!settingsUnavailableLogged) {
console.warn("LoRA Manager: unable to read auto path correction setting, defaulting to enabled.", error);
settingsUnavailableLogged = true;
}
return AUTO_PATH_CORRECTION_DEFAULT;
}
};
})();
// Register the extension
app.registerExtension({
name: "LoraManager.UsageStats",
settings: [
{
id: AUTO_PATH_CORRECTION_SETTING_ID,
name: "Auto path correction",
type: "boolean",
defaultValue: AUTO_PATH_CORRECTION_DEFAULT,
tooltip: "Automatically update model paths to their current file locations.",
category: ["LoRA Manager", "Automation", "Auto path correction"],
},
],
setup() {
// Listen for successful executions