diff --git a/src/main/main.ts b/src/main/main.ts index 6f3dc44..39fdb02 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -1,7 +1,7 @@ import { app, BrowserWindow, shell } from 'electron'; -import 'main/event/main-event-service'; import { EnvironmentService } from 'main/environment/service/environment-service'; import installExtension, { REDUX_DEVTOOLS } from 'electron-devtools-installer'; +import 'main/event/main-event-service'; // This allows TypeScript to pick up the magic constants that's auto-generated by Forge's Webpack // plugin that tells the Electron app where to look for the Webpack-bundled app code (depending on @@ -35,7 +35,7 @@ const createWindow = async () => { return { action: 'deny' }; }); - // and load the index.html of the app. + // Load the index.html of the app. await mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY); }; diff --git a/src/renderer/components/mainWindow/bodyTabs/OutputTabs.tsx b/src/renderer/components/mainWindow/bodyTabs/OutputTabs.tsx index b133259..c5e17ba 100644 --- a/src/renderer/components/mainWindow/bodyTabs/OutputTabs.tsx +++ b/src/renderer/components/mainWindow/bodyTabs/OutputTabs.tsx @@ -7,10 +7,7 @@ import { useEffect, useRef } from 'react'; import { ResponseStatus } from '@/components/mainWindow/responseStatus/ResponseStatus'; import { selectResponse, selectResponseEditor, setResponseEditor } from '@/state/responsesSlice'; import { useDispatch, useSelector } from 'react-redux'; -import { RendererEventService } from '@/services/event/renderer-event-service'; - -const eventService = RendererEventService.instance; -const textDecoder = new TextDecoder(); +import { IpcPushStream } from '@/lib/ipc-stream'; const monacoOptions = { ...DEFAULT_MONACO_OPTIONS, @@ -39,13 +36,6 @@ function getContentType(headers?: HttpHeaders) { } } -async function loadRequestBody(filePath: string) { - console.debug('Reading response body from', filePath); - const buffer = await eventService.readFile(filePath); - console.debug('Received response body of', buffer.byteLength, 'bytes'); - return textDecoder.decode(buffer); // TODO: decode with encoding from response headers -} - interface OutputTabsProps { className: string; } @@ -63,7 +53,13 @@ export function OutputTabs(props: OutputTabsProps) { } else if (response?.bodyFilePath == null) { editor.setValue(''); } else { - loadRequestBody(response.bodyFilePath).then((body) => editor.setValue(body)); + editor.setValue(''); + IpcPushStream.open(response.bodyFilePath).then((stream) => { + const data = [] as string[]; + stream.on('data', (chunk) => data.push(chunk)); + stream.on('end', () => editor?.setValue(data.join(''))); + stream.on('error', (error) => console.error('Error reading response body:', error)); + }); } }, [response?.bodyFilePath, editor]);