API optimizations
This commit is contained in:
+9
-5
@@ -1,5 +1,6 @@
|
||||
import { app } from "/scripts/app.js";
|
||||
import { SettingIds } from "../core/constants.js";
|
||||
import { getSetting } from "../core/settings.js";
|
||||
|
||||
export function findOriginalPropertiesButton() {
|
||||
const byTestId = document.querySelector('[data-testid="properties-panel-toggle"]');
|
||||
@@ -71,6 +72,11 @@ export function findPropertiesPanel() {
|
||||
}
|
||||
|
||||
export function isPropertiesPanelOpen() {
|
||||
const modernOpen = getSetting("Comfy.RightSidePanel.IsOpen");
|
||||
if (typeof modernOpen === "boolean") {
|
||||
return modernOpen;
|
||||
}
|
||||
|
||||
const panel = findPropertiesPanel();
|
||||
if (panel) return true;
|
||||
|
||||
@@ -278,11 +284,9 @@ export function applySidebarOverride() {
|
||||
|
||||
try {
|
||||
const overrideStock = (
|
||||
app.extensionManager?.setting?.get?.(SettingIds.OVERRIDE_STOCK_HISTORY) ??
|
||||
app.ui?.settings?.getSettingValue?.(SettingIds.OVERRIDE_STOCK_HISTORY) ??
|
||||
app.ui?.settings?.getSettingValue?.("Comfy Sidebar.Hide Junk.Override Stock Job History Tab") ??
|
||||
app.ui?.settings?.getSettingValue?.("Comfy Sidebar.Override Stock History") ??
|
||||
false
|
||||
getSetting(SettingIds.OVERRIDE_STOCK_HISTORY) ??
|
||||
getSetting("Comfy Sidebar.Hide Junk.Override Stock Job History Tab") ??
|
||||
getSetting("Comfy Sidebar.Override Stock History", false)
|
||||
);
|
||||
const stdBtn = findStandardQueueButton();
|
||||
const ourBtn = findOurSidebarButton();
|
||||
|
||||
+38
-41
@@ -11,6 +11,7 @@ import {
|
||||
} from "./adapter.js";
|
||||
import { SettingIds } from "../core/constants.js";
|
||||
import { isRuntimePreviewEnabled, setRuntimePreviewEnabled, setRuntimePreviewStateListener } from "../utils/comparison.js";
|
||||
import { getSetting, setSetting } from "../core/settings.js";
|
||||
|
||||
// Listen for runtime preview state changes to keep button UI in sync
|
||||
setRuntimePreviewStateListener(() => {
|
||||
@@ -88,20 +89,11 @@ div:has(> [class*="actionbar"]):not(header):not(.topbar):not(.actionbar-containe
|
||||
export function syncStockHistoryAndProgressSettings(enable) {
|
||||
const dockedVal = !!enable;
|
||||
const progressVal = !enable;
|
||||
const QPOV2_ID = "Comfy.Queue.QPOV2";
|
||||
const progressKey = "Comfy.Queue.ShowRunProgressBar";
|
||||
const QPOV2_ID = SettingIds.DOCK_QUEUE || "Comfy.Queue.QPOV2";
|
||||
const progressKey = SettingIds.SHOW_PROGRESS_BAR || "Comfy.Queue.ShowRunProgressBar";
|
||||
|
||||
if (app.extensionManager?.setting) {
|
||||
try { app.extensionManager.setting.set(QPOV2_ID, dockedVal); } catch (e) {}
|
||||
try { app.extensionManager.setting.set(progressKey, progressVal); } catch (e) {}
|
||||
} else if (app.ui?.settings) {
|
||||
try { app.ui.settings.setSettingValue(QPOV2_ID, dockedVal); } catch (e) {}
|
||||
try { app.ui.settings.setSettingValue(progressKey, progressVal); } catch (e) {}
|
||||
}
|
||||
|
||||
try { localStorage.setItem(QPOV2_ID, JSON.stringify(dockedVal)); } catch (e) {}
|
||||
try { localStorage.setItem(progressKey, JSON.stringify(progressVal)); } catch (e) {}
|
||||
try { window.dispatchEvent(new Event("storage")); } catch (e) {}
|
||||
setSetting(QPOV2_ID, dockedVal);
|
||||
setSetting(progressKey, progressVal);
|
||||
}
|
||||
|
||||
let savedButtonData = null;
|
||||
@@ -128,6 +120,11 @@ function setupSidebarTopObserver() {
|
||||
}
|
||||
|
||||
function isSidebarOnLeft() {
|
||||
const location = getSetting("Comfy.Sidebar.Location");
|
||||
if (location === "left" || location === "right") {
|
||||
return location === "left";
|
||||
}
|
||||
|
||||
const sidebar = document.querySelector('.comfyui-sidebar, .comfy-sidebar, .sidebar, [class*="sidebar-nav"], [class*="sidebar"]');
|
||||
if (!sidebar) return false;
|
||||
return sidebar.getBoundingClientRect().left < window.innerWidth / 2;
|
||||
@@ -425,11 +422,7 @@ export function applyClassicLayout(enable, updateSetting = false) {
|
||||
|
||||
if (enable) {
|
||||
if (updateSetting) {
|
||||
if (app.extensionManager?.setting) {
|
||||
app.extensionManager.setting.set("Comfy.Workflow.WorkflowTabsPosition", "Topbar");
|
||||
} else if (app.ui?.settings) {
|
||||
app.ui.settings.setSettingValue("Comfy.Workflow.WorkflowTabsPosition", "Topbar");
|
||||
}
|
||||
setSetting("Comfy.Workflow.WorkflowTabsPosition", "Topbar");
|
||||
}
|
||||
if (!styleEl) {
|
||||
styleEl = document.createElement("style");
|
||||
@@ -453,7 +446,7 @@ export function applyClassicLayout(enable, updateSetting = false) {
|
||||
}
|
||||
|
||||
function syncAvatarVisibility() {
|
||||
const hideAvatar = app.ui?.settings?.getSettingValue("Comfy Sidebar.Hide Junk.Avatar") ?? false;
|
||||
const hideAvatar = getSetting("Comfy Sidebar.Hide Junk.Avatar", false);
|
||||
const STYLE_AVATAR_ID = "comfy-sidebar-hide-avatar-override";
|
||||
let styleEl = document.getElementById(STYLE_AVATAR_ID);
|
||||
|
||||
@@ -501,7 +494,7 @@ function updateSidebarTabsVisibility() {
|
||||
};
|
||||
|
||||
Object.entries(tabSelectors).forEach(([tab, selector]) => {
|
||||
const shouldHide = app.ui?.settings?.getSettingValue(`Comfy Sidebar.Hide Junk.${tab}`) ?? false;
|
||||
const shouldHide = getSetting(`Comfy Sidebar.Hide Junk.${tab}`, false);
|
||||
const target = sidebar.querySelector(selector);
|
||||
if (target) {
|
||||
const tabBtn = target.closest('.comfyui-sidebar-tab, button, [role="tab"], li, a, .comfyui-sidebar-item') || target;
|
||||
@@ -514,11 +507,9 @@ function updateSidebarTabsVisibility() {
|
||||
});
|
||||
|
||||
const hideStockHistory = (
|
||||
app.extensionManager?.setting?.get?.(SettingIds.OVERRIDE_STOCK_HISTORY) ??
|
||||
app.ui?.settings?.getSettingValue?.(SettingIds.OVERRIDE_STOCK_HISTORY) ??
|
||||
app.ui?.settings?.getSettingValue?.("Comfy Sidebar.Hide Junk.Override Stock Job History Tab") ??
|
||||
app.ui?.settings?.getSettingValue?.("Comfy Sidebar.Override Stock History") ??
|
||||
false
|
||||
getSetting(SettingIds.OVERRIDE_STOCK_HISTORY) ??
|
||||
getSetting("Comfy Sidebar.Hide Junk.Override Stock Job History Tab") ??
|
||||
getSetting("Comfy Sidebar.Override Stock History", false)
|
||||
);
|
||||
const historyTarget = sidebar.querySelector('[data-testid="queue-tab-button"], [data-testid="job-history-tab-button"], [class*="lucide--history"]');
|
||||
if (historyTarget) {
|
||||
@@ -558,7 +549,7 @@ function cleanHTML(html) {
|
||||
}
|
||||
|
||||
function syncGraphButton() {
|
||||
const hideGraphBtn = app.ui?.settings?.getSettingValue("Comfy Sidebar.Hide Junk.Graph Button") ?? false;
|
||||
const hideGraphBtn = getSetting("Comfy Sidebar.Hide Junk.Graph Button", false);
|
||||
const graphBtn = findGraphButton();
|
||||
if (graphBtn) {
|
||||
if (hideGraphBtn) {
|
||||
@@ -653,11 +644,17 @@ function syncPropertiesButton(isClassicLayoutEnabled) {
|
||||
customBtn.addEventListener("click", (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
const nativeBtn = findOriginalPropertiesButton();
|
||||
if (nativeBtn) {
|
||||
nativeBtn.click();
|
||||
|
||||
const isOpen = getSetting("Comfy.RightSidePanel.IsOpen");
|
||||
if (typeof isOpen === "boolean") {
|
||||
setSetting("Comfy.RightSidePanel.IsOpen", !isOpen);
|
||||
requestAnimationFrame(() => syncClassicLayout());
|
||||
} else {
|
||||
const nativeBtn = findOriginalPropertiesButton();
|
||||
if (nativeBtn) {
|
||||
nativeBtn.click();
|
||||
requestAnimationFrame(() => syncClassicLayout());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -674,7 +671,7 @@ function syncPropertiesButton(isClassicLayoutEnabled) {
|
||||
}
|
||||
|
||||
function syncActiveQueueIndicator(isClassicLayoutEnabled) {
|
||||
const hideQueueIndicator = app.ui?.settings?.getSettingValue("Comfy Sidebar.Hide Junk.Override Stock Job History Tab") ?? false;
|
||||
const hideQueueIndicator = getSetting("Comfy Sidebar.Hide Junk.Override Stock Job History Tab", false);
|
||||
const indicator = findActiveQueueIndicator();
|
||||
if (indicator) {
|
||||
if (isClassicLayoutEnabled && hideQueueIndicator) {
|
||||
@@ -769,24 +766,19 @@ export function syncClassicLayout() {
|
||||
if (domObserver) domObserver.disconnect();
|
||||
|
||||
try {
|
||||
const isClassicLayoutEnabled = app.ui?.settings?.getSettingValue("Comfy Sidebar.Comfy Layout") ?? false;
|
||||
const tabsPos = app.extensionManager?.setting?.get?.("Comfy.Workflow.WorkflowTabsPosition") ??
|
||||
app.ui?.settings?.getSettingValue("Comfy.Workflow.WorkflowTabsPosition");
|
||||
const isClassicLayoutEnabled = getSetting("Comfy Sidebar.Comfy Layout", false);
|
||||
const tabsPos = getSetting("Comfy.Workflow.WorkflowTabsPosition");
|
||||
|
||||
// Real-time safeguard: if tabs are in Sidebar, disable Comfy Layout immediately
|
||||
if (isClassicLayoutEnabled && tabsPos === "Sidebar") {
|
||||
applyClassicLayout(false, false);
|
||||
if (app.extensionManager?.setting) {
|
||||
try { app.extensionManager.setting.set("Comfy Sidebar.Comfy Layout", false); } catch (e) {}
|
||||
} else if (app.ui?.settings) {
|
||||
try { app.ui.settings.setSettingValue("Comfy Sidebar.Comfy Layout", false); } catch (e) {}
|
||||
}
|
||||
setSetting("Comfy Sidebar.Comfy Layout", false);
|
||||
return;
|
||||
}
|
||||
|
||||
let canvasControlsMode = app.ui?.settings?.getSettingValue("Comfy Sidebar.Hide Junk.Floating Canvas Controls");
|
||||
let canvasControlsMode = getSetting("Comfy Sidebar.Hide Junk.Floating Canvas Controls");
|
||||
if (canvasControlsMode === undefined || canvasControlsMode === null) {
|
||||
const legacyDock = app.ui?.settings?.getSettingValue("Comfy Sidebar.Dock Canvas Controls");
|
||||
const legacyDock = getSetting("Comfy Sidebar.Dock Canvas Controls");
|
||||
canvasControlsMode = legacyDock ? "Dock" : "Default";
|
||||
} else if (typeof canvasControlsMode === "boolean") {
|
||||
canvasControlsMode = canvasControlsMode ? "Dock" : "Default";
|
||||
@@ -961,14 +953,19 @@ export function setupPropertiesPanelToggleFix() {
|
||||
}
|
||||
|
||||
/* Neutralize CanvasModeSelector inner selected backgrounds so idle mode is clean and transparent */
|
||||
.comfy-sidebar-unfloated-canvas-menu [class*="bg-muted"],
|
||||
.comfy-sidebar-unfloated-canvas-menu [class*="group-hover:bg-accent"],
|
||||
.comfy-sidebar-unfloated-canvas-menu > button div,
|
||||
.comfy-sidebar-unfloated-canvas-menu > div div,
|
||||
.comfy-sidebar-unfloated-canvas-menu > div button,
|
||||
.comfy-sidebar-unfloated-canvas-menu > div [role="button"],
|
||||
.comfy-sidebar-unfloated-canvas-menu [class*="bg-interface-panel-selected-surface"],
|
||||
.comfy-sidebar-unfloated-canvas-menu [class*="group-hover:bg-interface-button-hover-surface"] {
|
||||
background: transparent !important;
|
||||
background-color: transparent !important;
|
||||
border-radius: 0 !important;
|
||||
box-shadow: none !important;
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
/* Compact CanvasModeSelector padding and chevrons to eliminate extra sidebar width and ensure full-width highlight */
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { app } from "/scripts/app.js";
|
||||
|
||||
/**
|
||||
* Safely retrieves a setting value from ComfyUI's extension manager or legacy settings.
|
||||
*/
|
||||
export function getSetting(id, fallback = undefined) {
|
||||
const settings = app.extensionManager?.setting;
|
||||
if (settings?.get) {
|
||||
const val = settings.get(id);
|
||||
if (val !== undefined && val !== null) return val;
|
||||
}
|
||||
const legacyVal = app.ui?.settings?.getSettingValue?.(id);
|
||||
if (legacyVal !== undefined && legacyVal !== null) return legacyVal;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely sets a setting value across modern extensionManager and legacy UI settings.
|
||||
*/
|
||||
export function setSetting(id, value) {
|
||||
const settings = app.extensionManager?.setting;
|
||||
if (settings?.set) {
|
||||
settings.set(id, value);
|
||||
return;
|
||||
}
|
||||
app.ui?.settings?.setSettingValue?.(id, value);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { createPromptState, activatePrompt, updatePromptProgress } from "../core
|
||||
import { syncQueue, concludeRun, initSessionAndHistory, clearCancelledOrFailed } from "./queueService.js";
|
||||
import { findImagesInOutputs, findTextsInOutputs } from "../utils/utils.js";
|
||||
import { updateActiveComparisonPreview, isRuntimePreviewEnabled, focusRuntimePreviewTarget, getActiveComparisonViewer, showFullscreenPreview } from "../utils/comparison.js";
|
||||
import { getSetting } from "../core/settings.js";
|
||||
|
||||
export function setupExecutionTracker(onTargetedProgressUpdate) {
|
||||
const onStatus = () => syncQueue();
|
||||
@@ -17,7 +18,7 @@ export function setupExecutionTracker(onTargetedProgressUpdate) {
|
||||
};
|
||||
|
||||
const onExecutionStart = (e) => {
|
||||
const autoClear = app.ui?.settings?.getSettingValue?.("Comfy Sidebar.Auto Clear Interrupted") ?? false;
|
||||
const autoClear = getSetting(SettingIds.AUTO_CLEAR_INTERRUPTED, false);
|
||||
if (autoClear) {
|
||||
clearCancelledOrFailed();
|
||||
}
|
||||
@@ -70,7 +71,7 @@ export function setupExecutionTracker(onTargetedProgressUpdate) {
|
||||
|
||||
const onExecuting = (e) => {
|
||||
const nodeId = e.detail;
|
||||
const showWorkingNode = app.ui?.settings?.getSettingValue?.("Comfy Sidebar.Show Working Node Name") ?? true;
|
||||
const showWorkingNode = getSetting(SettingIds.SHOW_WORKING_NODE_NAME, true);
|
||||
const activePid = store.ui.currentlyActivePromptId;
|
||||
|
||||
if (activePid && store.hasPrompt(activePid)) {
|
||||
|
||||
+55
-128
@@ -13,11 +13,50 @@ import { setupGalleryView, teardownGalleryView } from "./ui/galleryView.js";
|
||||
import { initI18n, t } from "./core/i18n.js";
|
||||
import { updateCardProgressTargeted, cardPool } from "./ui/cardRenderer.js";
|
||||
import { store } from "./core/store.js";
|
||||
import { getSetting, setSetting } from "./core/settings.js";
|
||||
|
||||
let isInitialized = false;
|
||||
let activeKeydownHandler = null;
|
||||
let cleanupFns = [];
|
||||
|
||||
function setupKeydownShortcuts() {
|
||||
activeKeydownHandler = (e) => {
|
||||
const activeEl = document.activeElement;
|
||||
if (activeEl && (
|
||||
activeEl.tagName === "INPUT" ||
|
||||
activeEl.tagName === "TEXTAREA" ||
|
||||
activeEl.isContentEditable ||
|
||||
activeEl.tagName === "SELECT"
|
||||
)) return;
|
||||
|
||||
if (e.key.toLowerCase() === "q" && !e.ctrlKey && !e.metaKey && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (app.extensionManager?.command?.hasCommand?.("Workspace.ToggleSidebarTab.classic-comfy-sidebar")) {
|
||||
app.extensionManager.command.execute("Workspace.ToggleSidebarTab.classic-comfy-sidebar");
|
||||
} else {
|
||||
const ourBtn = findOurSidebarButton();
|
||||
if (ourBtn) ourBtn.click();
|
||||
}
|
||||
}
|
||||
|
||||
if (e.key.toLowerCase() === "q" && (e.ctrlKey || e.metaKey) && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
toggleIgnoreActiveNode(() => renderSidebar());
|
||||
}
|
||||
|
||||
// Alt+R: Renumber all nodes in execution order
|
||||
if (e.key.toLowerCase() === "r" && e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
renumberNodesTopologically();
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener("keydown", activeKeydownHandler, true);
|
||||
}
|
||||
|
||||
function registerSettings() {
|
||||
app.ui.settings.addSetting({
|
||||
id: SettingIds.GRID_COLUMNS_THRESHOLD,
|
||||
@@ -154,104 +193,6 @@ function registerSettings() {
|
||||
});
|
||||
}
|
||||
|
||||
function setupSettingsDialogObserver() {
|
||||
const targetTexts = [
|
||||
"Grid Columns Threshold",
|
||||
"Show Pending Count Only",
|
||||
"Show Working Node Name",
|
||||
"Auto Clear Interrupted",
|
||||
"Permanent Delete on Disk Deletion",
|
||||
"Hide Junk",
|
||||
"Override Stock History",
|
||||
"Hide Graph Button",
|
||||
"Hide Avatar",
|
||||
"Floating Canvas Controls",
|
||||
"Classic Layout",
|
||||
"Comfy Layout",
|
||||
"Default",
|
||||
"Dock",
|
||||
"Hide"
|
||||
];
|
||||
|
||||
const translateDOM = (rootEl) => {
|
||||
if (!rootEl) return;
|
||||
const walker = document.createTreeWalker(
|
||||
rootEl,
|
||||
NodeFilter.SHOW_TEXT,
|
||||
{
|
||||
acceptNode(node) {
|
||||
const text = node.nodeValue?.trim();
|
||||
return targetTexts.includes(text) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const nodesToTranslate = [];
|
||||
while (walker.nextNode()) {
|
||||
nodesToTranslate.push(walker.currentNode);
|
||||
}
|
||||
|
||||
for (const textNode of nodesToTranslate) {
|
||||
const raw = textNode.nodeValue.trim();
|
||||
const translated = t(raw);
|
||||
if (translated && translated !== raw) {
|
||||
textNode.nodeValue = textNode.nodeValue.replace(raw, translated);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const observer = new MutationObserver(() => {
|
||||
// 1. Translate headers and selected value inside the Settings dialog
|
||||
const dialog = document.querySelector('.p-dialog, .comfy-settings-dialog, [role="dialog"]');
|
||||
if (dialog) {
|
||||
translateDOM(dialog);
|
||||
}
|
||||
|
||||
// 2. Translate dropdown popup menu items (floated directly on document.body)
|
||||
const overlay = document.querySelector('.p-select-overlay, .p-dropdown-panel, .p-select-list, [data-pc-name="selectoverlay"]');
|
||||
if (overlay) {
|
||||
translateDOM(overlay);
|
||||
}
|
||||
});
|
||||
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
return () => observer.disconnect();
|
||||
}
|
||||
|
||||
function setupKeydownShortcuts() {
|
||||
activeKeydownHandler = (e) => {
|
||||
const activeEl = document.activeElement;
|
||||
if (activeEl && (
|
||||
activeEl.tagName === "INPUT" ||
|
||||
activeEl.tagName === "TEXTAREA" ||
|
||||
activeEl.isContentEditable ||
|
||||
activeEl.tagName === "SELECT"
|
||||
)) return;
|
||||
|
||||
if (e.key.toLowerCase() === "q" && !e.ctrlKey && !e.metaKey && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const ourBtn = findOurSidebarButton();
|
||||
if (ourBtn) ourBtn.click();
|
||||
}
|
||||
|
||||
if (e.key.toLowerCase() === "q" && (e.ctrlKey || e.metaKey) && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
toggleIgnoreActiveNode(() => renderSidebar());
|
||||
}
|
||||
|
||||
// Alt+R: Renumber all nodes in execution order
|
||||
if (e.key.toLowerCase() === "r" && e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
renumberNodesTopologically();
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener("keydown", activeKeydownHandler, true);
|
||||
}
|
||||
|
||||
function setupWorkflowTabsPositionWatcher() {
|
||||
let isSyncing = false;
|
||||
const TARGET_SETTING = "Comfy.Workflow.WorkflowTabsPosition";
|
||||
@@ -259,15 +200,11 @@ function setupWorkflowTabsPositionWatcher() {
|
||||
const checkAndDisableIfSidebar = (val) => {
|
||||
if (isSyncing) return;
|
||||
if (val === "Sidebar") {
|
||||
const isClassicEnabled = app.ui?.settings?.getSettingValue(SettingIds.CLASSIC_LAYOUT) ?? false;
|
||||
const isClassicEnabled = getSetting(SettingIds.CLASSIC_LAYOUT, false);
|
||||
if (isClassicEnabled) {
|
||||
isSyncing = true;
|
||||
try {
|
||||
if (app.extensionManager?.setting) {
|
||||
try { app.extensionManager.setting.set(SettingIds.CLASSIC_LAYOUT, false); } catch (e) {}
|
||||
} else if (app.ui?.settings) {
|
||||
try { app.ui.settings.setSettingValue(SettingIds.CLASSIC_LAYOUT, false); } catch (e) {}
|
||||
}
|
||||
setSetting(SettingIds.CLASSIC_LAYOUT, false);
|
||||
applyClassicLayout(false, false);
|
||||
} finally {
|
||||
isSyncing = false;
|
||||
@@ -278,7 +215,6 @@ function setupWorkflowTabsPositionWatcher() {
|
||||
|
||||
const cleanups = [];
|
||||
|
||||
// 1. Hook the setting's native onChange callback directly (instant execution on click)
|
||||
const attachNativeOnChange = (settingObj) => {
|
||||
if (!settingObj || settingObj._classicWatcherAttached) return;
|
||||
settingObj._classicWatcherAttached = true;
|
||||
@@ -293,23 +229,19 @@ function setupWorkflowTabsPositionWatcher() {
|
||||
});
|
||||
};
|
||||
|
||||
// Check existing registered setting in legacy UI and modern extension manager
|
||||
attachNativeOnChange(app.ui?.settings?.settings?.[TARGET_SETTING]);
|
||||
attachNativeOnChange(app.extensionManager?.setting?.getSetting?.(TARGET_SETTING));
|
||||
attachNativeOnChange(app.extensionManager?.setting?.settings?.[TARGET_SETTING]);
|
||||
|
||||
// 2. Hook Vue/Pinia reactive store subscription if available (zero polling, synchronous)
|
||||
const settingStore = app.extensionManager?.setting?.settingStore;
|
||||
if (settingStore?.$subscribe) {
|
||||
const unsubscribe = settingStore.$subscribe(() => {
|
||||
const val = app.extensionManager?.setting?.get?.(TARGET_SETTING) ??
|
||||
app.ui?.settings?.getSettingValue(TARGET_SETTING);
|
||||
const val = getSetting(TARGET_SETTING);
|
||||
checkAndDisableIfSidebar(val);
|
||||
});
|
||||
cleanups.push(unsubscribe);
|
||||
}
|
||||
|
||||
// 3. Hook addSetting in case core registers/re-registers the setting later
|
||||
if (app.ui?.settings?.addSetting) {
|
||||
const origAdd = app.ui.settings.addSetting.bind(app.ui.settings);
|
||||
app.ui.settings.addSetting = (setting) => {
|
||||
@@ -323,7 +255,6 @@ function setupWorkflowTabsPositionWatcher() {
|
||||
});
|
||||
}
|
||||
|
||||
// 4. Hook API setters as fallback
|
||||
if (app.ui?.settings?.setSettingValue) {
|
||||
const origSetSettingValue = app.ui.settings.setSettingValue.bind(app.ui.settings);
|
||||
app.ui.settings.setSettingValue = (id, value) => {
|
||||
@@ -364,8 +295,12 @@ app.registerExtension({
|
||||
id: "ComfySidebar.ToggleSidebar",
|
||||
label: t("Toggle Comfy Queue Sidebar"),
|
||||
function: () => {
|
||||
const ourBtn = findOurSidebarButton();
|
||||
if (ourBtn) ourBtn.click();
|
||||
if (app.extensionManager?.command?.hasCommand?.("Workspace.ToggleSidebarTab.classic-comfy-sidebar")) {
|
||||
app.extensionManager.command.execute("Workspace.ToggleSidebarTab.classic-comfy-sidebar");
|
||||
} else {
|
||||
const ourBtn = findOurSidebarButton();
|
||||
if (ourBtn) ourBtn.click();
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -423,23 +358,17 @@ app.registerExtension({
|
||||
if (!app.extensionManager || !app.extensionManager.registerSidebarTab) return;
|
||||
await initI18n();
|
||||
|
||||
const tabsPos = app.extensionManager?.setting?.get?.("Comfy.Workflow.WorkflowTabsPosition") ??
|
||||
app.ui.settings.getSettingValue("Comfy.Workflow.WorkflowTabsPosition");
|
||||
let isClassicLayoutEnabled = app.ui.settings.getSettingValue(SettingIds.CLASSIC_LAYOUT) ?? false;
|
||||
const tabsPos = getSetting("Comfy.Workflow.WorkflowTabsPosition");
|
||||
let isClassicLayoutEnabled = getSetting(SettingIds.CLASSIC_LAYOUT, false);
|
||||
|
||||
// Startup safeguard: if workflows are set to Sidebar, disable Comfy Layout
|
||||
if (isClassicLayoutEnabled && tabsPos === "Sidebar") {
|
||||
isClassicLayoutEnabled = false;
|
||||
if (app.extensionManager?.setting) {
|
||||
try { app.extensionManager.setting.set(SettingIds.CLASSIC_LAYOUT, false); } catch (e) {}
|
||||
} else if (app.ui?.settings) {
|
||||
try { app.ui.settings.setSettingValue(SettingIds.CLASSIC_LAYOUT, false); } catch (e) {}
|
||||
}
|
||||
setSetting(SettingIds.CLASSIC_LAYOUT, false);
|
||||
}
|
||||
|
||||
applyClassicLayout(isClassicLayoutEnabled, false);
|
||||
|
||||
const isHistoryOverrideEnabled = app.ui.settings.getSettingValue(SettingIds.OVERRIDE_STOCK_HISTORY) ?? false;
|
||||
const isHistoryOverrideEnabled = getSetting(SettingIds.OVERRIDE_STOCK_HISTORY, false);
|
||||
if (isHistoryOverrideEnabled) {
|
||||
syncStockHistoryAndProgressSettings(true);
|
||||
}
|
||||
@@ -452,14 +381,12 @@ app.registerExtension({
|
||||
cleanupFns.push(setupWorkflowTabsPositionWatcher());
|
||||
cleanupFns.push(setupDragAndDrop());
|
||||
cleanupFns.push(setupVueNodeObserver());
|
||||
cleanupFns.push(setupSettingsDialogObserver());
|
||||
|
||||
// Setup execution tracker with targeted fast-path update for active card
|
||||
cleanupFns.push(setupExecutionTracker((pid, progress, nodeName) => {
|
||||
const cardObj = cardPool.get(pid);
|
||||
const state = store.getPrompt(pid);
|
||||
if (cardObj && state) {
|
||||
const showWorkingNode = app.ui.settings.getSettingValue(SettingIds.SHOW_WORKING_NODE_NAME) ?? true;
|
||||
const showWorkingNode = getSetting(SettingIds.SHOW_WORKING_NODE_NAME, true);
|
||||
updateCardProgressTargeted(cardObj, progress, nodeName, showWorkingNode, state);
|
||||
} else {
|
||||
renderSidebar();
|
||||
@@ -527,7 +454,7 @@ app.registerExtension({
|
||||
}
|
||||
});
|
||||
|
||||
const isGalleryEnabled = app.ui.settings.getSettingValue("Comfy Sidebar.Enable Gallery") ?? true;
|
||||
const isGalleryEnabled = getSetting("Comfy Sidebar.Enable Gallery", true);
|
||||
if (!isGalleryEnabled) {
|
||||
setTimeout(() => setGalleryButtonVisible(false), 50);
|
||||
}
|
||||
@@ -558,4 +485,4 @@ app.registerExtension({
|
||||
app.extensionManager.unregisterSidebarTab("classic-comfy-sidebar");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user