|
1 | | -import { nativeImage, Tray, Menu, app, globalShortcut } from 'electron'; |
| 1 | +import { nativeImage, Tray, Menu, app, globalShortcut, desktopCapturer } from 'electron'; |
2 | 2 | import { TelemetrySink } from './bridge/iracingSdk/telemetrySink'; |
3 | 3 | import { OverlayManager } from './overlayManager'; |
| 4 | +import { writeFile } from 'node:fs/promises'; |
| 5 | +import path from 'node:path'; |
4 | 6 |
|
5 | 7 | class Taskbar { |
6 | 8 | private tray: Tray; |
@@ -65,11 +67,34 @@ class Taskbar { |
65 | 67 | this.overlayManager.toggleLockOverlays(); |
66 | 68 | } |
67 | 69 |
|
68 | | - private saveTelemetry(): void { |
69 | | - if (process.platform === 'darwin') return; |
70 | | - import('./bridge/iracingSdk/dumpTelemetry').then( |
71 | | - async ({ dumpCurrentTelemetry }) => await dumpCurrentTelemetry() |
72 | | - ); |
| 70 | + private async saveTelemetry(): Promise<void> { |
| 71 | + try { |
| 72 | + // First, import and call dumpTelemetry to get the directory path |
| 73 | + const { dumpCurrentTelemetry } = await import('./bridge/iracingSdk/dumpTelemetry'); |
| 74 | + const telemetryResult = await dumpCurrentTelemetry(); |
| 75 | + |
| 76 | + // Check if dirPath exists and is not null |
| 77 | + const dirPath = telemetryResult && 'dirPath' in telemetryResult ? telemetryResult.dirPath : null; |
| 78 | + if (dirPath) { |
| 79 | + // Capture all screens |
| 80 | + const sources = await desktopCapturer.getSources({ |
| 81 | + types: ['screen'], |
| 82 | + thumbnailSize: { width: 1920, height: 1080 } // Use a standard resolution |
| 83 | + }); |
| 84 | + |
| 85 | + // Save each screen as a separate file |
| 86 | + await Promise.all(sources.map(async (source, index) => { |
| 87 | + if (source.thumbnail) { |
| 88 | + const screenshotPath = path.join(dirPath, `screenshot_${index + 1}.png`); |
| 89 | + const pngData = source.thumbnail.toPNG(); |
| 90 | + await writeFile(screenshotPath, pngData); |
| 91 | + console.log(`Screenshot ${index + 1} saved to: ${screenshotPath}`); |
| 92 | + } |
| 93 | + })); |
| 94 | + } |
| 95 | + } catch (error) { |
| 96 | + console.error('Error capturing screenshots:', error); |
| 97 | + } |
73 | 98 | } |
74 | 99 |
|
75 | 100 | private registerShortcuts(): void { |
|
0 commit comments