dashcam 1.3.14-beta → 1.3.15-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 +32 -4
- package/bin/dashcam.js +32 -1
- package/lib/processManager.js +103 -9
- package/package.json +1 -1
|
@@ -36,13 +36,41 @@ logger.info('Background recording process started', {
|
|
|
36
36
|
// Write status file
|
|
37
37
|
function writeStatus(status) {
|
|
38
38
|
try {
|
|
39
|
-
|
|
39
|
+
const statusData = {
|
|
40
40
|
...status,
|
|
41
41
|
timestamp: Date.now(),
|
|
42
|
-
pid: process.pid
|
|
43
|
-
|
|
42
|
+
pid: process.pid,
|
|
43
|
+
platform: process.platform
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
logger.debug('Background process writing status file', {
|
|
47
|
+
statusFile: STATUS_FILE,
|
|
48
|
+
pid: statusData.pid,
|
|
49
|
+
isRecording: statusData.isRecording,
|
|
50
|
+
platform: statusData.platform
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
fs.writeFileSync(STATUS_FILE, JSON.stringify(statusData, null, 2));
|
|
54
|
+
|
|
55
|
+
// Verify it was written
|
|
56
|
+
if (fs.existsSync(STATUS_FILE)) {
|
|
57
|
+
logger.debug('Status file written and verified', { statusFile: STATUS_FILE });
|
|
58
|
+
|
|
59
|
+
// Read it back to verify content
|
|
60
|
+
const writtenContent = fs.readFileSync(STATUS_FILE, 'utf8');
|
|
61
|
+
logger.debug('Status file content verification', {
|
|
62
|
+
contentLength: writtenContent.length,
|
|
63
|
+
parseable: true
|
|
64
|
+
});
|
|
65
|
+
} else {
|
|
66
|
+
logger.error('Status file does not exist after write!', { statusFile: STATUS_FILE });
|
|
67
|
+
}
|
|
44
68
|
} catch (error) {
|
|
45
|
-
logger.error('Failed to write status file', {
|
|
69
|
+
logger.error('Failed to write status file in background process', {
|
|
70
|
+
error: error.message,
|
|
71
|
+
stack: error.stack,
|
|
72
|
+
statusFile: STATUS_FILE
|
|
73
|
+
});
|
|
46
74
|
}
|
|
47
75
|
}
|
|
48
76
|
|
package/bin/dashcam.js
CHANGED
|
@@ -395,8 +395,39 @@ 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('os').homedir() + '/.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').homedir(), '.dashcam-cli', 'status.json'),
|
|
413
|
+
statusFileExists: require('fs').existsSync(require('path').join(require('os').homedir(), '.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').homedir(), '.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
|
+
}
|
|
427
|
+
} catch (err) {
|
|
428
|
+
logger.error('Failed to read status file for debugging', { error: err.message });
|
|
429
|
+
}
|
|
430
|
+
|
|
400
431
|
process.exit(0);
|
|
401
432
|
}
|
|
402
433
|
|
package/lib/processManager.js
CHANGED
|
@@ -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
|
|