mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 15:15:44 -03:00
feat(sidebar): add force initialization option and improve state management
- Add `forceInitialize` option to sidebar initialization to bypass disabled setting - Refactor sidebar toggle logic to handle initialization promises more reliably - Improve cleanup behavior when sidebar is disabled - Ensure proper DOM updates when sidebar state changes - Maintain container layout consistency during sidebar operations
This commit is contained in:
@@ -62,8 +62,10 @@ export class SidebarManager {
|
|||||||
this.lastPageControls = pageControls;
|
this.lastPageControls = pageControls;
|
||||||
}
|
}
|
||||||
|
|
||||||
async initialize(pageControls) {
|
async initialize(pageControls, options = {}) {
|
||||||
if (this.isDisabledBySetting) {
|
const { forceInitialize = false } = options;
|
||||||
|
|
||||||
|
if (this.isDisabledBySetting && !forceInitialize) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +87,7 @@ export class SidebarManager {
|
|||||||
this.updateSidebarTitle();
|
this.updateSidebarTitle();
|
||||||
this.restoreSidebarState();
|
this.restoreSidebarState();
|
||||||
await this.loadFolderTree();
|
await this.loadFolderTree();
|
||||||
if (this.isDisabledBySetting) {
|
if (this.isDisabledBySetting && !forceInitialize) {
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -773,17 +775,39 @@ export class SidebarManager {
|
|||||||
this.isDisabledBySetting = !enabled;
|
this.isDisabledBySetting = !enabled;
|
||||||
this.updateDomVisibility(enabled);
|
this.updateDomVisibility(enabled);
|
||||||
|
|
||||||
|
const shouldForceInitialization = !enabled && !this.isInitialized;
|
||||||
|
const needsInitialization = !this.isInitialized || shouldForceInitialization;
|
||||||
|
|
||||||
|
if (this.lastPageControls && needsInitialization) {
|
||||||
|
if (!this.initializationPromise) {
|
||||||
|
this.initializationPromise = this.initialize(this.lastPageControls, {
|
||||||
|
forceInitialize: shouldForceInitialization,
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('Sidebar initialization failed:', error);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
this.initializationPromise = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.initializationPromise;
|
||||||
|
} else if (this.initializationPromise) {
|
||||||
|
await this.initializationPromise;
|
||||||
|
}
|
||||||
|
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
this.isHovering = false;
|
this.isHovering = false;
|
||||||
this.isVisible = false;
|
this.isVisible = false;
|
||||||
|
|
||||||
|
const container = document.querySelector('.container');
|
||||||
|
if (container) {
|
||||||
|
container.style.marginLeft = '';
|
||||||
|
}
|
||||||
|
|
||||||
if (this.isInitialized) {
|
if (this.isInitialized) {
|
||||||
this.cleanup();
|
this.updateBreadcrumbs();
|
||||||
} else {
|
this.updateSidebarHeader();
|
||||||
const container = document.querySelector('.container');
|
|
||||||
if (container) {
|
|
||||||
container.style.marginLeft = '';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -791,24 +815,7 @@ export class SidebarManager {
|
|||||||
|
|
||||||
if (this.isInitialized) {
|
if (this.isInitialized) {
|
||||||
this.updateAutoHideState();
|
this.updateAutoHideState();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.lastPageControls) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.initializationPromise) {
|
|
||||||
this.initializationPromise = this.initialize(this.lastPageControls)
|
|
||||||
.catch((error) => {
|
|
||||||
console.error('Sidebar initialization failed:', error);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
this.initializationPromise = null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.initializationPromise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePinButton() {
|
updatePinButton() {
|
||||||
|
|||||||
Reference in New Issue
Block a user