mirror of
https://github.com/vladmandic/automatic
synced 2026-09-18 16:54:33 +02:00
add notifications
This commit is contained in:
+15
-15
@@ -2,32 +2,32 @@
|
||||
|
||||
let lastHeadImg = null;
|
||||
let notificationButton = null;
|
||||
const regExpTempImage = /(?<=\/|\\)tmp[\w\d]{8}\.png$/gm;
|
||||
|
||||
onUiUpdate(function(){
|
||||
if(notificationButton == null){
|
||||
notificationButton = gradioApp().getElementById('request_notifications')
|
||||
if (notificationButton != null) notificationButton.addEventListener('click', (evt) => Notification.requestPermission(), true);
|
||||
if (!notificationButton) {
|
||||
notificationButton = gradioApp().getElementById('request_notifications')
|
||||
if (notificationButton) notificationButton.addEventListener('click', (evt) => Notification.requestPermission(), true);
|
||||
}
|
||||
const galleryPreviews = gradioApp().querySelectorAll('div[id^="tab_"][style*="display: block"] div[id$="_results"] .thumbnail-item > img');
|
||||
if (galleryPreviews == null) return;
|
||||
const headImg = galleryPreviews[0]?.src;
|
||||
if (headImg == null || headImg == lastHeadImg) return;
|
||||
if (headImg.search(regExpTempImage) != -1) return;
|
||||
lastHeadImg = headImg;
|
||||
// play notification sound if available
|
||||
if (!galleryPreviews) return;
|
||||
|
||||
if (document.hasFocus()) return; // window is in focus so don't send notifications
|
||||
|
||||
const audioNotification = gradioApp().querySelector('#audio_notification audio');
|
||||
if (audioNotification) audioNotification.play();
|
||||
if (document.hasFocus()) return;
|
||||
// Multiple copies of the images are in the DOM when one is selected. Dedup with a Set to get the real number generated.
|
||||
const imgs = new Set(Array.from(galleryPreviews).map(img => img.src));
|
||||
|
||||
const headImg = galleryPreviews[0]?.src;
|
||||
if (!headImg || headImg == lastHeadImg || headImg.endsWith('automatic.png')) return;
|
||||
lastHeadImg = headImg;
|
||||
console.log(headImg)
|
||||
const imgs = new Set(Array.from(galleryPreviews).map(img => img.src)); // Multiple copies of the images are in the DOM when one is selected
|
||||
const notification = new Notification(
|
||||
'Stable Diffusion', {
|
||||
'SD.Next', {
|
||||
body: `Generated ${imgs.size > 1 ? imgs.size - opts.return_grid : 1} image${imgs.size > 1 ? 's' : ''}`,
|
||||
icon: headImg,
|
||||
image: headImg }
|
||||
);
|
||||
notification.onclick = function(_) {
|
||||
notification.onclick = () => {
|
||||
parent.focus();
|
||||
this.close();
|
||||
};
|
||||
|
||||
@@ -37,9 +37,10 @@ function formatTime(secs) {
|
||||
}
|
||||
|
||||
function setTitle(progress) {
|
||||
var title = 'Stable Diffusion'
|
||||
if(opts.show_progress_in_title && progress) title = '[' + progress.trim() + '] ' + title;
|
||||
if(document.title != title) document.title = title;
|
||||
var title = 'SD.Next'
|
||||
console.log('progress:', progress)
|
||||
if (progress) title += ' ' + progress.split(' ')[0].trim();
|
||||
if (document.title != title) document.title = title;
|
||||
}
|
||||
|
||||
function randomId() {
|
||||
|
||||
Reference in New Issue
Block a user