Skip to content

Commit d4a2f41

Browse files
committed
able to pass back send request to trpc controller as well as started working on pasing option
1 parent 35cc538 commit d4a2f41

File tree

11 files changed

+469
-241
lines changed

11 files changed

+469
-241
lines changed

main.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
// ** Entry point for Electron **
3434
const { app, BrowserWindow, ipcMain, dialog, shell } = require('electron');
3535

36-
3736
const { autoUpdater } = require('electron-updater');
3837
const {
3938
default: installExtension,
@@ -61,7 +60,6 @@ require('./main_process/main_grpcController.js')();
6160
require('./main_process/main_wsController.js')();
6261
require('./main_process/main_mockController.js')();
6362

64-
6563
// require mac touchbar
6664
const { touchBar } = require('./main_process/main_touchbar.js');
6765

@@ -218,8 +216,6 @@ app.on('ready', () => {
218216
}
219217
});
220218

221-
222-
223219
// Quit when all windows are closed.
224220
app.on('window-all-closed', () => {
225221
if (mockServerProcess) {
@@ -427,9 +423,13 @@ ipcMain.on('import-proto', (event) => {
427423
if (err) {
428424
return console.log('import-proto error reading file : ', err);
429425
}
430-
426+
431427
protoParserFunc(importedProto).then((protoObj) => {
432-
mainWindow.webContents.send('proto-info', JSON.stringify(importedProto), JSON.stringify(protoObj));
428+
mainWindow.webContents.send(
429+
'proto-info',
430+
JSON.stringify(importedProto),
431+
JSON.stringify(protoObj)
432+
);
433433
});
434434
});
435435
})
@@ -442,8 +442,11 @@ ipcMain.on('import-proto', (event) => {
442442
// Runs the function and returns the value back to GRPCProtoEntryForm
443443
ipcMain.on('protoParserFunc-request', async (event, data) => {
444444
try {
445-
const result = await protoParserFunc(data)
446-
mainWindow.webContents.send('protoParserFunc-return', JSON.stringify(result));
445+
const result = await protoParserFunc(data);
446+
mainWindow.webContents.send(
447+
'protoParserFunc-return',
448+
JSON.stringify(result)
449+
);
447450
} catch (err) {
448451
console.log('error in protoParserFunc-request:, ', err);
449452
mainWindow.webContents.send('protoParserFunc-return', { error: err });
@@ -464,28 +467,30 @@ ipcMain.on('import-openapi', (event) => {
464467
.then((filePaths) => {
465468
if (!filePaths) return undefined;
466469
// read uploaded document & save in the redux store
467-
fs.readFile(filePaths.filePaths[0], 'utf-8', async (err, importedFile) => {
468-
// handle read error
469-
if (err) {
470-
return console.log('import-openapi error reading file : ', err);
471-
}
472-
473-
try {
474-
const documentObj = await openapiParserFunc(importedFile);
475-
// console.log('Main.js - Working here!',documentObj);
476-
mainWindow.webContents.send('openapi-info', documentObj);
477-
} catch (err) {
478-
return console.log('import-openapi error reading file : ', err);
470+
fs.readFile(
471+
filePaths.filePaths[0],
472+
'utf-8',
473+
async (err, importedFile) => {
474+
// handle read error
475+
if (err) {
476+
return console.log('import-openapi error reading file : ', err);
477+
}
478+
479+
try {
480+
const documentObj = await openapiParserFunc(importedFile);
481+
// console.log('Main.js - Working here!',documentObj);
482+
mainWindow.webContents.send('openapi-info', documentObj);
483+
} catch (err) {
484+
return console.log('import-openapi error reading file : ', err);
485+
}
479486
}
480-
481-
});
487+
);
482488
})
483489
.catch((err) => {
484490
console.log('error in import-openapi', err);
485491
});
486492
});
487493

488-
489494
/////////////////////////////////////////////////////////////////////////////////
490495
/////////////////////////////// MOCK SERVER //////////////////////////////////////
491496
/////////////////////////////////////////////////////////////////////////////////

main_process/main_httpController.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ const httpController = {
191191
reqResObj.connectionType = 'plain';
192192
}
193193

194-
// FIXME: There is something wrong with the logic below.
195-
// First, it is checking if the headers have a 'content-length'
196-
// or 'Content-Length' property. If it does not, it sets the
197-
// responseSize to null. It it does, it checks if the headers have
198-
// a 'content-length' property. If it does, it sets the contentLength
199-
// to 'content-length' or 'Content-Length'. This does not make sense.
200-
// I think it should be setting contentLength to headers['content-length']
194+
// FIXME: There is something wrong with the logic below.
195+
// First, it is checking if the headers have a 'content-length'
196+
// or 'Content-Length' property. If it does not, it sets the
197+
// responseSize to null. It it does, it checks if the headers have
198+
// a 'content-length' property. If it does, it sets the contentLength
199+
// to 'content-length' or 'Content-Length'. This does not make sense.
200+
// I think it should be setting contentLength to headers['content-length']
201201
// or headers['Content-Length'].
202202

203203
// check if response comes with 'content-length' header
@@ -209,14 +209,14 @@ const httpController = {
209209
? (contentLength = 'content-length')
210210
: (contentLength = 'Content-Length');
211211

212-
// FIXME: A previous group used a conversion figure of 1023.89427 to
213-
// convert octets to bytes. This is incorrect because both an octet
214-
// and byte are exactly 8 bits in modern computing. There could, however,
215-
// be some ambiguity because "bytes" may have a different meaning in legacy
216-
// systems. Check out this link for more info: https://en.wikipedia.org/wiki/Octet_(computing).
217-
// If the desired responseSize is in bytes, it is enough to simply assign the value
212+
// FIXME: A previous group used a conversion figure of 1023.89427 to
213+
// convert octets to bytes. This is incorrect because both an octet
214+
// and byte are exactly 8 bits in modern computing. There could, however,
215+
// be some ambiguity because "bytes" may have a different meaning in legacy
216+
// systems. Check out this link for more info: https://en.wikipedia.org/wiki/Octet_(computing).
217+
// If the desired responseSize is in bytes, it is enough to simply assign the value
218218
// of the content-length header.
219-
219+
220220
// Converting content length octets into bytes
221221
const conversionFigure = 1023.89427;
222222
const octetToByteConversion =
@@ -295,7 +295,7 @@ const httpController = {
295295
const { method, headers, body } = args.options;
296296
const response = await fetch(headers.url, { method, headers, body });
297297
const headersResponse = response.headers.raw();
298-
298+
event.sender.send('console', 'WHATS UP');
299299
if (headersResponse['content-type'][0].includes('stream')) {
300300
return {
301301
headers: headersResponse,
@@ -334,7 +334,6 @@ const httpController = {
334334
reqResObj.timeSent = Date.now();
335335

336336
const options = this.parseFetchOptionsFromReqRes(reqResObj);
337-
338337
//-----------------------------------------
339338
// Check if the URL provided is a stream
340339
//-----------------------------------------
@@ -404,9 +403,10 @@ const httpController = {
404403
cookies.forEach((cookie) => {
405404
const cookieString = `${cookie.key}=${cookie.value}`;
406405
// attach to formattedHeaders so options object includes this
407-
formattedHeaders.cookie = cookieString;
406+
formattedHeaders.cookie = formattedHeaders.cookie + ';' + cookieString;
408407
});
409408
}
409+
console.log(formattedHeaders);
410410

411411
const outputObj = {
412412
method,

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"format": "prettier --write \"**/*.+(js|jsx| tsx| json|css|md)\"",
2121
"lint": "eslint .",
2222
"lint:fix": "eslint --fix . ",
23-
"dev": "concurrently --success first \"webpack-dev-server --mode=development --config ./webpack.development.js\" \"nodemon ./src/server/server.js\"",
23+
"dev": "concurrently --success first \"webpack-dev-server --mode=development --config ./webpack.development.js\" \"nodemon --legacy-watch ./src/server/server.js\"",
2424
"build": "concurrently --success first \"webpack --mode=production --config ./webpack.production.js\"",
2525
"prod": "concurrently --success first \"webpack --mode=production --config ./webpack.production.js && electron .\"",
2626
"package-mac": "webpack --mode=production --config ./webpack.production.js && electron-builder build --x64 --mac",
@@ -215,7 +215,7 @@
215215
"jest": "26.0.1",
216216
"mini-css-extract-plugin": "^2.6.0",
217217
"mocha": "^9.2.2",
218-
"nodemon": "^2.0.15",
218+
"nodemon": "^2.0.22",
219219
"nyc": "^15.1.0",
220220
"playwright": "^1.21.1",
221221
"postcss-cssnext": "^3.1.0",
@@ -509,3 +509,4 @@
509509
}
510510
]
511511
}
512+

preload.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ const apiObj = {
6060
},
6161
removeAllListeners: (channel, cb) => {
6262
// allow list channels
63-
const allowedChannels = ['reqResUpdate', 'reply-gql', 'protoParserFunc-return', 'openapi-info'];
63+
const allowedChannels = [
64+
'reqResUpdate',
65+
'reply-gql',
66+
'protoParserFunc-return',
67+
'openapi-info',
68+
];
6469
if (allowedChannels.includes(channel)) {
6570
ipcRenderer.removeAllListeners(channel, (event, ...args) => cb(...args));
6671
} else {
@@ -69,9 +74,9 @@ const apiObj = {
6974
},
7075
};
7176

72-
// this is because we need to have context isolation to be false for spectron
77+
// this is because we need to have context isolation to be false for spectron
7378
// tests to run, but context bridge only runs if context isolation is true
74-
// basically we are assigning certain node functionality (require, ipcRenderer)
79+
// basically we are assigning certain node functionality (require, ipcRenderer)
7580
// to the window object in an UN-isolated context only for testing
7681
// security is reduced for testing, but remains sturdy otherwise
7782

src/client/components/App.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const App = () => {
3535
historyController.getHistory();
3636
collectionsController.getCollections();
3737
}, []);
38-
3938
/**
4039
* All of the main components are rendered from here. Excluding the update pop
4140
* up, there are only 3 main containers for this application.
@@ -67,9 +66,7 @@ const App = () => {
6766
</ErrorBoundary>
6867
</Split>
6968

70-
<ErrorBoundary>
71-
{/* <UpdatePopUpContainer /> */}
72-
</ErrorBoundary>
69+
<ErrorBoundary>{/* <UpdatePopUpContainer /> */}</ErrorBoundary>
7370
</HashRouter>
7471
</div>
7572
);

0 commit comments

Comments
 (0)