Skip to content

Commit c3e8ae6

Browse files
committed
自動生成でキャンセル処理を追加
1 parent cca821c commit c3e8ae6

File tree

6 files changed

+100
-11
lines changed

6 files changed

+100
-11
lines changed

css/ui/overlay-progress.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88
.op-loading-step {color:#695138;font-size:1rem;margin:0;font-weight:500;font-family:'Noto Sans JP',sans-serif}
99
.op-loading-substep {color:#8a6c56;font-size:0.875rem;margin:0.5rem 0 0;font-family:'Noto Sans JP',sans-serif}
1010
.op-progress-bar {width:100%;height:4px;background-color:#e9e5dc;border-radius:2px;margin-top:1rem;overflow:hidden}
11-
.op-progress-bar-fill {height:100%;background-color:#c3a992;width:0}
11+
.op-progress-bar-fill {height:100%;background-color:#c3a992;width:0}
12+
.op-cancel-button {margin-top:1rem;padding:0.5rem 1.5rem;background-color:#e74c3c;color:white;border:none;border-radius:4px;cursor:pointer;font-size:0.875rem;font-family:'Noto Sans JP',sans-serif;transition:background-color 0.2s}
13+
.op-cancel-button:hover {background-color:#c0392b}
14+
.op-cancel-button:disabled {background-color:#95a5a6;cursor:not-allowed}

js/ai/ai-management.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@ if(sdQueueStatus.total>0){
2525
return true;
2626
}
2727

28-
const comfyuiQueueStatus=sdQueue.getStatus();
28+
const comfyuiQueueStatus=comfyuiQueue.getStatus();
2929
if(comfyuiQueueStatus.total>0){
3030
return true;
3131
}
32+
return false;
33+
}
34+
35+
function clearAllQueues() {
36+
const sdCleared=sdQueue.clearQueue();
37+
const comfyCleared=comfyuiQueue.clearQueue();
38+
logger.info(`All queues cleared: SD=${sdCleared}, ComfyUI=${comfyCleared}`);
39+
return sdCleared+comfyCleared;
3240
}
3341

3442

js/ai/prompt/auto/auto-generation.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
async function autoMultiGenerate() {
2-
const loading=OP_showLoading({icon: 'process',step: 'Step1',substep: 'Multi Page',progress: 0});
2+
const loading=OP_showLoading({icon: 'process',step: 'Step1',substep: 'Multi Page',progress: 0},true);
33
await new Promise(requestAnimationFrame);
44

55
try{
@@ -8,14 +8,26 @@ let onePanelNumber=$("onePanelGenerateNumber").value;
88
let guidList=btmGetGuids();
99
for (const [index,guid] of guidList.entries()) {
1010

11+
if(OP_isCancelled()){
1112
OP_updateLoadingState(loading,{
12-
icon: 'process',step: 'Step2',substep: 'Page:'+(index+1),progress: 50
13+
icon: 'process',step: typeof getText==='function'?getText('op_cancelled'):'Cancelled',substep: '',progress: 100
14+
});
15+
break;
16+
}
17+
18+
OP_updateLoadingState(loading,{
19+
icon: 'process',step: 'Step2',substep: 'Page:'+(index+1)+'/'+guidList.length,progress: Math.round((index/guidList.length)*100)
1320
});
1421
await new Promise(requestAnimationFrame);
1522

1623
await chengeCanvasByGuid(guid);
1724

1825
for (let i=0;i<onePanelNumber;i++) {
26+
27+
if(OP_isCancelled()){
28+
break;
29+
}
30+
1931
const promises=[];
2032
let panelList=getPanelObjectList();
2133

@@ -24,9 +36,16 @@ var spinner=createSpinner(canvasMenuIndex);
2436
promises.push(T2I(panel,spinner));
2537
});
2638

27-
await Promise.all(promises);
39+
await Promise.allSettled(promises);
40+
41+
if(OP_isCancelled()){
42+
break;
43+
}
2844

2945
while (true) {
46+
if(OP_isCancelled()){
47+
break;
48+
}
3049
if (existsWaitQueue()) {
3150
await new Promise((r)=>setTimeout(r,2000));
3251
continue;
@@ -37,8 +56,10 @@ break;
3756

3857
}
3958

59+
if(!OP_isCancelled()){
4060
await btmSaveProjectFile();
4161
}
62+
}
4263
}finally{
4364
OP_hideLoading(loading);
4465
}

js/ai/queue/task-queue.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ this.activeCount=0;
77

88
add(task) {
99
return new Promise((resolve,reject)=>{
10-
this.queue.push(()=>task().then(resolve).catch(reject));
10+
this.queue.push({
11+
execute:()=>task().then(resolve).catch(reject),
12+
reject:reject
13+
});
1114
this.processQueue();
1215
});
1316
}
@@ -17,12 +20,12 @@ if (this.activeCount>=this.concurrency||this.queue.length===0) {
1720
return;
1821
}
1922

20-
const task=this.queue.shift();
23+
const taskItem=this.queue.shift();
2124
this.activeCount++;
2225

2326
try {
2427
logger.debug("task is run.");
25-
await task();
28+
await taskItem.execute();
2629
} catch (error) {
2730
logger.error("Task error:",error);
2831
} finally {
@@ -50,4 +53,16 @@ waiting: this.getWaitingCount(),
5053
total: this.getTotalCount()
5154
};
5255
}
56+
57+
clearQueue() {
58+
const clearedCount=this.queue.length;
59+
this.queue.forEach(taskItem=>{
60+
try{
61+
taskItem.reject(new Error('Queue cancelled'));
62+
}catch(e){}
63+
});
64+
this.queue=[];
65+
logger.debug(`Queue cleared: ${clearedCount} tasks removed`);
66+
return clearedCount;
67+
}
5368
}

js/ui/overlay-progress.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,17 @@ save: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" s
55
download: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="op-icon-spin"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>`
66
};
77

8-
function OP_createLoadingOverlay() {
8+
let OP_cancelRequested=false;
9+
10+
function OP_isCancelled(){
11+
return OP_cancelRequested;
12+
}
13+
14+
function OP_resetCancel(){
15+
OP_cancelRequested=false;
16+
}
17+
18+
function OP_createLoadingOverlay(showCancel=false) {
919
const overlay=document.createElement('div');
1020
const content=document.createElement('div');
1121
const iconContainer=document.createElement('div');
@@ -27,6 +37,23 @@ content.appendChild(iconContainer);
2737
content.appendChild(stepText);
2838
content.appendChild(subStepText);
2939
content.appendChild(progressBar);
40+
41+
if(showCancel){
42+
const cancelBtn=document.createElement('button');
43+
cancelBtn.className='op-cancel-button';
44+
cancelBtn.textContent=typeof getText==='function'?getText('op_cancel'):'Cancel';
45+
cancelBtn.onclick=function(){
46+
OP_cancelRequested=true;
47+
cancelBtn.disabled=true;
48+
cancelBtn.textContent=typeof getText==='function'?getText('op_cancelling'):'Cancelling...';
49+
subStepText.textContent=typeof getText==='function'?getText('op_waitingTask'):'Waiting for current task...';
50+
if(typeof clearAllQueues==='function'){
51+
clearAllQueues();
52+
}
53+
};
54+
content.appendChild(cancelBtn);
55+
}
56+
3057
overlay.appendChild(content);
3158
document.body.appendChild(overlay);
3259
return overlay;
@@ -47,8 +74,11 @@ function OP_hideLoading(overlay) {
4774
if (overlay&&overlay.parentNode) overlay.parentNode.removeChild(overlay);
4875
}
4976

50-
function OP_showLoading(options={}) {
51-
const overlay=OP_createLoadingOverlay();
77+
function OP_showLoading(options={},showCancel=false) {
78+
if(showCancel){
79+
OP_resetCancel();
80+
}
81+
const overlay=OP_createLoadingOverlay(showCancel);
5282
OP_updateLoadingState(overlay,options);
5383
return overlay;
5484
}

js/ui/third/i18next.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ const resources = {
2727
"th": {"unsupportedProjectFileFormat": "รูปแบบไฟล์ไม่รองรับ", "unsupportedProjectFileFormatMessage": "กรุณาเลือกไฟล์ .zip หรือ .lz4", "OutlinePen": "เส้นขอบคู่", "outline1-color": "สีขอบ1", "outline2-color": "สีขอบ2", "outline1-size": "ความกว้างขอบ1", "outline2-size": "ความกว้างขอบ2", "outline1-opacity": "ความทึบขอบ1", "outline2-opacity": "ความทึบขอบ2"},
2828
"de": {"unsupportedProjectFileFormat": "Nicht unterstütztes Dateiformat", "unsupportedProjectFileFormatMessage": "Bitte wählen Sie eine .zip- oder .lz4-Datei", "OutlinePen": "Doppelumriss", "outline1-color": "Umriss1 Farbe", "outline2-color": "Umriss2 Farbe", "outline1-size": "Umriss1 Breite", "outline2-size": "Umriss2 Breite", "outline1-opacity": "Umriss1 Deckkraft", "outline2-opacity": "Umriss2 Deckkraft"}
2929
},
30+
"20260112": {
31+
"ja": {"op_cancel": "キャンセル", "op_cancelling": "キャンセル中...", "op_cancelled": "キャンセル済み", "op_waitingTask": "現在のタスクを待機中..."},
32+
"en": {"op_cancel": "Cancel", "op_cancelling": "Cancelling...", "op_cancelled": "Cancelled", "op_waitingTask": "Waiting for current task..."},
33+
"ko": {"op_cancel": "취소", "op_cancelling": "취소 중...", "op_cancelled": "취소됨", "op_waitingTask": "현재 작업 대기 중..."},
34+
"fr": {"op_cancel": "Annuler", "op_cancelling": "Annulation...", "op_cancelled": "Annulé", "op_waitingTask": "En attente de la tâche en cours..."},
35+
"zh": {"op_cancel": "取消", "op_cancelling": "取消中...", "op_cancelled": "已取消", "op_waitingTask": "等待当前任务..."},
36+
"ru": {"op_cancel": "Отмена", "op_cancelling": "Отмена...", "op_cancelled": "Отменено", "op_waitingTask": "Ожидание текущей задачи..."},
37+
"es": {"op_cancel": "Cancelar", "op_cancelling": "Cancelando...", "op_cancelled": "Cancelado", "op_waitingTask": "Esperando tarea actual..."},
38+
"pt": {"op_cancel": "Cancelar", "op_cancelling": "Cancelando...", "op_cancelled": "Cancelado", "op_waitingTask": "Aguardando tarefa atual..."},
39+
"th": {"op_cancel": "ยกเลิก", "op_cancelling": "กำลังยกเลิก...", "op_cancelled": "ยกเลิกแล้ว", "op_waitingTask": "รอการทำงานปัจจุบัน..."},
40+
"de": {"op_cancel": "Abbrechen", "op_cancelling": "Abbrechen...", "op_cancelled": "Abgebrochen", "op_waitingTask": "Warte auf aktuelle Aufgabe..."}
41+
},
3042
"20250413": {
3143
"ja": {"upscaleButton": "画像を高解像度化します", "cropButton": "Crop", "importButton": "インポート", "exitModeButton": "モード解除"},
3244
"en": {"upscaleButton": "Upscale image", "cropButton": "Crop", "importButton": "Import", "exitModeButton": "Exit Mode"},

0 commit comments

Comments
 (0)