| 1 | import type { BrowserWindow } from 'electron' |
| 2 | import type { GenerateChunkEvent } from '@shared/generation' |
| 3 | |
| 4 | type GenerationWindowRunState = { |
| 5 | runId: string |
| 6 | mode: |
| 7 | | 'generate' |
| 8 | | 'edit' |
| 9 | | 'retry' |
| 10 | | 'addPage' |
| 11 | | 'retrySinglePage' |
| 12 | | 'style-switch' |
| 13 | | 'page-beautify' |
| 14 | } |
| 15 | |
| 16 | export function shouldRevealGenerationWindow( |
| 17 | event: GenerateChunkEvent, |
| 18 | runState?: GenerationWindowRunState |
| 19 | ): boolean { |
| 20 | if (event.type !== 'run_completed' && event.type !== 'run_error') return false |
| 21 | if (event.type === 'run_error' && event.payload.cancelled === true) return false |
| 22 | |
| 23 | if (runState) { |
| 24 | if (runState.runId !== event.payload.runId) return false |
| 25 | return runState.mode === 'generate' || runState.mode === 'retry' |
| 26 | } |
| 27 | |
| 28 | return !event.payload.activityKind |
| 29 | } |
| 30 | |
| 31 | export function revealGenerationWindow(window: BrowserWindow): void { |
| 32 | if (window.isDestroyed()) return |
| 33 | if (window.isMinimized()) window.restore() |
| 34 | if (!window.isVisible()) window.show() |
| 35 | window.focus() |
| 36 | } |
| 37 |