Skip to content

Commit

Permalink
#108 - use IpcStream to load response body
Browse files Browse the repository at this point in the history
  • Loading branch information
SoulKa committed Oct 29, 2024
1 parent d84b846 commit 978ab47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/main/main.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
};

Expand Down
20 changes: 8 additions & 12 deletions src/renderer/components/mainWindow/bodyTabs/OutputTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand All @@ -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]);

Expand Down

0 comments on commit 978ab47

Please sign in to comment.