Add generation lock and floating-first auto

This commit is contained in:
henrryyes
2026-01-18 18:23:54 +08:00
parent 4a59139c4d
commit 31d680c96c
2 changed files with 64 additions and 19 deletions

View File

@@ -10,6 +10,7 @@ import {
saveSettings,
findLastAIMessageId,
classifyError,
isGenerating,
} from './novel-draw.js';
import { registerToToolbar, removeFromToolbar } from '../../widgets/message-toolbar.js';
@@ -754,6 +755,11 @@ async function handleFloorDrawClick(messageId) {
const panelData = panelMap.get(messageId);
if (!panelData || panelData.state !== FloatState.IDLE) return;
if (isGenerating()) {
toastr?.info?.('已有任务进行中,请等待完成');
return;
}
try {
await generateAndInsertImages({
messageId,
@@ -777,8 +783,9 @@ async function handleFloorDrawClick(messageId) {
});
} catch (e) {
console.error('[NovelDraw]', e);
if (e.message === '已取消') {
if (e.message === '已取消' || e.message?.includes('已有任务进行中')) {
setFloorState(messageId, FloatState.IDLE);
if (e.message?.includes('已有任务进行中')) toastr?.info?.(e.message);
} else {
setFloorState(messageId, FloatState.ERROR, { error: classifyError(e) });
}
@@ -1230,6 +1237,11 @@ async function handleFloatingDrawClick() {
return;
}
if (isGenerating()) {
toastr?.info?.('已有任务进行中,请等待完成');
return;
}
try {
await generateAndInsertImages({
messageId,
@@ -1253,8 +1265,9 @@ async function handleFloatingDrawClick() {
});
} catch (e) {
console.error('[NovelDraw]', e);
if (e.message === '已取消') {
if (e.message === '已取消' || e.message?.includes('已有任务进行中')) {
setFloatingState(FloatState.IDLE);
if (e.message?.includes('已有任务进行中')) toastr?.info?.(e.message);
} else {
setFloatingState(FloatState.ERROR, { error: classifyError(e) });
}
@@ -1547,4 +1560,5 @@ export {
SIZE_OPTIONS,
createFloatingButton,
destroyFloatingButton,
setFloatingState,
};