Added fallback for open model url to deal with popup block or ad-blockers.

- Moved Model Manager z-index from 2000 to 99 (1 below modals).
This commit is contained in:
Christian Bastian
2024-09-09 02:17:39 -04:00
parent ce93156460
commit cff4c96ef3
2 changed files with 35 additions and 6 deletions

View File

@@ -10,7 +10,7 @@
position: fixed; position: fixed;
overflow: hidden; overflow: hidden;
width: 100%; width: 100%;
z-index: 2000; z-index: 99; /*needs to be below dialog modal*/
/*override comfy-modal settings*/ /*override comfy-modal settings*/
border-radius: 0; border-radius: 0;

View File

@@ -15,9 +15,16 @@ function clamp(x, min, max) {
function comfyRequest(url, options = undefined) { function comfyRequest(url, options = undefined) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
api.fetchApi(url, options) api.fetchApi(url, options)
.then((response) => response.json()) .then((response) => {
.then(resolve) if (!response.ok) {
.catch(reject); reject(new Error(`HTTP error ${response.status}: ${response.statusText}`));
} else {
response.json()
.then(resolve)
.catch(error => reject(new Error(`Failed to parse JSON: ${error.message}`)));
}
})
.catch(error => reject(new Error(`Request error: ${error.message}`)));
}); });
} }
@@ -147,13 +154,35 @@ async function tryOpenModelUrl(modelSearchPath) {
const encodedPath = encodeURIComponent(modelSearchPath); const encodedPath = encodeURIComponent(modelSearchPath);
const requestUrl = `/model-manager/model/info/web-url?path=${encodedPath}`; const requestUrl = `/model-manager/model/info/web-url?path=${encodedPath}`;
const webUrlResponse = await comfyRequest(requestUrl); const webUrlResponse = await comfyRequest(requestUrl);
let modelUrl;
try { try {
const modelUrl = new URL(webUrlResponse["url"]); modelUrl = new URL(webUrlResponse["url"]);
window.open(modelUrl, '_blank').focus();
} }
catch (exception) { catch (exception) {
return false; return false;
} }
try {
window.open(modelUrl, '_blank').focus();
}
catch (exception) {
// browser or ad-blocker blocking opening new window
app.ui.dialog.show($el("span",
[
$el("p", {
style: { color: "var(--input-text)" },
}, [modelSearchPath]),
$el("a", {
href: modelUrl,
target: "_blank",
}, [
$el("span", [
modelUrl,
$el("i.mdi.mdi-open-in-new"),
])
]),
]
));
}
return true; return true;
} }