fix notifications

This commit is contained in:
Vladimir Mandic
2024-05-02 13:08:16 -04:00
parent 6cd884acb6
commit eecbcd1c30
6 changed files with 11 additions and 8 deletions
+1 -1
View File
@@ -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);
+5 -4
View File
@@ -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');
}
+1
View File
@@ -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();
};
-1
View File
@@ -8,7 +8,6 @@ async function initStartup() {
initModels();
getUIDefaults();
initiGenerationParams();
initNotifications();
initPromptChecker();
initLogMonitor();
initContextMenu();