dashcam 1.3.27 → 1.3.28
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/bin/dashcam-background.js +17 -0
- package/lib/processManager.js +10 -1
- package/package.json +1 -1
|
@@ -14,6 +14,7 @@ import os from 'os';
|
|
|
14
14
|
const PROCESS_DIR = path.join(os.homedir(), '.dashcam-cli');
|
|
15
15
|
const STATUS_FILE = path.join(PROCESS_DIR, 'status.json');
|
|
16
16
|
const RESULT_FILE = path.join(PROCESS_DIR, 'recording-result.json');
|
|
17
|
+
const STOP_REQUEST_FILE = path.join(PROCESS_DIR, 'stop-request.txt');
|
|
17
18
|
|
|
18
19
|
console.log('[Background INIT] Process directory:', PROCESS_DIR);
|
|
19
20
|
console.log('[Background INIT] Status file:', STATUS_FILE);
|
|
@@ -218,9 +219,25 @@ async function runBackgroundRecording() {
|
|
|
218
219
|
process.on('SIGTERM', () => handleShutdown('SIGTERM'));
|
|
219
220
|
|
|
220
221
|
// Keep the process alive - wait indefinitely for signals
|
|
222
|
+
// Also poll for stop request file (for Windows compatibility)
|
|
221
223
|
logger.info('Background recording is now running. Waiting for stop signal...');
|
|
222
224
|
console.log('[Background] Waiting for stop signal...');
|
|
223
225
|
|
|
226
|
+
// Poll for stop request file every 500ms (Windows SIGTERM workaround)
|
|
227
|
+
const pollInterval = setInterval(() => {
|
|
228
|
+
if (fs.existsSync(STOP_REQUEST_FILE)) {
|
|
229
|
+
console.log('[Background] Stop request file detected');
|
|
230
|
+
clearInterval(pollInterval);
|
|
231
|
+
// Delete the stop request file
|
|
232
|
+
try {
|
|
233
|
+
fs.unlinkSync(STOP_REQUEST_FILE);
|
|
234
|
+
} catch (e) {
|
|
235
|
+
// Ignore deletion errors
|
|
236
|
+
}
|
|
237
|
+
handleShutdown('STOP_FILE');
|
|
238
|
+
}
|
|
239
|
+
}, 500);
|
|
240
|
+
|
|
224
241
|
} catch (error) {
|
|
225
242
|
logger.error('Background recording setup failed:', error);
|
|
226
243
|
console.error('[Background] Recording setup failed:', error.message);
|
package/lib/processManager.js
CHANGED
|
@@ -12,6 +12,7 @@ const __dirname = path.dirname(__filename);
|
|
|
12
12
|
const PROCESS_DIR = path.join(os.homedir(), '.dashcam-cli');
|
|
13
13
|
const STATUS_FILE = path.join(PROCESS_DIR, 'status.json');
|
|
14
14
|
const RESULT_FILE = path.join(PROCESS_DIR, 'recording-result.json');
|
|
15
|
+
const STOP_REQUEST_FILE = path.join(PROCESS_DIR, 'stop-request.txt');
|
|
15
16
|
|
|
16
17
|
console.log('[INIT] Process Manager initialized');
|
|
17
18
|
console.log('[INIT] Process directory:', PROCESS_DIR);
|
|
@@ -283,7 +284,15 @@ class ProcessManager {
|
|
|
283
284
|
|
|
284
285
|
logger.info('Sending stop signal to background process', { pid });
|
|
285
286
|
|
|
286
|
-
//
|
|
287
|
+
// Write stop request file (for Windows where SIGTERM doesn't work reliably with detached processes)
|
|
288
|
+
try {
|
|
289
|
+
fs.writeFileSync(STOP_REQUEST_FILE, Date.now().toString());
|
|
290
|
+
logger.debug('Wrote stop request file', { path: STOP_REQUEST_FILE });
|
|
291
|
+
} catch (error) {
|
|
292
|
+
logger.error('Failed to write stop request file', { error });
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Send SIGTERM to the background process to trigger graceful shutdown (Unix/Mac)
|
|
287
296
|
try {
|
|
288
297
|
process.kill(pid, 'SIGTERM');
|
|
289
298
|
logger.info('Sent SIGTERM to background process');
|