now allows for fixed host setting

also makes rest of localstorage data prefixed

Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
Victor Seiji Hariki 2022-12-19 22:23:24 -03:00
parent 0a2aa49777
commit a04a071965
2 changed files with 33 additions and 6 deletions

View file

@ -81,6 +81,9 @@
}; };
})(); })();
// Parse url parameters
const urlParams = new URLSearchParams(window.location.search);
window.onload = startup; window.onload = startup;
var stableDiffusionData = { var stableDiffusionData = {
@ -184,6 +187,22 @@ function startup() {
changeSyncCursorSize(); changeSyncCursorSize();
} }
function setFixedHost(host, changePromptMessage) {
const hostInput = document.getElementById("host");
hostInput.value = host;
hostInput.readOnly = true;
hostInput.style.cursor = "default";
hostInput.style.backgroundColor = "#ddd";
hostInput.addEventListener("dblclick", () => {
if (confirm(changePromptMessage)) {
hostInput.style.backgroundColor = null;
hostInput.style.cursor = null;
hostInput.readOnly = false;
hostInput.focus();
}
});
}
/** /**
* Initial connection checks * Initial connection checks
*/ */
@ -195,8 +214,10 @@ function testHostConfiguration() {
hostEl.value = localStorage.getItem("openoutpaint/host"); hostEl.value = localStorage.getItem("openoutpaint/host");
const requestHost = (prompt, def = "http://127.0.0.1:7860") => { const requestHost = (prompt, def = "http://127.0.0.1:7860") => {
let value = window.prompt(prompt, def); let value = null;
if (value === null) value = "http://127.0.0.1:7860";
if (!urlParams.has("noprompt")) value = window.prompt(prompt, def);
if (value === null) value = def;
value = value.endsWith("/") ? value.substring(0, value.length - 1) : value; value = value.endsWith("/") ? value.substring(0, value.length - 1) : value;
host = value; host = value;
@ -489,16 +510,16 @@ const makeSlider = (
textStep = null, textStep = null,
valuecb = null valuecb = null
) => { ) => {
const local = lsKey && localStorage.getItem(lsKey); const local = lsKey && localStorage.getItem(`openoutpaint/${lsKey}`);
const def = parseFloat(local === null ? defaultValue : local); const def = parseFloat(local === null ? defaultValue : local);
let cb = (v) => { let cb = (v) => {
stableDiffusionData[lsKey] = v; stableDiffusionData[lsKey] = v;
if (lsKey) localStorage.setItem(lsKey, v); if (lsKey) localStorage.setItem(`openoutpaint/${lsKey}`, v);
}; };
if (valuecb) { if (valuecb) {
cb = (v) => { cb = (v) => {
valuecb(v); valuecb(v);
localStorage.setItem(lsKey, v); localStorage.setItem(`openoutpaint/${lsKey}`, v);
}; };
} }
return createSlider(label, el, { return createSlider(label, el, {
@ -607,7 +628,7 @@ function changeSyncCursorSize() {
document.getElementById("cbxSyncCursorSize").checked document.getElementById("cbxSyncCursorSize").checked
); //is this horribly hacky, putting it in SD data instead of making a gross global var? ); //is this horribly hacky, putting it in SD data instead of making a gross global var?
localStorage.setItem( localStorage.setItem(
"sync_cursor_size", "openoutpaint/sync_cursor_size",
stableDiffusionData.sync_cursor_size stableDiffusionData.sync_cursor_size
); );
if (stableDiffusionData.sync_cursor_size) { if (stableDiffusionData.sync_cursor_size) {

View file

@ -72,6 +72,12 @@
console.debug( console.debug(
`[webui] Communication with '${origin}' has been initialized` `[webui] Communication with '${origin}' has been initialized`
); );
if (data.host)
setFixedHost(
data.host,
`Are you sure you want to modify the host?\nThis configuration was provided by the hosting page\n - ${parentWindow.document.title} (${origin})`
);
break; break;
case "openoutpaint/add-resource": case "openoutpaint/add-resource":
{ {