diff --git a/javascript/state.core.js b/javascript/state.core.js index 911df98..d09a77f 100644 --- a/javascript/state.core.js +++ b/javascript/state.core.js @@ -95,7 +95,7 @@ state.core = (function () { store = new state.Store(); - loadUI(); + loadUI(config); restoreTabs(config); forEachElement(ELEMENTS, config, (element, tab) => { @@ -177,16 +177,26 @@ state.core = (function () { }; } - function loadUI() { + function loadUI(config) { + let quickSettings = gradioApp().getElementById("quicksettings"); let className = quickSettings.querySelector('button').className; - quickSettings.appendChild(createHeaderButton('State: Reset', "*️⃣", className, {}, actions.resetAll)); - quickSettings.appendChild(createHeaderButton('State: Export',"📤", className, {}, actions.exportState)); - let fileInput = createHeaderFileInput('State: Import',"📥", className); - quickSettings.appendChild(fileInput.hiddenButton); - quickSettings.appendChild(fileInput.button); - } + let uiConfig = config['state_ui']; + if (!uiConfig || uiConfig.indexOf('Reset Button') > -1) { + quickSettings.appendChild(createHeaderButton('State: Reset', "*️⃣", className, {}, actions.resetAll)); + } + + if (!uiConfig || uiConfig.indexOf('Export Button') > -1) { + quickSettings.appendChild(createHeaderButton('State: Export',"📤", className, {}, actions.exportState)); + } + + if (!uiConfig || uiConfig.indexOf('Import Button') > -1) { + let fileInput = createHeaderFileInput('State: Import',"📥", className); + quickSettings.appendChild(fileInput.hiddenButton); + quickSettings.appendChild(fileInput.button); + } + } function restoreTabs(config) { diff --git a/javascript/state.store.js b/javascript/state.store.js index f7a16c3..0d92cc2 100644 --- a/javascript/state.store.js +++ b/javascript/state.store.js @@ -3,7 +3,7 @@ state = window.state; state.Store = function Store (prefix) { this.prefix = state.constants.LS_PREFIX + (prefix ? prefix + '-' : ''); -} +}; state.Store.prototype.set = function (key, value) { if (key.startsWith(this.prefix)) { diff --git a/scripts/state_settings.py b/scripts/state_settings.py index 4ce4a9e..77becee 100644 --- a/scripts/state_settings.py +++ b/scripts/state_settings.py @@ -89,5 +89,17 @@ def on_ui_settings(): ] }, section=section)) + shared.opts.add_option("state_ui", shared.OptionInfo([ + "Reset Button", + "Import Button", + "Export Button" + ], "State UI", gr.CheckboxGroup, lambda: { + "choices": [ + "Reset Button", + "Import Button", + "Export Button" + ], + }, section=section)) + scripts.script_callbacks.on_ui_settings(on_ui_settings)