From df8fa5b51600b9334c55ef33b5ea31bcaaeabc69 Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Mon, 27 May 2024 09:46:46 -0400 Subject: [PATCH] sync --- electron/lib/ScriptBuffer.ts | 11 +++++++++++ electron/main.ts | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/electron/lib/ScriptBuffer.ts b/electron/lib/ScriptBuffer.ts index 0e2a0bb..d691be3 100644 --- a/electron/lib/ScriptBuffer.ts +++ b/electron/lib/ScriptBuffer.ts @@ -52,6 +52,17 @@ export class ScriptBuffer extends EventEmitter { throw error } }) + + // Listen for clear events + this.on('script-buffer-clear', () => { + ScriptBuffer.#buffer = [] + try { + this.#save() + } catch (error:any) { + throw new ScriptBufferError(error.message, this.#write) + } + this.emit('script-buffer-updated') + }) } /** diff --git a/electron/main.ts b/electron/main.ts index 3c1a325..3a08731 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -332,6 +332,7 @@ const buildMenu = ():Menu => { label: `Show Output Buffer`, click: () => { bufferWindow() } })) + bufferMenu.append(new MenuItem({ type: 'separator' })) bufferMenu.append(new MenuItem({ label: `Save as JSON`, @@ -374,6 +375,23 @@ const buildMenu = ():Menu => { } } })) + bufferMenu.append(new MenuItem({ type: 'separator' })) + + bufferMenu.append(new MenuItem({ + label: 'Clear Buffer', + click: async () => { + const { response } = await dialog.showMessageBox({ + type: 'question', + title: `${appInfo.name} - Confirm`, + buttons: [ 'Yes', 'No' ], + message: 'Are you sure you want to clear the buffer?' + }) + if (response === 0) { + resBuff.emit('script-buffer-clear') + bufferWin?.webContents.send('send-buffer-data', resBuff.read()) + } + } + })) menu.append(new MenuItem({ label: `Output Buffer`, submenu: bufferMenu})) menu.append(new MenuItem({