dashcam 1.3.14-beta → 1.3.16-beta
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 +52 -6
- package/bin/dashcam.js +33 -1
- package/lib/processManager.js +105 -11
- package/package.json +1 -1
|
@@ -11,8 +11,8 @@ import fs from 'fs';
|
|
|
11
11
|
import path from 'path';
|
|
12
12
|
import os from 'os';
|
|
13
13
|
|
|
14
|
-
// Get process directory for status files
|
|
15
|
-
const PROCESS_DIR = path.join(os.
|
|
14
|
+
// Get process directory for status files (system temp for cross-session access)
|
|
15
|
+
const PROCESS_DIR = path.join(os.tmpdir(), 'dashcam-cli');
|
|
16
16
|
const STATUS_FILE = path.join(PROCESS_DIR, 'status.json');
|
|
17
17
|
const RESULT_FILE = path.join(PROCESS_DIR, 'upload-result.json');
|
|
18
18
|
|
|
@@ -28,6 +28,13 @@ const options = JSON.parse(optionsJson);
|
|
|
28
28
|
// Enable verbose logging in background
|
|
29
29
|
setVerbose(true);
|
|
30
30
|
|
|
31
|
+
console.log('[Background] Process started', {
|
|
32
|
+
pid: process.pid,
|
|
33
|
+
platform: process.platform,
|
|
34
|
+
processDir: PROCESS_DIR,
|
|
35
|
+
statusFile: STATUS_FILE
|
|
36
|
+
});
|
|
37
|
+
|
|
31
38
|
logger.info('Background recording process started', {
|
|
32
39
|
pid: process.pid,
|
|
33
40
|
options
|
|
@@ -36,13 +43,43 @@ logger.info('Background recording process started', {
|
|
|
36
43
|
// Write status file
|
|
37
44
|
function writeStatus(status) {
|
|
38
45
|
try {
|
|
39
|
-
|
|
46
|
+
const statusData = {
|
|
40
47
|
...status,
|
|
41
48
|
timestamp: Date.now(),
|
|
42
|
-
pid: process.pid
|
|
43
|
-
|
|
49
|
+
pid: process.pid,
|
|
50
|
+
platform: process.platform
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
console.log('[Background] Writing status file:', {
|
|
54
|
+
statusFile: STATUS_FILE,
|
|
55
|
+
pid: statusData.pid,
|
|
56
|
+
isRecording: statusData.isRecording,
|
|
57
|
+
platform: statusData.platform
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
fs.writeFileSync(STATUS_FILE, JSON.stringify(statusData, null, 2));
|
|
61
|
+
|
|
62
|
+
// Verify it was written
|
|
63
|
+
if (fs.existsSync(STATUS_FILE)) {
|
|
64
|
+
console.log('[Background] Status file written and verified:', STATUS_FILE);
|
|
65
|
+
|
|
66
|
+
// Read it back to verify content
|
|
67
|
+
const writtenContent = fs.readFileSync(STATUS_FILE, 'utf8');
|
|
68
|
+
console.log('[Background] Status file content verification:', {
|
|
69
|
+
contentLength: writtenContent.length,
|
|
70
|
+
parseable: true
|
|
71
|
+
});
|
|
72
|
+
} else {
|
|
73
|
+
console.error('[Background] Status file does not exist after write!', STATUS_FILE);
|
|
74
|
+
logger.error('Status file does not exist after write!', { statusFile: STATUS_FILE });
|
|
75
|
+
}
|
|
44
76
|
} catch (error) {
|
|
45
|
-
|
|
77
|
+
console.error('[Background] Failed to write status file:', error.message);
|
|
78
|
+
logger.error('Failed to write status file in background process', {
|
|
79
|
+
error: error.message,
|
|
80
|
+
stack: error.stack,
|
|
81
|
+
statusFile: STATUS_FILE
|
|
82
|
+
});
|
|
46
83
|
}
|
|
47
84
|
}
|
|
48
85
|
|
|
@@ -74,9 +111,12 @@ async function runBackgroundRecording() {
|
|
|
74
111
|
};
|
|
75
112
|
|
|
76
113
|
logger.info('Starting recording with options', { recordingOptions });
|
|
114
|
+
console.log('[Background] Starting recording with options:', recordingOptions);
|
|
77
115
|
|
|
78
116
|
recordingResult = await startRecording(recordingOptions);
|
|
79
117
|
|
|
118
|
+
console.log('[Background] Recording started, writing status file...');
|
|
119
|
+
|
|
80
120
|
// Write status to track the recording
|
|
81
121
|
writeStatus({
|
|
82
122
|
isRecording: true,
|
|
@@ -90,6 +130,12 @@ async function runBackgroundRecording() {
|
|
|
90
130
|
outputPath: recordingResult.outputPath,
|
|
91
131
|
startTime: recordingResult.startTime
|
|
92
132
|
});
|
|
133
|
+
|
|
134
|
+
console.log('[Background] Recording started successfully', {
|
|
135
|
+
outputPath: recordingResult.outputPath,
|
|
136
|
+
startTime: recordingResult.startTime,
|
|
137
|
+
pid: process.pid
|
|
138
|
+
});
|
|
93
139
|
|
|
94
140
|
// Set up signal handlers for graceful shutdown
|
|
95
141
|
const handleShutdown = async (signal) => {
|
package/bin/dashcam.js
CHANGED
|
@@ -395,8 +395,40 @@ program
|
|
|
395
395
|
// Enable verbose logging for stop command
|
|
396
396
|
setVerbose(true);
|
|
397
397
|
|
|
398
|
-
|
|
398
|
+
logger.debug('Stop command invoked', {
|
|
399
|
+
platform: process.platform,
|
|
400
|
+
cwd: process.cwd(),
|
|
401
|
+
pid: process.pid,
|
|
402
|
+
processDir: require('path').join(require('os').tmpdir(), 'dashcam-cli')
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
const isActive = processManager.isRecordingActive();
|
|
406
|
+
logger.debug('Recording active check result', { isActive });
|
|
407
|
+
|
|
408
|
+
if (!isActive) {
|
|
399
409
|
console.log('No active recording to stop');
|
|
410
|
+
logger.warn('Stop command called but no active recording found', {
|
|
411
|
+
platform: process.platform,
|
|
412
|
+
statusFile: require('path').join(require('os').tmpdir(), 'dashcam-cli', 'status.json'),
|
|
413
|
+
statusFileExists: require('fs').existsSync(require('path').join(require('os').tmpdir(), 'dashcam-cli', 'status.json'))
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
// Try to read and display status file for debugging
|
|
417
|
+
try {
|
|
418
|
+
const statusPath = require('path').join(require('os').tmpdir(), 'dashcam-cli', 'status.json');
|
|
419
|
+
if (require('fs').existsSync(statusPath)) {
|
|
420
|
+
const statusContent = require('fs').readFileSync(statusPath, 'utf8');
|
|
421
|
+
logger.debug('Status file contents', { content: statusContent });
|
|
422
|
+
console.log('Status file exists but recording not detected as active');
|
|
423
|
+
console.log('Status file location:', statusPath);
|
|
424
|
+
} else {
|
|
425
|
+
console.log('Status file does not exist');
|
|
426
|
+
console.log('Expected status file location:', statusPath);
|
|
427
|
+
}
|
|
428
|
+
} catch (err) {
|
|
429
|
+
logger.error('Failed to read status file for debugging', { error: err.message });
|
|
430
|
+
}
|
|
431
|
+
|
|
400
432
|
process.exit(0);
|
|
401
433
|
}
|
|
402
434
|
|
package/lib/processManager.js
CHANGED
|
@@ -8,8 +8,8 @@ import { logger } from './logger.js';
|
|
|
8
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
9
|
const __dirname = path.dirname(__filename);
|
|
10
10
|
|
|
11
|
-
// Use
|
|
12
|
-
const PROCESS_DIR = path.join(os.
|
|
11
|
+
// Use system temp directory for cross-session communication
|
|
12
|
+
const PROCESS_DIR = path.join(os.tmpdir(), 'dashcam-cli');
|
|
13
13
|
const STATUS_FILE = path.join(PROCESS_DIR, 'status.json');
|
|
14
14
|
const RESULT_FILE = path.join(PROCESS_DIR, 'upload-result.json');
|
|
15
15
|
|
|
@@ -30,23 +30,66 @@ class ProcessManager {
|
|
|
30
30
|
|
|
31
31
|
writeStatus(status) {
|
|
32
32
|
try {
|
|
33
|
-
|
|
33
|
+
const statusData = {
|
|
34
34
|
...status,
|
|
35
35
|
timestamp: Date.now(),
|
|
36
36
|
pid: process.pid
|
|
37
|
-
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
logger.debug('Writing status file', {
|
|
40
|
+
statusFile: STATUS_FILE,
|
|
41
|
+
pid: statusData.pid,
|
|
42
|
+
isRecording: statusData.isRecording,
|
|
43
|
+
platform: process.platform
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
fs.writeFileSync(STATUS_FILE, JSON.stringify(statusData, null, 2));
|
|
47
|
+
|
|
48
|
+
// Verify it was written
|
|
49
|
+
if (fs.existsSync(STATUS_FILE)) {
|
|
50
|
+
logger.debug('Status file written successfully');
|
|
51
|
+
} else {
|
|
52
|
+
logger.error('Status file does not exist after write!');
|
|
53
|
+
}
|
|
38
54
|
} catch (error) {
|
|
39
|
-
logger.error('Failed to write status file', {
|
|
55
|
+
logger.error('Failed to write status file', {
|
|
56
|
+
error: error.message,
|
|
57
|
+
stack: error.stack,
|
|
58
|
+
statusFile: STATUS_FILE
|
|
59
|
+
});
|
|
40
60
|
}
|
|
41
61
|
}
|
|
42
62
|
|
|
43
63
|
readStatus() {
|
|
44
64
|
try {
|
|
45
|
-
|
|
65
|
+
logger.debug('Reading status file', {
|
|
66
|
+
statusFile: STATUS_FILE,
|
|
67
|
+
exists: fs.existsSync(STATUS_FILE)
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (!fs.existsSync(STATUS_FILE)) {
|
|
71
|
+
logger.debug('Status file does not exist');
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
46
75
|
const data = fs.readFileSync(STATUS_FILE, 'utf8');
|
|
47
|
-
|
|
76
|
+
const status = JSON.parse(data);
|
|
77
|
+
|
|
78
|
+
logger.debug('Status file read successfully', {
|
|
79
|
+
pid: status.pid,
|
|
80
|
+
isRecording: status.isRecording,
|
|
81
|
+
timestamp: status.timestamp,
|
|
82
|
+
startTime: status.startTime,
|
|
83
|
+
outputPath: status.outputPath
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
return status;
|
|
48
87
|
} catch (error) {
|
|
49
|
-
logger.error('Failed to read status file', {
|
|
88
|
+
logger.error('Failed to read status file', {
|
|
89
|
+
error: error.message,
|
|
90
|
+
stack: error.stack,
|
|
91
|
+
statusFile: STATUS_FILE
|
|
92
|
+
});
|
|
50
93
|
return null;
|
|
51
94
|
}
|
|
52
95
|
}
|
|
@@ -98,26 +141,77 @@ class ProcessManager {
|
|
|
98
141
|
}
|
|
99
142
|
|
|
100
143
|
isProcessRunning(pid) {
|
|
101
|
-
if (!pid)
|
|
144
|
+
if (!pid) {
|
|
145
|
+
logger.debug('isProcessRunning: no PID provided');
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
|
|
102
149
|
try {
|
|
103
150
|
process.kill(pid, 0); // Signal 0 just checks if process exists
|
|
151
|
+
logger.debug('Process is running', { pid });
|
|
104
152
|
return true;
|
|
105
153
|
} catch (error) {
|
|
154
|
+
logger.debug('Process is not running', {
|
|
155
|
+
pid,
|
|
156
|
+
error: error.code,
|
|
157
|
+
platform: process.platform
|
|
158
|
+
});
|
|
106
159
|
return false;
|
|
107
160
|
}
|
|
108
161
|
}
|
|
109
162
|
|
|
110
163
|
isRecordingActive() {
|
|
164
|
+
logger.debug('Checking if recording is active...', {
|
|
165
|
+
statusFile: STATUS_FILE,
|
|
166
|
+
processDir: PROCESS_DIR,
|
|
167
|
+
platform: process.platform
|
|
168
|
+
});
|
|
169
|
+
|
|
111
170
|
const status = this.readStatus();
|
|
112
171
|
|
|
113
|
-
|
|
172
|
+
logger.debug('Status check result', {
|
|
173
|
+
hasStatus: !!status,
|
|
174
|
+
hasPid: !!(status && status.pid),
|
|
175
|
+
isRecording: status ? status.isRecording : null,
|
|
176
|
+
statusPid: status ? status.pid : null,
|
|
177
|
+
currentPid: process.pid
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
if (!status) {
|
|
181
|
+
logger.debug('No status found - recording not active');
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (!status.pid) {
|
|
186
|
+
logger.debug('Status has no PID - marking as completed');
|
|
187
|
+
this.markStatusCompleted({ reason: 'no_pid_in_status' });
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const processRunning = this.isProcessRunning(status.pid);
|
|
192
|
+
logger.debug('Process running check', {
|
|
193
|
+
pid: status.pid,
|
|
194
|
+
isRunning: processRunning
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
if (!processRunning) {
|
|
198
|
+
logger.debug('Process not running - marking as completed', {
|
|
199
|
+
pid: status.pid,
|
|
200
|
+
wasRecording: status.isRecording
|
|
201
|
+
});
|
|
202
|
+
|
|
114
203
|
// Mark as completed if process is dead but status exists
|
|
115
|
-
if (status
|
|
204
|
+
if (status.isRecording) {
|
|
116
205
|
this.markStatusCompleted({ reason: 'process_not_running' });
|
|
117
206
|
}
|
|
118
207
|
return false;
|
|
119
208
|
}
|
|
120
209
|
|
|
210
|
+
logger.debug('Recording active status', {
|
|
211
|
+
isRecording: status.isRecording,
|
|
212
|
+
pid: status.pid
|
|
213
|
+
});
|
|
214
|
+
|
|
121
215
|
return status.isRecording;
|
|
122
216
|
}
|
|
123
217
|
|