-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
90 lines (74 loc) · 2.77 KB
/
Copy pathmain.js
File metadata and controls
90 lines (74 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const { app, BrowserWindow, session } = require('electron');
const { spawn } = require('child_process');
const path = require('path');
let mainWindow;
let pythonProcess;
// Must be registered at top level BEFORE app.whenReady(), so the handler
// is attached before any early HTTPS request fires.
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
// Allow mitmproxy's self-signed cert for HTTPS interception
event.preventDefault();
callback(true);
});
function createWindow() {
mainWindow = new BrowserWindow({
width: 1280,
height: 800,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
// Required: UI is a file:// page that fetches http://127.0.0.1:5000
webSecurity: false
}
});
mainWindow.loadFile('index.html');
// Uncomment to open DevTools for debugging:
// mainWindow.webContents.openDevTools();
}
app.whenReady().then(async () => {
console.log('[LowKeyPrivate] Starting mitmproxy engine...');
pythonProcess = spawn('mitmdump', ['-s', 'engine.py', '--listen-port', '8080', '--ssl-insecure'], {
cwd: __dirname
});
pythonProcess.stdout.on('data', (data) => {
console.log(`[Engine] ${data.toString().trim()}`);
});
pythonProcess.stderr.on('data', (data) => {
// mitmproxy writes normal startup logs to stderr — not just errors
const msg = data.toString().trim();
if (msg) console.log(`[Engine] ${msg}`);
});
pythonProcess.on('error', (err) => {
console.error(`[Engine] Failed to start mitmdump: ${err.message}`);
console.error('[Engine] Make sure mitmproxy is installed: pip install mitmproxy');
});
pythonProcess.on('exit', (code) => {
if (code !== 0 && code !== null) {
console.error(`[Engine] mitmdump exited with code ${code}`);
}
});
// '<local>' bypasses ALL loopback addresses (localhost, 127.0.0.1, ::1)
// so the UI's fetch() calls to FastAPI at :5000 never go through mitmproxy.
try {
await session.defaultSession.setProxy({
proxyRules: 'http=127.0.0.1:8080;https=127.0.0.1:8080',
proxyBypassRules: '<local>'
});
console.log('[LowKeyPrivate] Proxy rules applied — port 8080');
} catch (err) {
console.error('[LowKeyPrivate] Failed to set proxy:', err);
}
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});
app.on('will-quit', () => {
console.log('[LowKeyPrivate] Shutting down engine...');
if (pythonProcess) {
pythonProcess.kill();
}
});