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:
@@ -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
|
// Create a batch file to launch the cookie-based camera proxy
|
||||||
const truncatedKey = safeCookieKey.length > 20 ? safeCookieKey.substring(0, 20) + '...' : safeCookieKey;
|
const truncatedKey = safeCookieKey.length > 20 ? safeCookieKey.substring(0, 20) + '...' : safeCookieKey;
|
||||||
const batchContent = `@echo off
|
const batchContent = `@echo off
|
||||||
|
title APT-Proxy-${safeDeviceUuid}
|
||||||
echo Launching Alta Video Camera Proxy (Cookie Method)...
|
echo Launching Alta Video Camera Proxy (Cookie Method)...
|
||||||
echo Domain: ${safeDomain}
|
echo Domain: ${safeDomain}
|
||||||
echo Device UUID: ${safeDeviceUuid}
|
echo Device UUID: ${safeDeviceUuid}
|
||||||
@@ -291,8 +292,9 @@ pause >nul`;
|
|||||||
console.log('Launching cookie-based camera proxy via batch file:', batchPath);
|
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]');
|
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
|
// Launch the batch file in a new command prompt window with unique title
|
||||||
const cmdProcess = spawn('cmd', ['/c', 'start', 'cmd', '/k', batchPath], {
|
const windowTitle = `APT-Proxy-${safeDeviceUuid}`;
|
||||||
|
const cmdProcess = spawn('cmd', ['/c', 'start', `"${windowTitle}"`, 'cmd', '/c', batchPath], {
|
||||||
detached: true,
|
detached: true,
|
||||||
stdio: 'ignore'
|
stdio: 'ignore'
|
||||||
});
|
});
|
||||||
@@ -305,6 +307,7 @@ pause >nul`;
|
|||||||
startTime: Date.now(),
|
startTime: Date.now(),
|
||||||
cookieKey: truncatedKey,
|
cookieKey: truncatedKey,
|
||||||
domain: safeDomain,
|
domain: safeDomain,
|
||||||
|
windowTitle: windowTitle, // Store window title for targeted cleanup
|
||||||
type: 'cookie' // Mark as cookie-based proxy
|
type: 'cookie' // Mark as cookie-based proxy
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -348,14 +351,11 @@ pause >nul`;
|
|||||||
// Stop camera proxy functionality
|
// Stop camera proxy functionality
|
||||||
ipcMain.handle('camera-proxy-stop', async (event, { processId }) => {
|
ipcMain.handle('camera-proxy-stop', async (event, { processId }) => {
|
||||||
try {
|
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) => {
|
return new Promise((resolve) => {
|
||||||
let processesKilled = 0;
|
// Kill all aware-cam-proxy.exe processes by name
|
||||||
let totalAttempts = 0;
|
const killProxy = spawn('taskkill', ['/f', '/im', 'aware-cam-proxy.exe'], {
|
||||||
|
|
||||||
// Step 1: Kill all aware-cam-proxy-win.exe processes by name
|
|
||||||
const killProxy = spawn('taskkill', ['/f', '/im', 'aware-cam-proxy-win.exe'], {
|
|
||||||
stdio: ['ignore', 'pipe', 'pipe']
|
stdio: ['ignore', 'pipe', 'pipe']
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -371,66 +371,17 @@ ipcMain.handle('camera-proxy-stop', async (event, { processId }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
killProxy.on('close', (code) => {
|
killProxy.on('close', (code) => {
|
||||||
totalAttempts++;
|
|
||||||
if (code === 0 || proxyOutput.includes('SUCCESS')) {
|
|
||||||
processesKilled++;
|
|
||||||
console.log('Camera proxy processes terminated successfully');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
// Clean up our process tracking
|
||||||
activeProxyProcesses.clear();
|
activeProxyProcesses.clear();
|
||||||
|
|
||||||
// Determine final result
|
if (code === 0 || proxyOutput.includes('SUCCESS')) {
|
||||||
if (processesKilled > 0) {
|
console.log('Camera proxy processes terminated successfully');
|
||||||
resolve({
|
resolve({
|
||||||
success: true,
|
success: true,
|
||||||
message: 'Camera proxy processes and terminal windows closed successfully'
|
message: 'Camera proxy processes stopped successfully'
|
||||||
});
|
});
|
||||||
} else if (proxyError.includes('not found') || proxyError.includes('No tasks')) {
|
} else if (proxyError.includes('not found') || proxyError.includes('No tasks')) {
|
||||||
|
console.log('No camera proxy processes were running');
|
||||||
resolve({
|
resolve({
|
||||||
success: true,
|
success: true,
|
||||||
message: 'No camera proxy processes were running'
|
message: 'No camera proxy processes were running'
|
||||||
@@ -438,27 +389,14 @@ ipcMain.handle('camera-proxy-stop', async (event, { processId }) => {
|
|||||||
} else {
|
} else {
|
||||||
resolve({
|
resolve({
|
||||||
success: true,
|
success: true,
|
||||||
message: 'Attempted to close all camera proxy processes and windows'
|
message: 'Attempted to stop all camera proxy processes'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
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) => {
|
killProxy.on('error', (error) => {
|
||||||
console.error('Error with taskkill by name:', error);
|
console.error('Error with taskkill by name:', error);
|
||||||
|
activeProxyProcesses.clear();
|
||||||
resolve({
|
resolve({
|
||||||
success: false,
|
success: false,
|
||||||
message: `Failed to stop camera proxy: ${error.message}`
|
message: `Failed to stop camera proxy: ${error.message}`
|
||||||
|
|||||||
Reference in New Issue
Block a user