Fix proxy stop not killing aware-cam-proxy.exe processes

The stop handler was targeting the wrong executable name
(aware-cam-proxy-win.exe instead of aware-cam-proxy.exe), so taskkill
never found the running process. Also removed dangerous fallbacks that
killed all cmd.exe processes system-wide and deprecated wmic calls.
Simplified to a single targeted taskkill. Launch now uses a unique
window title and cmd /c so terminals close naturally after the proxy
exits.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Zac
2026-02-09 21:50:38 -05:00
parent f57183448f
commit c9b466b0d1
+37 -99
View File
@@ -272,6 +272,7 @@ ipcMain.handle('camera-proxy-cookie-launch', async (event, { deploymentUrl, cook
// Create a batch file to launch the cookie-based camera proxy
const truncatedKey = safeCookieKey.length > 20 ? safeCookieKey.substring(0, 20) + '...' : safeCookieKey;
const batchContent = `@echo off
title APT-Proxy-${safeDeviceUuid}
echo Launching Alta Video Camera Proxy (Cookie Method)...
echo Domain: ${safeDomain}
echo Device UUID: ${safeDeviceUuid}
@@ -290,13 +291,14 @@ pause >nul`;
console.log('Launching cookie-based camera proxy via batch file:', batchPath);
console.log('Command will be: aware-cam-proxy.exe -a', safeDomain, '-d', safeDeviceUuid, '-k [REDACTED]');
// Launch the batch file in a new command prompt window
const cmdProcess = spawn('cmd', ['/c', 'start', 'cmd', '/k', batchPath], {
// Launch the batch file in a new command prompt window with unique title
const windowTitle = `APT-Proxy-${safeDeviceUuid}`;
const cmdProcess = spawn('cmd', ['/c', 'start', `"${windowTitle}"`, 'cmd', '/c', batchPath], {
detached: true,
stdio: 'ignore'
});
// Store the process information for later termination
const processInfo = {
process: cmdProcess,
@@ -305,9 +307,10 @@ pause >nul`;
startTime: Date.now(),
cookieKey: truncatedKey,
domain: safeDomain,
windowTitle: windowTitle, // Store window title for targeted cleanup
type: 'cookie' // Mark as cookie-based proxy
};
activeProxyProcesses.set(cmdProcess.pid, processInfo);
// Clean up the batch file after a delay
@@ -348,124 +351,59 @@ pause >nul`;
// Stop camera proxy functionality
ipcMain.handle('camera-proxy-stop', async (event, { processId }) => {
try {
console.log('Attempting to stop camera proxy processes and close terminal windows...');
console.log('Attempting to stop camera proxy processes...');
return new Promise((resolve) => {
let processesKilled = 0;
let totalAttempts = 0;
// Step 1: Kill all aware-cam-proxy-win.exe processes by name
const killProxy = spawn('taskkill', ['/f', '/im', 'aware-cam-proxy-win.exe'], {
// Kill all aware-cam-proxy.exe processes by name
const killProxy = spawn('taskkill', ['/f', '/im', 'aware-cam-proxy.exe'], {
stdio: ['ignore', 'pipe', 'pipe']
});
let proxyOutput = '';
let proxyError = '';
killProxy.stdout.on('data', (data) => {
proxyOutput += data.toString();
});
killProxy.stderr.on('data', (data) => {
proxyError += data.toString();
});
killProxy.on('close', (code) => {
totalAttempts++;
// Clean up our process tracking
activeProxyProcesses.clear();
if (code === 0 || proxyOutput.includes('SUCCESS')) {
processesKilled++;
console.log('Camera proxy processes terminated successfully');
resolve({
success: true,
message: 'Camera proxy processes stopped successfully'
});
} else if (proxyError.includes('not found') || proxyError.includes('No tasks')) {
console.log('No camera proxy processes were running');
resolve({
success: true,
message: 'No camera proxy processes were running'
});
} else {
resolve({
success: true,
message: 'Attempted to stop all camera proxy processes'
});
}
// Step 2: Kill command prompt windows containing our batch file or camera proxy
const killCmdWindows = spawn('powershell', [
'-Command',
`Get-Process | Where-Object {$_.ProcessName -eq "cmd" -and $_.MainWindowTitle -like "*camera-proxy*" -or $_.MainWindowTitle -like "*aware-cam-proxy*" -or $_.MainWindowTitle -like "*Command Prompt*"} | Stop-Process -Force`
], {
stdio: 'ignore'
});
killCmdWindows.on('close', () => {
totalAttempts++;
// Step 3: More aggressive approach - kill all cmd processes that might be related
const killAllCmd = spawn('taskkill', ['/f', '/im', 'cmd.exe'], {
stdio: ['ignore', 'pipe', 'pipe']
});
let cmdOutput = '';
killAllCmd.stdout.on('data', (data) => {
cmdOutput += data.toString();
});
killAllCmd.on('close', (cmdCode) => {
totalAttempts++;
if (cmdCode === 0 || cmdOutput.includes('SUCCESS')) {
processesKilled++;
console.log('Command prompt windows closed successfully');
}
// Step 4: Final cleanup - use wmic as fallback
const wmicKill = spawn('wmic', [
'process', 'where',
'name="cmd.exe" or name="aware-cam-proxy-win.exe"',
'delete'
], {
stdio: 'ignore'
});
wmicKill.on('close', (wmicCode) => {
totalAttempts++;
if (wmicCode === 0) {
processesKilled++;
}
// Clean up our process tracking
activeProxyProcesses.clear();
// Determine final result
if (processesKilled > 0) {
resolve({
success: true,
message: 'Camera proxy processes and terminal windows closed successfully'
});
} else if (proxyError.includes('not found') || proxyError.includes('No tasks')) {
resolve({
success: true,
message: 'No camera proxy processes were running'
});
} else {
resolve({
success: true,
message: 'Attempted to close all camera proxy processes and windows'
});
}
});
wmicKill.on('error', () => {
// Even if wmic fails, we might have succeeded with other methods
activeProxyProcesses.clear();
resolve({
success: processesKilled > 0,
message: processesKilled > 0 ?
'Camera proxy processes terminated, some terminal windows may remain open' :
'Unable to terminate camera proxy processes. Please close terminal windows manually.'
});
});
});
});
});
killProxy.on('error', (error) => {
console.error('Error with taskkill by name:', error);
activeProxyProcesses.clear();
resolve({
success: false,
message: `Failed to stop camera proxy: ${error.message}`
});
});
});
} catch (error) {
console.error('Failed to stop camera proxy:', error);
return {