Merge pull request #22 from ilian6806/develop

Added extra networks support
pull/30/head
Ilian Iliev 2023-04-11 13:25:08 +03:00 committed by GitHub
commit 4cc8fa3ca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 28 deletions

View File

@ -38,6 +38,10 @@ state.core = (function () {
'styles': 'styles'
};
const TOGGLE_BUTTONS = {
'extra_networks': 'extra_networks',
};
let store = null;
function hasSetting(id, tab) {
@ -59,6 +63,16 @@ state.core = (function () {
.catch(error => console.error('[state]: Error getting JSON file:', error));
}
function forEachElement(list, config, action) {
for (const [settingId, element] of Object.entries(list)) {
TABS.forEach(tab => {
if (config.hasSetting(settingId, tab)) {
action(element, tab);
}
});
}
}
function load(config) {
store = new state.Store();
@ -66,37 +80,25 @@ state.core = (function () {
loadUI();
restoreTabs(config);
for (const [settingId, element] of Object.entries(ELEMENTS)) {
TABS.forEach(tab => {
if (config.hasSetting(settingId, tab)) {
forEachElement(ELEMENTS, config, (element, tab) => {
handleSavedInput(`${tab}_${element}`);
}
});
}
for (const [settingId, element] of Object.entries(ELEMENTS_WITHOUT_PREFIX)) {
TABS.forEach(tab => {
if (config.hasSetting(settingId, tab)) {
forEachElement(ELEMENTS_WITHOUT_PREFIX, config, (element, tab) => {
handleSavedInput(`${element}`);
}
});
}
for (const [settingId, element] of Object.entries(SELECTS)) {
TABS.forEach(tab => {
if (config.hasSetting(settingId, tab)) {
forEachElement(SELECTS, config, (element, tab) => {
handleSavedSelects(`${tab}_${element}`);
}
});
}
for (const [settingId, element] of Object.entries(MULTI_SELECTS)) {
TABS.forEach(tab => {
if (config.hasSetting(settingId, tab)) {
forEachElement(MULTI_SELECTS, config, (element, tab) => {
handleSavedMultiSelects(`${tab}_${element}`);
}
});
}
forEachElement(TOGGLE_BUTTONS, config, (element, tab) => {
handleToggleButton(`${tab}_${element}`);
});
handleExtensions(config);
handleSettingsPage();
@ -208,6 +210,17 @@ state.core = (function () {
state.utils.handleMultipleSelect(select, id, store);
}
function handleToggleButton(id) {
const btn = gradioApp().querySelector(`button#${id}`);
if (! btn) { return; }
if (store.get(id) === 'true') {
state.utils.triggerMouseEvent(btn);
}
btn.addEventListener('click', function () {
store.set(id, Array.from(this.classList).indexOf('secondary-down') === -1);
});
}
function handleExtensions(config) {
if (config['state_extensions']) {
config['state_extensions'].forEach(function (ext) {

View File

@ -17,6 +17,7 @@ def on_ui_settings():
"choices": [
"prompt",
"negative_prompt",
"extra_networks",
"styles",
"sampling",
"sampling_steps",
@ -42,6 +43,7 @@ def on_ui_settings():
"choices": [
"prompt",
"negative_prompt",
"extra_networks",
"styles",
"sampling",
"resize_mode",