| 13 | * Returns a promise that resolves when flush is complete or timeout occurs |
| 14 | */ |
| 15 | export function requestRendererFlush(window: BrowserWindow): Promise<void> { |
| 16 | return new Promise((resolve) => { |
| 17 | const windowId = window.id |
| 18 | |
| 19 | // Set up timeout protection |
| 20 | const timeoutId = setTimeout(() => { |
| 21 | console.warn(`[Main] Flush timeout for window ${windowId}`) |
| 22 | pendingFlushResolves.delete(windowId) |
| 23 | resolve() |
| 24 | }, FLUSH_TIMEOUT_MS) |
| 25 | |
| 26 | // Store resolve function |
| 27 | pendingFlushResolves.set(windowId, () => { |
| 28 | clearTimeout(timeoutId) |
| 29 | pendingFlushResolves.delete(windowId) |
| 30 | resolve() |
| 31 | }) |
| 32 | |
| 33 | // Send flush request to renderer |
| 34 | window.webContents.send('persistence:flush-request') |
| 35 | }) |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * 验证文件路径是否在允许的目录内 |