MCPcopy Create free account
hub / github.com/TechJeeper/Printventory / stopHttpServer

Function stopHttpServer

main.js:1304–1370  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1302 if (wsIpcDebug) {
1303 console.log('[WebSocket] Handler found for channel:', channel, 'Raw args:', args, 'Args length:', args?.length, 'Args type:', typeof args);
1304 console.log('[WebSocket] Calling handler with flatArgs:', flatArgs, 'Length:', flatArgs.length);
1305 }
1306 const result = await handler(mockEvent, ...flatArgs);
1307
1308 // Convert ArrayBuffer to base64 for WebSocket transmission
1309 let serializedResult = result;
1310 if (result instanceof ArrayBuffer) {
1311 const buffer = Buffer.from(result);
1312 serializedResult = {
1313 __arrayBuffer: true,
1314 data: buffer.toString('base64'),
1315 byteLength: result.byteLength
1316 };
1317 } else if (result && result.buffer instanceof ArrayBuffer) {
1318 // Handle TypedArray (Uint8Array, etc.)
1319 const buffer = Buffer.from(result.buffer, result.byteOffset, result.byteLength);
1320 serializedResult = {
1321 __arrayBuffer: true,
1322 data: buffer.toString('base64'),
1323 byteLength: result.byteLength
1324 };
1325 }
1326
1327 ws.send(jsonStringifyForWs({
1328 id,
1329 type: 'result',
1330 result: serializedResult
1331 }));
1332 } catch (error) {
1333 console.error(`Error in handler for '${channel}':`, error);
1334 ws.send(JSON.stringify({
1335 id,
1336 type: 'error',
1337 error: error.message || String(error)
1338 }));
1339 }
1340 } else {
1341 // Fallback: Try to find handler using Electron's internal mechanism
1342 // This is for handlers that weren't registered in our registry
1343 // Use the hidden window as fallback if direct call doesn't work
1344 if (mainWindow && !mainWindow.isDestroyed()) {
1345 // Wait if window is still loading
1346 if (mainWindow.webContents.isLoading()) {
1347 await new Promise(resolve => {
1348 const timeout = setTimeout(resolve, 5000);
1349 mainWindow.webContents.once('did-finish-load', () => {
1350 clearTimeout(timeout);
1351 resolve();
1352 });
1353 });
1354 }
1355
1356 // Stringify args for safe injection into JavaScript code
1357 const argsJson = JSON.stringify(args || []);
1358
1359 const result = await mainWindow.webContents.executeJavaScript(`
1360 (async () => {
1361 try {

Callers 2

restartHttpServerFunction · 0.85
main.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected