Skip to content

Commit 9eb0ca3

Browse files
authored
track terminal helper server connected (#118)
1 parent 5538cca commit 9eb0ca3

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

src/main/events.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
storeSessionRecording,
1919
} from "./actions/networkSessionStorage";
2020
import { createOrUpdateAxiosInstance } from "./actions/getProxiedAxios";
21+
// todo: refactor main.ts to only export core entities like webappWindow
22+
// and then build these utilites elsewhere
2123
// eslint-disable-next-line import/no-cycle
2224
import createTrayMenu from "./main";
2325

@@ -218,9 +220,9 @@ export const registerMainProcessEventsForWebAppWindow = (webAppWindow) => {
218220
const filePath = filePaths[0];
219221
trackRecentlyAccessedFile(filePath);
220222
const fileName = path.basename(filePath);
221-
const finalCategory = getFileCategory(path.extname(filePath));
223+
const fileCategory = getFileCategory(path.extname(filePath));
222224
const contents = fs.readFileSync(filePath, "utf-8");
223-
return { filePath, name: fileName, category: finalCategory, contents };
225+
return { filePath, name: fileName, category: fileCategory, contents };
224226
})
225227
.catch((err) => {
226228
console.log(err);
@@ -242,11 +244,15 @@ export const registerMainProcessEventsForWebAppWindow = (webAppWindow) => {
242244
return "err:NOT FOUND";
243245
}
244246
});
247+
248+
ipcMain.handle("helper-server-hit", () => {
249+
webAppWindow.send("helper-server-hit");
250+
});
245251
};
246252

247253
export const registerMainProcessCommonEvents = () => {
248-
ipcMain.handle("open-file-dialog", async () => {
249-
const fileDialogPromise = dialog.showOpenDialog({});
254+
ipcMain.handle("open-file-dialog", async (event, options) => {
255+
const fileDialogPromise = dialog.showOpenDialog(options ?? {});
250256
return fileDialogPromise;
251257
});
252258
};

src/renderer/actions/startHelperServer.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import { ipcRenderer } from "electron";
12
import { staticConfig } from "../config";
23

3-
var http = require("http");
4-
const pem_path = staticConfig.ROOT_CERT_PATH;
4+
const http = require("http");
5+
6+
const pemPath = staticConfig.ROOT_CERT_PATH;
7+
8+
function trackHelperServerHit() {
9+
ipcRenderer.invoke("helper-server-hit");
10+
}
511

612
const getShellScript = (port) => `
713
export http_proxy="http://127.0.0.1:${port}"
@@ -13,13 +19,13 @@ const getShellScript = (port) => `
1319
export npm_config_proxy="http://127.0.0.1:${port}"
1420
export npm_config_https_proxy="http://127.0.0.1:${port}"
1521
export GOPROXY="http://127.0.0.1:${port}"
16-
export SSL_CERT_FILE="${pem_path}"
17-
export NODE_EXTRA_CA_CERTS="${pem_path}"
18-
export REQUESTS_CA_BUNDLE="${pem_path}"
19-
export PERL_LWP_SSL_CA_FILE="${pem_path}"
20-
export GIT_SSL_CAINFO="${pem_path}"
21-
export CARGO_HTTP_CAINFO="${pem_path}"
22-
export CURL_CA_BUNDLE="${pem_path}"
22+
export SSL_CERT_FILE="${pemPath}"
23+
export NODE_EXTRA_CA_CERTS="${pemPath}"
24+
export REQUESTS_CA_BUNDLE="${pemPath}"
25+
export PERL_LWP_SSL_CA_FILE="${pemPath}"
26+
export GIT_SSL_CAINFO="${pemPath}"
27+
export CARGO_HTTP_CAINFO="${pemPath}"
28+
export CURL_CA_BUNDLE="${pemPath}"
2329
if command -v winpty >/dev/null 2>&1; then
2430
# Work around for winpty's hijacking of certain commands
2531
alias php=php
@@ -35,12 +41,13 @@ const getShellScript = (port) => `
3541

3642
const startHelperServer = async (helperServerPort) => {
3743
return new Promise((resolve) => {
38-
var server = http.createServer(function (req, res) {
39-
//create web server
44+
const server = http.createServer((req, res) => {
45+
// create web server
4046
console.log(window.proxy.httpPort);
41-
if (req.url == "/tpsetup") {
47+
if (req.url === "/tpsetup") {
4248
const shellScript = getShellScript(window.proxy.httpPort);
4349
// const shellScript = `export http_proxy="http://127.0.0.1:${window.proxy.httpPort}"`
50+
trackHelperServerHit();
4451
res.writeHead(200, { "Content-Type": "text/x-shellscript" });
4552
res.write(shellScript);
4653
res.end();

0 commit comments

Comments
 (0)