瀏覽代碼

make live preview display work independently from progress bar

AUTOMATIC1111 2 年之前
父節點
當前提交
a0d721e109
共有 2 個文件被更改,包括 20 次插入11 次删除
  1. 18 10
      javascript/progressbar.js
  2. 2 1
      modules/progress.py

+ 18 - 10
javascript/progressbar.js

@@ -93,8 +93,8 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
         atEnd();
         atEnd();
     };
     };
 
 
-    var fun = function(id_task, id_live_preview) {
-        request("./internal/progress", {id_task: id_task, id_live_preview: id_live_preview}, function(res) {
+    var funProgress = function(id_task) {
+        request("./internal/progress", {id_task: id_task, live_preview: false}, function(res) {
             if (res.completed) {
             if (res.completed) {
                 removeProgressBar();
                 removeProgressBar();
                 return;
                 return;
@@ -119,7 +119,6 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
                 progressText += " ETA: " + formatTime(res.eta);
                 progressText += " ETA: " + formatTime(res.eta);
             }
             }
 
 
-
             setTitle(progressText);
             setTitle(progressText);
 
 
             if (res.textinfo && res.textinfo.indexOf("\n") == -1) {
             if (res.textinfo && res.textinfo.indexOf("\n") == -1) {
@@ -142,7 +141,20 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
                 return;
                 return;
             }
             }
 
 
+            if (onProgress) {
+                onProgress(res);
+            }
+
+            setTimeout(() => {
+                funProgress(id_task, res.id_live_preview);
+            }, opts.live_preview_refresh_period || 500);
+        }, function() {
+            removeProgressBar();
+        });
+    }
 
 
+    var funLivePreview = function(id_task, id_live_preview) {
+        request("./internal/progress", {id_task: id_task, id_live_preview: id_live_preview}, function(res) {
             if (res.live_preview && gallery) {
             if (res.live_preview && gallery) {
                 rect = gallery.getBoundingClientRect();
                 rect = gallery.getBoundingClientRect();
                 if (rect.width) {
                 if (rect.width) {
@@ -160,18 +172,14 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
                 img.src = res.live_preview;
                 img.src = res.live_preview;
             }
             }
 
 
-
-            if (onProgress) {
-                onProgress(res);
-            }
-
             setTimeout(() => {
             setTimeout(() => {
-                fun(id_task, res.id_live_preview);
+                funLivePreview(id_task, res.id_live_preview);
             }, opts.live_preview_refresh_period || 500);
             }, opts.live_preview_refresh_period || 500);
         }, function() {
         }, function() {
             removeProgressBar();
             removeProgressBar();
         });
         });
     };
     };
 
 
-    fun(id_task, 0);
+    funProgress(id_task, 0);
+    funLivePreview(id_task, 0);
 }
 }

+ 2 - 1
modules/progress.py

@@ -48,6 +48,7 @@ def add_task_to_queue(id_job):
 class ProgressRequest(BaseModel):
 class ProgressRequest(BaseModel):
     id_task: str = Field(default=None, title="Task ID", description="id of the task to get progress for")
     id_task: str = Field(default=None, title="Task ID", description="id of the task to get progress for")
     id_live_preview: int = Field(default=-1, title="Live preview image ID", description="id of last received last preview image")
     id_live_preview: int = Field(default=-1, title="Live preview image ID", description="id of last received last preview image")
+    live_preview: bool = Field(default=True, title="Include live preview", description="boolean flag indicating whether to include the live preview image")
 
 
 
 
 class ProgressResponse(BaseModel):
 class ProgressResponse(BaseModel):
@@ -91,7 +92,7 @@ def progressapi(req: ProgressRequest):
 
 
     id_live_preview = req.id_live_preview
     id_live_preview = req.id_live_preview
     shared.state.set_current_image()
     shared.state.set_current_image()
-    if opts.live_previews_enable and shared.state.id_live_preview != req.id_live_preview:
+    if opts.live_previews_enable and req.live_preview and shared.state.id_live_preview != req.id_live_preview:
         image = shared.state.current_image
         image = shared.state.current_image
         if image is not None:
         if image is not None:
             buffered = io.BytesIO()
             buffered = io.BytesIO()