mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-06-09 20:39:25 -03:00
fix(autocomplete): reactively refresh lora syntax format cache on settings change (#917)
The autocomplete module cached the lora_syntax_format value at module load but never updated it when the setting changed, causing autocomplete to always insert legacy A1111 format even when 'full path' was configured. - Expose refreshLoraSyntaxFormat() to re-fetch the setting from the API - Listen for cross-tab 'storage' events to react to settings saved in the standalone web UI - Listen for 'visibilitychange' to refresh when the user switches back to the ComfyUI tab - Wire SettingsManager.saveSetting() to set a localStorage key when lora_syntax_format changes, triggering the storage event
This commit is contained in:
@@ -295,6 +295,13 @@ export class SettingsManager {
|
|||||||
// Update state
|
// Update state
|
||||||
state.global.settings[settingKey] = value;
|
state.global.settings[settingKey] = value;
|
||||||
|
|
||||||
|
if (settingKey === 'lora_syntax_format') {
|
||||||
|
try {
|
||||||
|
localStorage.setItem('lm:lora-syntax-format-changed', Date.now().toString());
|
||||||
|
} catch (_) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.isBackendSetting(settingKey)) {
|
if (!this.isBackendSetting(settingKey)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,14 +105,16 @@ function removeLoraExtension(fileName = '') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let _loraSyntaxFormatCache = null;
|
let _loraSyntaxFormatCache = null;
|
||||||
|
let _loraSyntaxFormatRefreshPromise = null;
|
||||||
|
|
||||||
function _getLoraSyntaxFormat() {
|
function _getLoraSyntaxFormat() {
|
||||||
if (typeof _loraSyntaxFormatCache !== 'undefined' && _loraSyntaxFormatCache !== null) {
|
if (_loraSyntaxFormatCache !== null) {
|
||||||
return _loraSyntaxFormatCache;
|
return _loraSyntaxFormatCache;
|
||||||
}
|
}
|
||||||
return 'legacy';
|
return 'legacy';
|
||||||
}
|
}
|
||||||
async function _initLoraSyntaxFormat() {
|
|
||||||
|
async function _fetchLoraSyntaxFormat() {
|
||||||
try {
|
try {
|
||||||
const response = await api.fetchApi('/lm/settings');
|
const response = await api.fetchApi('/lm/settings');
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
@@ -124,10 +126,44 @@ async function _initLoraSyntaxFormat() {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
}
|
}
|
||||||
|
if (_loraSyntaxFormatCache === null) {
|
||||||
_loraSyntaxFormatCache = 'legacy';
|
_loraSyntaxFormatCache = 'legacy';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _triggerBackgroundRefresh() {
|
||||||
|
if (_loraSyntaxFormatRefreshPromise) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_loraSyntaxFormatRefreshPromise = _fetchLoraSyntaxFormat().finally(() => {
|
||||||
|
_loraSyntaxFormatRefreshPromise = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshLoraSyntaxFormat() {
|
||||||
|
await _fetchLoraSyntaxFormat();
|
||||||
|
}
|
||||||
|
|
||||||
|
function _initLoraSyntaxFormat() {
|
||||||
|
_triggerBackgroundRefresh();
|
||||||
|
}
|
||||||
_initLoraSyntaxFormat();
|
_initLoraSyntaxFormat();
|
||||||
|
|
||||||
|
function _initLoraSyntaxFormatReactive() {
|
||||||
|
window.addEventListener('storage', (e) => {
|
||||||
|
if (e.key === 'lm:lora-syntax-format-changed') {
|
||||||
|
_triggerBackgroundRefresh();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener('visibilitychange', () => {
|
||||||
|
if (document.visibilityState === 'visible') {
|
||||||
|
_triggerBackgroundRefresh();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_initLoraSyntaxFormatReactive();
|
||||||
|
|
||||||
function parseSearchTokens(term = '') {
|
function parseSearchTokens(term = '') {
|
||||||
const include = [];
|
const include = [];
|
||||||
const exclude = [];
|
const exclude = [];
|
||||||
@@ -2791,4 +2827,4 @@ class AutoComplete {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { AutoComplete };
|
export { AutoComplete, refreshLoraSyntaxFormat };
|
||||||
|
|||||||
Reference in New Issue
Block a user