Skip to content

Commit

Permalink
add notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmandic committed May 3, 2023
1 parent 8cbce7e commit 0af6c70
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from modules.cmd_args import parser
except:
import argparse
parser = argparse.ArgumentParser(description="Stable Diffusion", conflict_handler='resolve', formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=55, indent_increment=2, width=200))
parser = argparse.ArgumentParser(description="SD.Next", conflict_handler='resolve', formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=55, indent_increment=2, width=200))

class Dot(dict): # dot notation access to dictionary attributes
__getattr__ = dict.get
Expand Down
30 changes: 15 additions & 15 deletions javascript/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
7 changes: 4 additions & 3 deletions javascript/progressbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion modules/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ def reload_scripts():
for _interface, label, _ifid in interfaces:
shared.tab_names.append(label)

with gr.Blocks(theme=shared.gradio_theme, analytics_enabled=False, title="Stable Diffusion") as demo:
with gr.Blocks(theme=shared.gradio_theme, analytics_enabled=False, title="SD.Next") as demo:
with gr.Row(elem_id="quicksettings", variant="compact"):
for i, k, item in sorted(quicksettings_list, key=lambda x: quicksettings_names.get(x[1], x[0])):
component = create_setting_component(k, is_quicksettings=True)
Expand Down
2 changes: 1 addition & 1 deletion wiki
Submodule wiki updated from ab46c9 to fad4a1

1 comment on commit 0af6c70

@sebaxakerhtc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Please sign in to comment.