dashcam 1.3.12-beta → 1.3.13-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/lib/processManager.js +3 -24
- package/package.json +1 -1
package/lib/processManager.js
CHANGED
|
@@ -10,7 +10,6 @@ const __dirname = path.dirname(__filename);
|
|
|
10
10
|
|
|
11
11
|
// Use a fixed directory in the user's home directory for cross-process communication
|
|
12
12
|
const PROCESS_DIR = path.join(os.homedir(), '.dashcam-cli');
|
|
13
|
-
const PID_FILE = path.join(PROCESS_DIR, 'recording.pid');
|
|
14
13
|
const STATUS_FILE = path.join(PROCESS_DIR, 'status.json');
|
|
15
14
|
const RESULT_FILE = path.join(PROCESS_DIR, 'upload-result.json');
|
|
16
15
|
|
|
@@ -82,24 +81,6 @@ class ProcessManager {
|
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
|
|
85
|
-
writePid(pid = process.pid) {
|
|
86
|
-
try {
|
|
87
|
-
fs.writeFileSync(PID_FILE, pid.toString());
|
|
88
|
-
} catch (error) {
|
|
89
|
-
logger.error('Failed to write PID file', { error });
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
readPid() {
|
|
94
|
-
try {
|
|
95
|
-
if (!fs.existsSync(PID_FILE)) return null;
|
|
96
|
-
const pid = parseInt(fs.readFileSync(PID_FILE, 'utf8').trim());
|
|
97
|
-
return isNaN(pid) ? null : pid;
|
|
98
|
-
} catch (error) {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
84
|
isProcessRunning(pid) {
|
|
104
85
|
if (!pid) return false;
|
|
105
86
|
try {
|
|
@@ -111,16 +92,15 @@ class ProcessManager {
|
|
|
111
92
|
}
|
|
112
93
|
|
|
113
94
|
isRecordingActive() {
|
|
114
|
-
const pid = this.readPid();
|
|
115
95
|
const status = this.readStatus();
|
|
116
96
|
|
|
117
|
-
if (!pid || !this.isProcessRunning(pid)) {
|
|
97
|
+
if (!status || !status.pid || !this.isProcessRunning(status.pid)) {
|
|
118
98
|
// Clean up but preserve upload result in case the background process just finished uploading
|
|
119
99
|
this.cleanup({ preserveResult: true });
|
|
120
100
|
return false;
|
|
121
101
|
}
|
|
122
102
|
|
|
123
|
-
return status
|
|
103
|
+
return status.isRecording;
|
|
124
104
|
}
|
|
125
105
|
|
|
126
106
|
getActiveStatus() {
|
|
@@ -131,7 +111,6 @@ class ProcessManager {
|
|
|
131
111
|
cleanup(options = {}) {
|
|
132
112
|
const { preserveResult = false } = options;
|
|
133
113
|
try {
|
|
134
|
-
if (fs.existsSync(PID_FILE)) fs.unlinkSync(PID_FILE);
|
|
135
114
|
if (fs.existsSync(STATUS_FILE)) fs.unlinkSync(STATUS_FILE);
|
|
136
115
|
if (!preserveResult && fs.existsSync(RESULT_FILE)) fs.unlinkSync(RESULT_FILE);
|
|
137
116
|
} catch (error) {
|
|
@@ -149,13 +128,13 @@ class ProcessManager {
|
|
|
149
128
|
|
|
150
129
|
try {
|
|
151
130
|
const status = this.readStatus();
|
|
152
|
-
const pid = this.readPid();
|
|
153
131
|
|
|
154
132
|
if (!status || !status.isRecording) {
|
|
155
133
|
logger.warn('No active recording found');
|
|
156
134
|
return false;
|
|
157
135
|
}
|
|
158
136
|
|
|
137
|
+
const pid = status.pid;
|
|
159
138
|
if (!pid || !this.isProcessRunning(pid)) {
|
|
160
139
|
logger.warn('Background process not running');
|
|
161
140
|
this.cleanup({ preserveResult: true });
|