dashcam 1.0.1-beta.29 → 1.0.1-beta.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/processManager.js +31 -6
- package/package.json +1 -1
package/lib/processManager.js
CHANGED
|
@@ -171,12 +171,31 @@ class ProcessManager {
|
|
|
171
171
|
this.cleanup({ preserveResult: true });
|
|
172
172
|
return result;
|
|
173
173
|
} else {
|
|
174
|
-
// Different process -
|
|
174
|
+
// Different process - need to stop it
|
|
175
175
|
logger.info('Stopping active recording process', { pid });
|
|
176
|
-
|
|
176
|
+
|
|
177
|
+
// On Windows, signals don't work the same way, so we need to forcefully terminate
|
|
178
|
+
const isWindows = process.platform === 'win32';
|
|
179
|
+
|
|
180
|
+
if (isWindows) {
|
|
181
|
+
logger.info('Windows detected, using taskkill to stop process');
|
|
182
|
+
try {
|
|
183
|
+
// Use taskkill to forcefully stop the process tree on Windows
|
|
184
|
+
const { execSync } = await import('child_process');
|
|
185
|
+
execSync(`taskkill /PID ${pid} /F /T`, { stdio: 'ignore' });
|
|
186
|
+
} catch (error) {
|
|
187
|
+
logger.warn('Failed to kill process with taskkill', { error: error.message });
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
try {
|
|
191
|
+
process.kill(pid, 'SIGINT');
|
|
192
|
+
} catch (error) {
|
|
193
|
+
logger.warn('Failed to send SIGINT', { error: error.message });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
177
196
|
|
|
178
197
|
// Wait for the process to actually finish
|
|
179
|
-
const maxWaitTime =
|
|
198
|
+
const maxWaitTime = 30000; // 30 seconds
|
|
180
199
|
const startWait = Date.now();
|
|
181
200
|
|
|
182
201
|
while (this.isProcessRunning(pid) && (Date.now() - startWait) < maxWaitTime) {
|
|
@@ -184,9 +203,15 @@ class ProcessManager {
|
|
|
184
203
|
}
|
|
185
204
|
|
|
186
205
|
if (this.isProcessRunning(pid)) {
|
|
187
|
-
logger.warn('Process did not stop within timeout
|
|
188
|
-
|
|
189
|
-
|
|
206
|
+
logger.warn('Process did not stop within timeout');
|
|
207
|
+
if (!isWindows) {
|
|
208
|
+
try {
|
|
209
|
+
process.kill(pid, 'SIGKILL');
|
|
210
|
+
} catch (error) {
|
|
211
|
+
logger.warn('Failed to send SIGKILL', { error: error.message });
|
|
212
|
+
}
|
|
213
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
214
|
+
}
|
|
190
215
|
}
|
|
191
216
|
|
|
192
217
|
if (status) {
|