dashcam 1.3.6-beta → 1.3.8-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 +20 -1
- package/lib/processManager.js +18 -6
- package/package.json +1 -1
|
@@ -12,10 +12,21 @@ import path from 'path';
|
|
|
12
12
|
import os from 'os';
|
|
13
13
|
|
|
14
14
|
// Get process directory for status files
|
|
15
|
-
|
|
15
|
+
// Use a fixed system-wide directory for cross-process communication
|
|
16
|
+
// On Windows: C:\ProgramData\dashcam-cli
|
|
17
|
+
// On Unix: /tmp/dashcam-cli
|
|
18
|
+
const PROCESS_DIR = process.platform === 'win32'
|
|
19
|
+
? path.join('C:', 'ProgramData', 'dashcam-cli')
|
|
20
|
+
: path.join('/tmp', 'dashcam-cli');
|
|
21
|
+
const PID_FILE = path.join(PROCESS_DIR, 'recording.pid');
|
|
16
22
|
const STATUS_FILE = path.join(PROCESS_DIR, 'status.json');
|
|
17
23
|
const RESULT_FILE = path.join(PROCESS_DIR, 'upload-result.json');
|
|
18
24
|
|
|
25
|
+
// Ensure process directory exists
|
|
26
|
+
if (!fs.existsSync(PROCESS_DIR)) {
|
|
27
|
+
fs.mkdirSync(PROCESS_DIR, { recursive: true });
|
|
28
|
+
}
|
|
29
|
+
|
|
19
30
|
// Parse options from command line argument
|
|
20
31
|
const optionsJson = process.argv[2];
|
|
21
32
|
if (!optionsJson) {
|
|
@@ -33,6 +44,14 @@ logger.info('Background recording process started', {
|
|
|
33
44
|
options
|
|
34
45
|
});
|
|
35
46
|
|
|
47
|
+
// Write PID file immediately
|
|
48
|
+
try {
|
|
49
|
+
fs.writeFileSync(PID_FILE, process.pid.toString());
|
|
50
|
+
logger.info('PID file written', { path: PID_FILE, pid: process.pid });
|
|
51
|
+
} catch (error) {
|
|
52
|
+
logger.error('Failed to write PID file', { error });
|
|
53
|
+
}
|
|
54
|
+
|
|
36
55
|
// Write status file
|
|
37
56
|
function writeStatus(status) {
|
|
38
57
|
try {
|
package/lib/processManager.js
CHANGED
|
@@ -8,8 +8,12 @@ import { logger } from './logger.js';
|
|
|
8
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
9
|
const __dirname = path.dirname(__filename);
|
|
10
10
|
|
|
11
|
-
// Use a fixed
|
|
12
|
-
|
|
11
|
+
// Use a fixed system-wide directory for cross-process communication
|
|
12
|
+
// On Windows: C:\ProgramData\dashcam-cli
|
|
13
|
+
// On Unix: /tmp/dashcam-cli
|
|
14
|
+
const PROCESS_DIR = process.platform === 'win32'
|
|
15
|
+
? path.join('C:', 'ProgramData', 'dashcam-cli')
|
|
16
|
+
: path.join('/tmp', 'dashcam-cli');
|
|
13
17
|
const PID_FILE = path.join(PROCESS_DIR, 'recording.pid');
|
|
14
18
|
const STATUS_FILE = path.join(PROCESS_DIR, 'status.json');
|
|
15
19
|
const RESULT_FILE = path.join(PROCESS_DIR, 'upload-result.json');
|
|
@@ -111,16 +115,23 @@ class ProcessManager {
|
|
|
111
115
|
}
|
|
112
116
|
|
|
113
117
|
isRecordingActive() {
|
|
114
|
-
const pid = this.readPid();
|
|
115
118
|
const status = this.readStatus();
|
|
116
119
|
|
|
117
|
-
if (!
|
|
120
|
+
if (!status || !status.pid) {
|
|
118
121
|
// Clean up but preserve upload result in case the background process just finished uploading
|
|
119
122
|
this.cleanup({ preserveResult: true });
|
|
120
123
|
return false;
|
|
121
124
|
}
|
|
122
125
|
|
|
123
|
-
|
|
126
|
+
const pid = status.pid;
|
|
127
|
+
|
|
128
|
+
if (!this.isProcessRunning(pid)) {
|
|
129
|
+
// Clean up but preserve upload result in case the background process just finished uploading
|
|
130
|
+
this.cleanup({ preserveResult: true });
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return status.isRecording;
|
|
124
135
|
}
|
|
125
136
|
|
|
126
137
|
getActiveStatus() {
|
|
@@ -149,13 +160,14 @@ class ProcessManager {
|
|
|
149
160
|
|
|
150
161
|
try {
|
|
151
162
|
const status = this.readStatus();
|
|
152
|
-
const pid = this.readPid();
|
|
153
163
|
|
|
154
164
|
if (!status || !status.isRecording) {
|
|
155
165
|
logger.warn('No active recording found');
|
|
156
166
|
return false;
|
|
157
167
|
}
|
|
158
168
|
|
|
169
|
+
const pid = status.pid;
|
|
170
|
+
|
|
159
171
|
if (!pid || !this.isProcessRunning(pid)) {
|
|
160
172
|
logger.warn('Background process not running');
|
|
161
173
|
this.cleanup({ preserveResult: true });
|