Add the debug packet window to the Electron main process.

This commit is contained in:
2026-11-01 09:01:45 +11:00
parent 54c4cf4386
commit 121244e97b
3 changed files with 179 additions and 0 deletions
+46
View File
@@ -113,6 +113,9 @@ let tray = null;
let isQuitting = false;
let apiServer = null;
let pendingDeepLink = null;
let debugWindow = null;
const debugPacketBacklog = [];
const DEBUG_PACKET_LIMIT = 2000;
let protocolRegistrationState = {
before: false,
registerCall: false,
@@ -1960,6 +1963,49 @@ ipcMain.handle('discord-collectibles:download-assets', async (event, { assets })
}
});
// Debug packet window
ipcMain.handle('debug:open-window', () => {
if (debugWindow && !debugWindow.isDestroyed()) {
debugWindow.focus();
return { success: true };
}
debugWindow = new BrowserWindow({
width: 900,
height: 600,
title: 'Debug Packets',
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
nodeIntegration: false,
webSecurity: true
}
});
debugWindow.on('closed', () => {
debugWindow = null;
});
// Send the backlog as one batch once the page has registered its listener
debugWindow.webContents.on('did-finish-load', () => {
debugWindow.webContents.send('debug:packet', debugPacketBacklog);
});
debugWindow.loadFile(path.join(__dirname, 'debug.html'));
return { success: true };
});
ipcMain.on('debug:packet', (event, packet) => {
if (!packet || typeof packet !== 'object') return;
debugPacketBacklog.push(packet);
if (debugPacketBacklog.length > DEBUG_PACKET_LIMIT) debugPacketBacklog.shift(); // Keep last 2000
if (debugWindow && !debugWindow.isDestroyed()) {
debugWindow.webContents.send('debug:packet', packet);
}
});
console.log('Paarrot Electron main process started');
console.log('Development mode:', isDev);
console.log('Platform:', process.platform);