dashcam 1.0.1-beta.32 → 1.0.1-beta.34

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.
@@ -55,8 +55,13 @@ function writeUploadResult(result) {
55
55
  timestamp: Date.now()
56
56
  }, null, 2));
57
57
  logger.info('Successfully wrote upload result to file');
58
+ // Verify the file was written
59
+ if (fs.existsSync(RESULT_FILE)) {
60
+ const content = fs.readFileSync(RESULT_FILE, 'utf8');
61
+ logger.info('Verified upload result file exists and contains', { content: content.substring(0, 100) });
62
+ }
58
63
  } catch (error) {
59
- logger.error('Failed to write upload result file', { error });
64
+ logger.error('Failed to write upload result file', { error: error.message, stack: error.stack });
60
65
  }
61
66
  }
62
67
 
@@ -99,10 +104,11 @@ async function runBackgroundRecording() {
99
104
  }
100
105
  isShuttingDown = true;
101
106
 
102
- logger.info(`Received ${signal}, stopping background recording...`);
107
+ logger.info(`Received ${signal} signal, stopping background recording...`, { pid: process.pid });
103
108
 
104
109
  try {
105
110
  // Stop the recording
111
+ logger.info('Calling stopRecording...');
106
112
  const stopResult = await stopRecording();
107
113
 
108
114
  if (stopResult) {
@@ -128,10 +134,12 @@ async function runBackgroundRecording() {
128
134
  logger.info('Upload complete', { shareLink: uploadResult.shareLink });
129
135
 
130
136
  // Write upload result for stop command to read
137
+ logger.info('About to write upload result...');
131
138
  writeUploadResult({
132
139
  shareLink: uploadResult.shareLink,
133
140
  replayId: uploadResult.replay?.id
134
141
  });
142
+ logger.info('Upload result written successfully');
135
143
  }
136
144
 
137
145
  // Update status to indicate recording stopped
@@ -144,13 +152,19 @@ async function runBackgroundRecording() {
144
152
  logger.info('Background process exiting successfully');
145
153
  process.exit(0);
146
154
  } catch (error) {
147
- logger.error('Error during shutdown:', error);
155
+ logger.error('Error during shutdown:', { error: error.message, stack: error.stack });
148
156
  process.exit(1);
149
157
  }
150
158
  };
151
159
 
152
- process.on('SIGINT', () => handleShutdown('SIGINT'));
153
- process.on('SIGTERM', () => handleShutdown('SIGTERM'));
160
+ process.on('SIGINT', () => {
161
+ logger.info('SIGINT handler triggered');
162
+ handleShutdown('SIGINT');
163
+ });
164
+ process.on('SIGTERM', () => {
165
+ logger.info('SIGTERM handler triggered');
166
+ handleShutdown('SIGTERM');
167
+ });
154
168
 
155
169
  // Keep the process alive
156
170
  logger.info('Background recording is now running. Waiting for stop signal...');
package/bin/dashcam.js CHANGED
@@ -136,10 +136,7 @@ async function recordingAction(options, command) {
136
136
  log('Use "dashcam status" to check progress');
137
137
  log('Use "dashcam stop" to stop recording and upload');
138
138
 
139
- // Close stdout/stderr and exit immediately to prevent blocking
140
- // when called from automation scripts with piped output
141
- process.stdout.end();
142
- process.stderr.end();
139
+ // Process can exit now - background process is detached
143
140
  process.exit(0);
144
141
 
145
142
  } catch (error) {
@@ -59,22 +59,26 @@ class ProcessManager {
59
59
  logger.info('Successfully wrote upload result to file');
60
60
  // Verify it was written
61
61
  if (fs.existsSync(RESULT_FILE)) {
62
- logger.info('Verified upload result file exists');
62
+ const fileSize = fs.statSync(RESULT_FILE).size;
63
+ logger.info('Verified upload result file exists', { size: fileSize });
63
64
  } else {
64
65
  logger.error('Upload result file does not exist after write!');
65
66
  }
66
67
  } catch (error) {
67
- logger.error('Failed to write upload result file', { error });
68
+ logger.error('Failed to write upload result file', { error: error.message, stack: error.stack });
68
69
  }
69
70
  }
70
71
 
71
72
  readUploadResult() {
72
73
  try {
74
+ logger.debug('Checking for upload result file', { path: RESULT_FILE, exists: fs.existsSync(RESULT_FILE) });
73
75
  if (!fs.existsSync(RESULT_FILE)) return null;
74
76
  const data = fs.readFileSync(RESULT_FILE, 'utf8');
75
- return JSON.parse(data);
77
+ const result = JSON.parse(data);
78
+ logger.debug('Successfully read upload result', { shareLink: result.shareLink });
79
+ return result;
76
80
  } catch (error) {
77
- logger.error('Failed to read upload result file', { error });
81
+ logger.error('Failed to read upload result file', { error: error.message, stack: error.stack });
78
82
  return null;
79
83
  }
80
84
  }
@@ -128,11 +132,23 @@ class ProcessManager {
128
132
  cleanup(options = {}) {
129
133
  const { preserveResult = false } = options;
130
134
  try {
131
- if (fs.existsSync(PID_FILE)) fs.unlinkSync(PID_FILE);
132
- if (fs.existsSync(STATUS_FILE)) fs.unlinkSync(STATUS_FILE);
133
- if (!preserveResult && fs.existsSync(RESULT_FILE)) fs.unlinkSync(RESULT_FILE);
135
+ logger.debug('Cleanup called', { preserveResult, resultFileExists: fs.existsSync(RESULT_FILE) });
136
+ if (fs.existsSync(PID_FILE)) {
137
+ fs.unlinkSync(PID_FILE);
138
+ logger.debug('Deleted PID file');
139
+ }
140
+ if (fs.existsSync(STATUS_FILE)) {
141
+ fs.unlinkSync(STATUS_FILE);
142
+ logger.debug('Deleted STATUS file');
143
+ }
144
+ if (!preserveResult && fs.existsSync(RESULT_FILE)) {
145
+ fs.unlinkSync(RESULT_FILE);
146
+ logger.debug('Deleted RESULT file');
147
+ } else if (preserveResult && fs.existsSync(RESULT_FILE)) {
148
+ logger.debug('Preserved RESULT file');
149
+ }
134
150
  } catch (error) {
135
- logger.error('Failed to cleanup process files', { error });
151
+ logger.error('Failed to cleanup process files', { error: error.message });
136
152
  }
137
153
  }
138
154
 
@@ -159,11 +175,19 @@ class ProcessManager {
159
175
  const isWindows = process.platform === 'win32';
160
176
 
161
177
  if (isWindows) {
162
- logger.info('Windows detected, using taskkill to stop process');
178
+ logger.info('Windows detected, attempting graceful shutdown first');
163
179
  try {
164
- // Use taskkill to forcefully stop the process tree on Windows
180
+ // First try graceful shutdown without /F (force) flag
181
+ // This sends CTRL+C which Node.js can handle
165
182
  const { execSync } = await import('child_process');
166
- execSync(`taskkill /PID ${pid} /F /T`, { stdio: 'ignore' });
183
+ try {
184
+ execSync(`taskkill /PID ${pid} /T`, { stdio: 'ignore', timeout: 5000 });
185
+ logger.info('Sent graceful shutdown signal to process');
186
+ } catch (error) {
187
+ // If graceful shutdown fails or times out, force kill
188
+ logger.warn('Graceful shutdown failed, forcing termination');
189
+ execSync(`taskkill /PID ${pid} /F /T`, { stdio: 'ignore' });
190
+ }
167
191
  } catch (error) {
168
192
  logger.warn('Failed to kill process with taskkill', { error: error.message });
169
193
  }
@@ -238,20 +262,11 @@ class ProcessManager {
238
262
  const __dirname = path.dirname(__filename);
239
263
  const backgroundScript = path.join(__dirname, '..', 'bin', 'dashcam-background.js');
240
264
 
241
- // On Windows, we need to ensure stdio is completely detached
242
- const isWindows = process.platform === 'win32';
243
- const spawnOptions = {
265
+ // Spawn a detached background process
266
+ const child = spawn(process.execPath, [backgroundScript, JSON.stringify(options)], {
244
267
  detached: true,
245
268
  stdio: 'ignore'
246
- };
247
-
248
- // On Windows, also create a new process group to fully detach
249
- if (isWindows) {
250
- spawnOptions.windowsHide = true;
251
- }
252
-
253
- // Spawn a detached background process
254
- const child = spawn(process.execPath, [backgroundScript, JSON.stringify(options)], spawnOptions);
269
+ });
255
270
 
256
271
  // Unref so the parent process can exit
257
272
  child.unref();
@@ -263,8 +278,7 @@ class ProcessManager {
263
278
 
264
279
  logger.info('Background process spawned successfully', {
265
280
  pid,
266
- backgroundScript,
267
- platform: process.platform
281
+ backgroundScript
268
282
  });
269
283
 
270
284
  // Wait a moment for the background process to write its status
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dashcam",
3
- "version": "1.0.1-beta.32",
3
+ "version": "1.0.1-beta.34",
4
4
  "description": "Minimal CLI version of Dashcam desktop app",
5
5
  "main": "bin/index.js",
6
6
  "bin": {