From 46126f995007aae93bdc093b7beb5729e7fc7d96 Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Tue, 21 Oct 2025 18:47:42 +0800 Subject: [PATCH] feat(extensions): add auto path correction toggle for LoRA Manager, fixes #410 --- scripts/app.js | 8 +++++++ web/comfyui/usage_stats.js | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/scripts/app.js b/scripts/app.js index 53957e20..6ffbbfd4 100644 --- a/scripts/app.js +++ b/scripts/app.js @@ -1,9 +1,17 @@ +const settingsStore = new Map(); + export const app = { canvas: { ds: { scale: 1 } }, extensionManager: { toast: { add: () => {}, }, + setting: { + get: (id) => (settingsStore.has(id) ? settingsStore.get(id) : undefined), + set: async (id, value) => { + settingsStore.set(id, value); + }, + }, }, registerExtension: () => {}, graphToPrompt: async () => ({ workflow: { nodes: new Map() } }), diff --git a/web/comfyui/usage_stats.js b/web/comfyui/usage_stats.js index d55624c2..da1e2b13 100644 --- a/web/comfyui/usage_stats.js +++ b/web/comfyui/usage_stats.js @@ -17,9 +17,48 @@ 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 @@ -108,6 +147,10 @@ app.registerExtension({ }, async loadedGraphNode(node) { + if (!getAutoPathCorrectionPreference()) { + return; + } + // Check if this node type needs path correction const target = PATH_CORRECTION_TARGETS.find(t => t.comfyClass === node.comfyClass); if (!target) {