mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 15:15:44 -03:00
feat(extensions): add auto path correction toggle for LoRA Manager, fixes #410
This commit is contained in:
@@ -1,9 +1,17 @@
|
|||||||
|
const settingsStore = new Map();
|
||||||
|
|
||||||
export const app = {
|
export const app = {
|
||||||
canvas: { ds: { scale: 1 } },
|
canvas: { ds: { scale: 1 } },
|
||||||
extensionManager: {
|
extensionManager: {
|
||||||
toast: {
|
toast: {
|
||||||
add: () => {},
|
add: () => {},
|
||||||
},
|
},
|
||||||
|
setting: {
|
||||||
|
get: (id) => (settingsStore.has(id) ? settingsStore.get(id) : undefined),
|
||||||
|
set: async (id, value) => {
|
||||||
|
settingsStore.set(id, value);
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
registerExtension: () => {},
|
registerExtension: () => {},
|
||||||
graphToPrompt: async () => ({ workflow: { nodes: new Map() } }),
|
graphToPrompt: async () => ({ workflow: { nodes: new Map() } }),
|
||||||
|
|||||||
@@ -17,9 +17,48 @@ const PATH_CORRECTION_TARGETS = [
|
|||||||
{ comfyClass: "easy loraStack", widgetNamePattern: "lora_\\d+_name", modelType: "loras" }
|
{ 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
|
// Register the extension
|
||||||
app.registerExtension({
|
app.registerExtension({
|
||||||
name: "LoraManager.UsageStats",
|
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() {
|
setup() {
|
||||||
// Listen for successful executions
|
// Listen for successful executions
|
||||||
@@ -108,6 +147,10 @@ app.registerExtension({
|
|||||||
},
|
},
|
||||||
|
|
||||||
async loadedGraphNode(node) {
|
async loadedGraphNode(node) {
|
||||||
|
if (!getAutoPathCorrectionPreference()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if this node type needs path correction
|
// Check if this node type needs path correction
|
||||||
const target = PATH_CORRECTION_TARGETS.find(t => t.comfyClass === node.comfyClass);
|
const target = PATH_CORRECTION_TARGETS.find(t => t.comfyClass === node.comfyClass);
|
||||||
if (!target) {
|
if (!target) {
|
||||||
|
|||||||
Reference in New Issue
Block a user