dashcam 1.3.6-beta → 1.3.7-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 +14 -0
- package/lib/processManager.js +12 -4
- package/package.json +1 -1
|
@@ -13,9 +13,15 @@ import os from 'os';
|
|
|
13
13
|
|
|
14
14
|
// Get process directory for status files
|
|
15
15
|
const PROCESS_DIR = path.join(os.homedir(), '.dashcam-cli');
|
|
16
|
+
const PID_FILE = path.join(PROCESS_DIR, 'recording.pid');
|
|
16
17
|
const STATUS_FILE = path.join(PROCESS_DIR, 'status.json');
|
|
17
18
|
const RESULT_FILE = path.join(PROCESS_DIR, 'upload-result.json');
|
|
18
19
|
|
|
20
|
+
// Ensure process directory exists
|
|
21
|
+
if (!fs.existsSync(PROCESS_DIR)) {
|
|
22
|
+
fs.mkdirSync(PROCESS_DIR, { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
|
|
19
25
|
// Parse options from command line argument
|
|
20
26
|
const optionsJson = process.argv[2];
|
|
21
27
|
if (!optionsJson) {
|
|
@@ -33,6 +39,14 @@ logger.info('Background recording process started', {
|
|
|
33
39
|
options
|
|
34
40
|
});
|
|
35
41
|
|
|
42
|
+
// Write PID file immediately
|
|
43
|
+
try {
|
|
44
|
+
fs.writeFileSync(PID_FILE, process.pid.toString());
|
|
45
|
+
logger.info('PID file written', { path: PID_FILE, pid: process.pid });
|
|
46
|
+
} catch (error) {
|
|
47
|
+
logger.error('Failed to write PID file', { error });
|
|
48
|
+
}
|
|
49
|
+
|
|
36
50
|
// Write status file
|
|
37
51
|
function writeStatus(status) {
|
|
38
52
|
try {
|
package/lib/processManager.js
CHANGED
|
@@ -111,16 +111,23 @@ class ProcessManager {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
isRecordingActive() {
|
|
114
|
-
const pid = this.readPid();
|
|
115
114
|
const status = this.readStatus();
|
|
116
115
|
|
|
117
|
-
if (!
|
|
116
|
+
if (!status || !status.pid) {
|
|
118
117
|
// Clean up but preserve upload result in case the background process just finished uploading
|
|
119
118
|
this.cleanup({ preserveResult: true });
|
|
120
119
|
return false;
|
|
121
120
|
}
|
|
122
121
|
|
|
123
|
-
|
|
122
|
+
const pid = status.pid;
|
|
123
|
+
|
|
124
|
+
if (!this.isProcessRunning(pid)) {
|
|
125
|
+
// Clean up but preserve upload result in case the background process just finished uploading
|
|
126
|
+
this.cleanup({ preserveResult: true });
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return status.isRecording;
|
|
124
131
|
}
|
|
125
132
|
|
|
126
133
|
getActiveStatus() {
|
|
@@ -149,13 +156,14 @@ class ProcessManager {
|
|
|
149
156
|
|
|
150
157
|
try {
|
|
151
158
|
const status = this.readStatus();
|
|
152
|
-
const pid = this.readPid();
|
|
153
159
|
|
|
154
160
|
if (!status || !status.isRecording) {
|
|
155
161
|
logger.warn('No active recording found');
|
|
156
162
|
return false;
|
|
157
163
|
}
|
|
158
164
|
|
|
165
|
+
const pid = status.pid;
|
|
166
|
+
|
|
159
167
|
if (!pid || !this.isProcessRunning(pid)) {
|
|
160
168
|
logger.warn('Background process not running');
|
|
161
169
|
this.cleanup({ preserveResult: true });
|