aboutsummaryrefslogtreecommitdiffstats
path: root/javascript
diff options
context:
space:
mode:
authorAUTOMATIC <16777216c@gmail.com>2022-09-20 06:53:37 +0000
committerAUTOMATIC <16777216c@gmail.com>2022-09-20 06:53:37 +0000
commit54a097a8186222ba193d1abaaec6b3c65670313d (patch)
tree30e215492b39db93fe1d6ed85be21f66ab955936 /javascript
parentab38392119e9c37c7a9c3f921e0c237deb42b205 (diff)
parentd7f36dac21857dbcedb0303a5c80c35deae26592 (diff)
downloadstable-diffusion-webui-gfx803-54a097a8186222ba193d1abaaec6b3c65670313d.tar.gz
stable-diffusion-webui-gfx803-54a097a8186222ba193d1abaaec6b3c65670313d.tar.bz2
stable-diffusion-webui-gfx803-54a097a8186222ba193d1abaaec6b3c65670313d.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'javascript')
-rw-r--r--javascript/notification.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/javascript/notification.js b/javascript/notification.js
new file mode 100644
index 00000000..4711c279
--- /dev/null
+++ b/javascript/notification.js
@@ -0,0 +1,34 @@
+// Monitors the gallery and sends a browser notification when the leading image is new.
+
+let lastHeadImg = null;
+
+onUiUpdate(function(){
+ const galleryPreviews = gradioApp().querySelectorAll('img.h-full.w-full.overflow-hidden');
+
+ if (galleryPreviews == null) return;
+
+ const headImg = galleryPreviews[0]?.src;
+
+ if (headImg == null || headImg == lastHeadImg) return;
+
+ lastHeadImg = headImg;
+
+ 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 notification = new Notification(
+ 'Stable Diffusion',
+ {
+ body: `Generated ${imgs.size > 1 ? imgs.size - 1 : 1} image${imgs.size > 1 ? 's' : ''}`,
+ icon: headImg,
+ image: headImg,
+ }
+ );
+
+ notification.onclick = function(_){
+ parent.focus();
+ this.close();
+ };
+});