dashcam 1.0.1-beta.27 → 1.0.1-beta.28

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.js CHANGED
@@ -466,58 +466,43 @@ program
466
466
 
467
467
  console.log('Recording stopped successfully');
468
468
 
469
- // Wait for upload to complete (background process handles this)
470
- logger.debug('Waiting for background upload to complete...');
471
- console.log(' Uploading recording...');
472
-
473
- // Wait up to 2 minutes for upload result to appear
474
- const maxWaitForUpload = 120000; // 2 minutes
475
- const startWaitForUpload = Date.now();
476
- let uploadResult = null;
477
-
478
- while (!uploadResult && (Date.now() - startWaitForUpload) < maxWaitForUpload) {
479
- uploadResult = processManager.readUploadResult();
480
- if (!uploadResult) {
481
- await new Promise(resolve => setTimeout(resolve, 1000)); // Check every second
482
- }
483
- }
484
-
485
- logger.debug('Upload result read attempt', { found: !!uploadResult, shareLink: uploadResult?.shareLink });
486
-
487
- if (uploadResult && uploadResult.shareLink) {
488
- console.log('📹 Watch your recording:', uploadResult.shareLink);
489
- // Clean up the result file now that we've read it
469
+ // Check if the result already has a shareLink (from signal handler upload)
470
+ if (result.shareLink) {
471
+ console.log('📹 Watch your recording:', result.shareLink);
490
472
  processManager.cleanup();
491
473
  process.exit(0);
492
474
  }
493
475
 
494
- // Check if files still exist - if not, background process already uploaded
495
- const filesExist = fs.existsSync(result.outputPath) &&
496
- (!result.gifPath || fs.existsSync(result.gifPath)) &&
497
- (!result.snapshotPath || fs.existsSync(result.snapshotPath));
476
+ // Otherwise, check if upload result file was written
477
+ const uploadResultFromFile = processManager.readUploadResult();
478
+ logger.debug('Upload result read attempt', { found: !!uploadResultFromFile, shareLink: uploadResultFromFile?.shareLink });
498
479
 
499
- if (!filesExist) {
500
- console.log(' Recording uploaded by background process');
501
- logger.info('Files were cleaned up by background process');
480
+ if (uploadResultFromFile && uploadResultFromFile.shareLink) {
481
+ console.log('📹 Watch your recording:', uploadResultFromFile.shareLink);
482
+ processManager.cleanup();
502
483
  process.exit(0);
503
484
  }
504
485
 
505
- // Always attempt to upload - let upload function find project if needed
486
+ // No upload result found - need to upload ourselves
487
+ // This commonly happens on Windows where signal handlers work differently
488
+ logger.info('No upload result found, uploading now...');
506
489
  console.log('Uploading recording...');
490
+
507
491
  try {
508
492
  const uploadResult = await upload(result.outputPath, {
509
493
  title: activeStatus?.options?.title,
510
494
  description: activeStatus?.options?.description,
511
- project: activeStatus?.options?.project, // May be undefined, that's ok
495
+ project: activeStatus?.options?.project,
512
496
  duration: result.duration,
513
497
  clientStartDate: result.clientStartDate,
514
498
  apps: result.apps,
515
- icons: result.icons,
499
+ logs: result.logs,
516
500
  gifPath: result.gifPath,
517
501
  snapshotPath: result.snapshotPath
518
502
  });
519
503
 
520
504
  console.log('📹 Watch your recording:', uploadResult.shareLink);
505
+ processManager.cleanup();
521
506
  } catch (uploadError) {
522
507
  console.error('Upload failed:', uploadError.message);
523
508
  console.log('Recording saved locally:', result.outputPath);
@@ -171,9 +171,14 @@ class ProcessManager {
171
171
  this.cleanup({ preserveResult: true });
172
172
  return result;
173
173
  } else {
174
- // Different process - send signal (for backward compatibility if needed)
174
+ // Different process - send signal to stop it
175
175
  logger.info('Stopping active recording process', { pid });
176
- process.kill(pid, 'SIGINT');
176
+
177
+ try {
178
+ process.kill(pid, 'SIGINT');
179
+ } catch (error) {
180
+ logger.warn('Failed to send SIGINT, process may have already exited', { error: error.message });
181
+ }
177
182
 
178
183
  // Wait for the process to actually finish
179
184
  const maxWaitTime = 120000; // 2 minutes max
@@ -185,12 +190,55 @@ class ProcessManager {
185
190
 
186
191
  if (this.isProcessRunning(pid)) {
187
192
  logger.warn('Process did not stop within timeout, forcing termination');
188
- process.kill(pid, 'SIGKILL');
193
+ try {
194
+ process.kill(pid, 'SIGKILL');
195
+ } catch (error) {
196
+ logger.warn('Failed to send SIGKILL', { error: error.message });
197
+ }
189
198
  await new Promise(resolve => setTimeout(resolve, 1000));
190
199
  }
191
200
 
201
+ // Wait a bit for upload result file to be written by the signal handler
202
+ logger.debug('Waiting for upload result file...');
203
+ const maxWaitForUpload = 10000; // 10 seconds
204
+ const startWaitForUpload = Date.now();
205
+ let uploadResult = null;
206
+
207
+ while (!uploadResult && (Date.now() - startWaitForUpload) < maxWaitForUpload) {
208
+ uploadResult = this.readUploadResult();
209
+ if (!uploadResult) {
210
+ await new Promise(resolve => setTimeout(resolve, 500));
211
+ }
212
+ }
213
+
214
+ // If upload result exists, the signal handler did the upload
215
+ if (uploadResult) {
216
+ logger.info('Upload completed by recording process');
217
+ if (status) {
218
+ const basePath = status.outputPath.substring(0, status.outputPath.lastIndexOf('.'));
219
+ const result = {
220
+ outputPath: status.outputPath,
221
+ gifPath: `${basePath}.gif`,
222
+ snapshotPath: `${basePath}.png`,
223
+ duration: Date.now() - status.startTime,
224
+ clientStartDate: status.startTime,
225
+ apps: [],
226
+ logs: [],
227
+ shareLink: uploadResult.shareLink,
228
+ replayId: uploadResult.replayId
229
+ };
230
+
231
+ this.cleanup({ preserveResult: false }); // Clean up everything including result
232
+ return result;
233
+ }
234
+ }
235
+
236
+ // If no upload result, we need to handle it ourselves
237
+ // This can happen on Windows where signal handlers don't work the same way
238
+ logger.warn('No upload result found, handling upload in stop command');
239
+
192
240
  if (status) {
193
- logger.info('Recording stopped, returning status', {
241
+ logger.info('Reconstructing result from status', {
194
242
  outputPath: status.outputPath,
195
243
  duration: Date.now() - status.startTime
196
244
  });
@@ -206,7 +254,14 @@ class ProcessManager {
206
254
  logs: []
207
255
  };
208
256
 
209
- this.cleanup({ preserveResult: true });
257
+ // Don't cleanup yet - let the stop command handle upload
258
+ // Just update status to not recording
259
+ this.writeStatus({
260
+ isRecording: false,
261
+ completedTime: Date.now(),
262
+ pid: status.pid
263
+ });
264
+
210
265
  return result;
211
266
  } else {
212
267
  throw new Error('No status information available for active recording');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dashcam",
3
- "version": "1.0.1-beta.27",
3
+ "version": "1.0.1-beta.28",
4
4
  "description": "Minimal CLI version of Dashcam desktop app",
5
5
  "main": "bin/index.js",
6
6
  "bin": {