Skip to content

Commit 0697663

Browse files
authored
Add toast message on execution interrupted (#490)
* Move toast to top level * Toast store
1 parent a1a6eee commit 0697663

File tree

6 files changed

+71
-6
lines changed

6 files changed

+71
-6
lines changed

src/App.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<ProgressSpinner v-if="isLoading" class="spinner"></ProgressSpinner>
33
<BlockUI full-screen :blocked="isLoading" />
44
<GlobalDialog />
5+
<GlobalToast />
56
<GraphCanvas />
67
</template>
78

@@ -24,6 +25,7 @@ import { useI18n } from 'vue-i18n'
2425
import { useWorkspaceStore } from './stores/workspaceStateStore'
2526
import NodeLibrarySidebarTab from './components/sidebar/tabs/NodeLibrarySidebarTab.vue'
2627
import GlobalDialog from './components/dialog/GlobalDialog.vue'
28+
import GlobalToast from './components/toast/GlobalToast.vue'
2729
import { api } from './scripts/api'
2830
import { StatusWsMessageStatus } from './types/apiTypes'
2931
import { useQueuePendingTaskCountStore } from './stores/queueStore'

src/components/sidebar/tabs/QueueSidebarTab.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@
3636
</div>
3737
</template>
3838
</SideBarTabTemplate>
39-
<Toast />
4039
<ConfirmPopup />
4140
<ContextMenu ref="menu" :model="menuItems" />
4241
</template>
4342

4443
<script setup lang="ts">
4544
import Button from 'primevue/button'
4645
import ConfirmPopup from 'primevue/confirmpopup'
47-
import Toast from 'primevue/toast'
4846
import ContextMenu from 'primevue/contextmenu'
4947
import TaskItem from './queue/TaskItem.vue'
5048
import SideBarTabTemplate from './SidebarTabTemplate.vue'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<template>
2+
<Toast />
3+
</template>
4+
5+
<script setup lang="ts">
6+
import { useToastStore } from '@/stores/toastStore'
7+
import Toast from 'primevue/toast'
8+
import { useToast } from 'primevue/usetoast'
9+
import { watch } from 'vue'
10+
11+
const toast = useToast()
12+
const toastStore = useToastStore()
13+
14+
watch(
15+
() => toastStore.messages,
16+
(newMessages) => {
17+
if (newMessages.length === 0) {
18+
return
19+
}
20+
21+
newMessages.forEach((message) => {
22+
toast.add(message)
23+
})
24+
toastStore.removeAll()
25+
},
26+
{ deep: true }
27+
)
28+
</script>

src/extensions/core/keybinds.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import { app } from '../../scripts/app'
22
import { api } from '../../scripts/api'
3+
import { useToastStore } from '@/stores/toastStore'
34

45
app.registerExtension({
56
name: 'Comfy.Keybinds',
67
init() {
7-
const keybindListener = function (event) {
8+
const keybindListener = async function (event) {
89
const modifierPressed = event.ctrlKey || event.metaKey
910

1011
// Queue prompt using (ctrl or command) + enter
1112
if (modifierPressed && event.key === 'Enter') {
1213
// Cancel current prompt using (ctrl or command) + alt + enter
1314
if (event.altKey) {
14-
api.interrupt()
15+
await api.interrupt()
16+
useToastStore().add({
17+
severity: 'info',
18+
summary: 'Interrupted',
19+
detail: 'Execution has been interrupted',
20+
life: 1000
21+
})
1522
return
1623
}
1724
// Queue prompt as first for generation using (ctrl or command) + shift + enter

src/scripts/ui/menu/interruptButton.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import { StatusWsMessageStatus } from '@/types/apiTypes'
22
import { api } from '../../api'
33
import { ComfyButton } from '../components/button'
4+
import { useToastStore } from '@/stores/toastStore'
45

56
export function getInterruptButton(visibility: string) {
67
const btn = new ComfyButton({
78
icon: 'close',
89
tooltip: 'Cancel current generation',
910
enabled: false,
10-
action: () => {
11-
api.interrupt()
11+
action: async () => {
12+
await api.interrupt()
13+
useToastStore().add({
14+
severity: 'info',
15+
summary: 'Interrupted',
16+
detail: 'Execution has been interrupted',
17+
life: 1000
18+
})
1219
},
1320
classList: ['comfyui-button', 'comfyui-interrupt-button', visibility]
1421
})

src/stores/toastStore.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Within Vue component context, you can directly call useToast().add()
2+
// instead of going through the store.
3+
// The store is useful when you need to call it from outside the Vue component context.
4+
import { defineStore } from 'pinia'
5+
import type { ToastMessageOptions } from 'primevue/toast'
6+
7+
export const useToastStore = defineStore('toast', {
8+
state: () => ({
9+
messages: [] as ToastMessageOptions[]
10+
}),
11+
12+
actions: {
13+
add(message: ToastMessageOptions) {
14+
this.messages = [...this.messages, message]
15+
},
16+
remove(message: ToastMessageOptions) {
17+
this.messages = this.messages.filter((msg) => msg !== message)
18+
},
19+
removeAll() {
20+
this.messages = []
21+
}
22+
}
23+
})

0 commit comments

Comments
 (0)