Skip to content

Commit

Permalink
Added extra networks support
Browse files Browse the repository at this point in the history
  • Loading branch information
ilian-iliev-io committed Apr 11, 2023
1 parent b51580f commit 74f1c74
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 28 deletions.
69 changes: 41 additions & 28 deletions javascript/state.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ state.core = (function () {
'styles': 'styles'
};

const TOGGLE_BUTTONS = {
'extra_networks': 'extra_networks',
};

let store = null;

function hasSetting(id, tab) {
Expand All @@ -59,44 +63,42 @@ 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();

loadUI();
restoreTabs(config);

for (const [settingId, element] of Object.entries(ELEMENTS)) {
TABS.forEach(tab => {
if (config.hasSetting(settingId, tab)) {
handleSavedInput(`${tab}_${element}`);
}
});
}
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)) {
handleSavedInput(`${element}`);
}
});
}
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)) {
handleSavedSelects(`${tab}_${element}`);
}
});
}
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)) {
handleSavedMultiSelects(`${tab}_${element}`);
}
});
}
forEachElement(MULTI_SELECTS, config, (element, tab) => {
handleSavedMultiSelects(`${tab}_${element}`);
});

forEachElement(TOGGLE_BUTTONS, config, (element, tab) => {
handleToggleButton(`${tab}_${element}`);
});

handleExtensions(config);
handleSettingsPage();
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions scripts/state_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def on_ui_settings():
"choices": [
"prompt",
"negative_prompt",
"extra_networks",
"styles",
"sampling",
"sampling_steps",
Expand All @@ -42,6 +43,7 @@ def on_ui_settings():
"choices": [
"prompt",
"negative_prompt",
"extra_networks",
"styles",
"sampling",
"resize_mode",
Expand Down

0 comments on commit 74f1c74

Please sign in to comment.