From eecbcd1c30ee4717d153bc2aed7feb07c1051c06 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Thu, 2 May 2024 13:08:16 -0400 Subject: [PATCH] fix notifications --- .eslintrc.json | 4 +++- extensions-builtin/sdnext-modernui | 2 +- javascript/logMonitor.js | 2 +- javascript/notification.js | 9 +++++---- javascript/progressBar.js | 1 + javascript/startup.js | 1 - 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 2bb10241b..2a58658e4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -111,7 +111,9 @@ "idbGet": "readonly", "idbPut": "readonly", "idbDel": "readonly", - "idbAdd": "readonly" + "idbAdd": "readonly", + // notification.js + "sendNotification": "readonly" }, "ignorePatterns": [ "node_modules", diff --git a/extensions-builtin/sdnext-modernui b/extensions-builtin/sdnext-modernui index 7dd6c3b66..92474c2b8 160000 --- a/extensions-builtin/sdnext-modernui +++ b/extensions-builtin/sdnext-modernui @@ -1 +1 @@ -Subproject commit 7dd6c3b66fbf38850cccdf6c169929384284a8a7 +Subproject commit 92474c2b8a66ca1136aeee0049a67dada6dac842 diff --git a/javascript/logMonitor.js b/javascript/logMonitor.js index 66e7f0a36..e4fe99a7f 100644 --- a/javascript/logMonitor.js +++ b/javascript/logMonitor.js @@ -41,7 +41,7 @@ async function logMonitor() { document.getElementById('logWarnings').innerText = logWarnings; document.getElementById('logErrors').innerText = logErrors; const modenUIBtn = document.getElementById('btn_console'); - if (modenUIBtn) modenUIBtn.setAttribute('error-count', logErrors); + if (modenUIBtn) modenUIBtn.setAttribute('error-count', logErrors > 0 ? logErrors : ''); }; if (logMonitorStatus) setTimeout(logMonitor, opts.logmonitor_refresh_period); diff --git a/javascript/notification.js b/javascript/notification.js index 0c8879885..33e8d1c55 100644 --- a/javascript/notification.js +++ b/javascript/notification.js @@ -3,14 +3,15 @@ let lastHeadImg = null; let notificationButton = null; -async function initNotifications() { +async function sendNotification() { if (!notificationButton) { notificationButton = gradioApp().getElementById('request_notifications'); if (notificationButton) notificationButton.addEventListener('click', (evt) => Notification.requestPermission(), true); } if (document.hasFocus()) return; // window is in focus so don't send notifications - const galleryPreviews = gradioApp().querySelectorAll('div[id^="tab_"][style*="display: block"] div[id$="_results"] .thumbnail-item > img'); - if (!galleryPreviews) return; + let galleryPreviews = gradioApp().querySelectorAll('div[id^="tab_"][style*="display: block"] div[id$="_results"] .thumbnail-item > img'); + if (!galleryPreviews || galleryPreviews.length === 0) galleryPreviews = gradioApp().querySelectorAll('.thumbnail-item > img'); + if (!galleryPreviews || galleryPreviews.length === 0) return; const headImg = galleryPreviews[0]?.src; if (!headImg || headImg === lastHeadImg || headImg.includes('logo-bg-')) return; const audioNotification = gradioApp().querySelector('#audio_notification audio'); @@ -26,5 +27,5 @@ async function initNotifications() { parent.focus(); this.close(); }; - log('sendNotification'); + log('sendNotifications'); } diff --git a/javascript/progressBar.js b/javascript/progressBar.js index 238a2988e..91908bd2d 100644 --- a/javascript/progressBar.js +++ b/javascript/progressBar.js @@ -109,6 +109,7 @@ function requestProgress(id_task, progressEl, galleryEl, atEnd = null, onProgres setProgress(); if (parentGallery && livePreview) parentGallery.removeChild(livePreview); checkPaused(true); + sendNotification(); if (atEnd) atEnd(); }; diff --git a/javascript/startup.js b/javascript/startup.js index 0d079650a..12fedfd94 100644 --- a/javascript/startup.js +++ b/javascript/startup.js @@ -8,7 +8,6 @@ async function initStartup() { initModels(); getUIDefaults(); initiGenerationParams(); - initNotifications(); initPromptChecker(); initLogMonitor(); initContextMenu();