1- const { ipcRenderer } = require ( 'electron' ) ;
2-
31let cpuUsageHistory = [ ] ;
42let gpuUsageHistory = [ ] ;
53const maxHistory = 30 ;
64
7- ipcRenderer . on ( 'update-stats' , ( event , stats ) => {
5+ // Prosty FPS counter via requestAnimationFrame
6+ let fps = 0 ;
7+ let frameCount = 0 ;
8+ let lastTime = performance . now ( ) ;
9+
10+ let recorder ;
11+ let chunks = [ ] ;
12+ let stream ;
13+
14+ function updateFPS ( ) {
15+ const now = performance . now ( ) ;
16+ frameCount ++ ;
17+ if ( now - lastTime >= 1000 ) {
18+ fps = frameCount ;
19+ frameCount = 0 ;
20+ lastTime = now ;
21+ }
22+ document . getElementById ( 'fps' ) . textContent = fps ;
23+ requestAnimationFrame ( updateFPS ) ;
24+ }
25+
26+ requestAnimationFrame ( updateFPS ) ; // Uruchom counter
27+
28+ window . electronAPI . onUpdateStats ( ( event , stats ) => {
829 document . getElementById ( 'cpu-temp' ) . textContent = stats . cpuTemp ;
930 document . getElementById ( 'cpu-usage' ) . textContent = stats . cpuUsage ;
1031 document . getElementById ( 'cpu-freq' ) . textContent = stats . cpuFreq ;
11- document . getElementById ( 'cpu-voltage ' ) . textContent = stats . cpuVoltage ;
32+ document . getElementById ( 'cpu-cores ' ) . textContent = stats . cpuCores ; // Nowe pole
1233 document . getElementById ( 'cpu-fan' ) . textContent = stats . cpuFan ;
13- document . getElementById ( 'gpu-temp' ) . textContent = stats . gpuTemp ;
14- document . getElementById ( 'gpu-usage' ) . textContent = stats . gpuUsage ;
15- document . getElementById ( 'gpu-fan' ) . textContent = stats . gpuFan ;
16- document . getElementById ( 'gpu-mem' ) . textContent = stats . gpuMem ;
17- document . getElementById ( 'gpu-power' ) . textContent = stats . gpuPower ;
1834 document . getElementById ( 'ram-usage' ) . textContent = stats . ramUsage ;
1935 document . getElementById ( 'disk-usage' ) . textContent = stats . diskUsage ;
2036 document . getElementById ( 'battery-level' ) . textContent = stats . batteryLevel ;
2137 document . getElementById ( 'uptime' ) . textContent = stats . uptime ;
2238 document . getElementById ( 'net-download' ) . textContent = stats . netDownload ;
2339 document . getElementById ( 'net-upload' ) . textContent = stats . netUpload ;
24- document . getElementById ( 'fps' ) . textContent = stats . fps ;
2540 document . getElementById ( 'load-avg' ) . textContent = stats . loadAvg ;
2641
27- if ( stats . cpuUsage !== 'N/A ' ) {
42+ if ( stats . cpuUsage !== '-- ' ) {
2843 cpuUsageHistory . push ( parseFloat ( stats . cpuUsage ) ) ;
2944 if ( cpuUsageHistory . length > maxHistory ) cpuUsageHistory . shift ( ) ;
3045 drawCpuChart ( ) ;
3146 drawCpuGauge ( parseFloat ( stats . cpuUsage ) || 0 ) ;
3247 }
3348
34- if ( stats . gpuUsage !== 'N/A ' ) {
49+ if ( stats . gpuUsage !== '-- ' ) {
3550 gpuUsageHistory . push ( parseFloat ( stats . gpuUsage ) ) ;
3651 if ( gpuUsageHistory . length > maxHistory ) gpuUsageHistory . shift ( ) ;
3752 drawGpuChart ( ) ;
38- drawGpuGauge ( parseFloat ( stats . gpuUsage ) || 0 ) ;
53+ }
54+ } ) ;
55+
56+ window . electronAPI . onGetRects ( ( ) => {
57+ const topRightElement = document . querySelector ( '.overlay-top-right' ) ;
58+ const topRight = topRightElement . getBoundingClientRect ( ) ;
59+ window . electronAPI . send ( 'rects' , {
60+ topRight : {
61+ top : topRight . top ,
62+ right : parseFloat ( getComputedStyle ( topRightElement ) . right ) , // right z CSS (30px)
63+ width : topRight . width ,
64+ height : topRight . height
65+ }
66+ } ) ;
67+ } ) ;
68+
69+ document . getElementById ( 'screenshot-btn' ) . addEventListener ( 'click' , ( ) => {
70+ window . electronAPI . send ( 'take-screenshot' ) ;
71+ } ) ;
72+
73+ document . getElementById ( 'record-btn' ) . addEventListener ( 'click' , async ( ) => {
74+ try {
75+ const sources = await window . electronAPI . desktopCapturer . getSources ( { types : [ 'screen' ] } ) ;
76+ const sourceId = sources [ 0 ] . id ;
77+ const constraints = {
78+ audio : false ,
79+ video : {
80+ mandatory : {
81+ chromeMediaSource : 'desktop' ,
82+ chromeMediaSourceId : sourceId
83+ }
84+ }
85+ } ;
86+ stream = await navigator . mediaDevices . getUserMedia ( constraints ) ;
87+ recorder = new MediaRecorder ( stream ) ;
88+ chunks = [ ] ;
89+ recorder . ondataavailable = ( e ) => chunks . push ( e . data ) ;
90+ recorder . onstop = ( ) => {
91+ const blob = new Blob ( chunks , { type : 'video/webm' } ) ;
92+ const url = URL . createObjectURL ( blob ) ;
93+ const a = document . createElement ( 'a' ) ;
94+ a . href = url ;
95+ a . download = `recording_${ Date . now ( ) } .webm` ;
96+ a . click ( ) ;
97+ URL . revokeObjectURL ( url ) ;
98+ if ( stream ) {
99+ stream . getTracks ( ) . forEach ( track => track . stop ( ) ) ;
100+ }
101+ } ;
102+ recorder . start ( ) ;
103+ window . electronAPI . send ( 'start-recording' ) ;
104+ } catch ( err ) {
105+ console . error ( 'Error starting recording:' , err ) ;
106+ }
107+ } ) ;
108+
109+ window . electronAPI . onStopRecording ( ( ) => {
110+ if ( recorder ) {
111+ recorder . stop ( ) ;
39112 }
40113} ) ;
41114
@@ -51,6 +124,7 @@ function drawGpuChart() {
51124
52125function drawLineChart ( ctx , data , color ) {
53126 ctx . clearRect ( 0 , 0 , ctx . canvas . width , ctx . canvas . height ) ;
127+ if ( data . length === 0 ) return ;
54128 ctx . beginPath ( ) ;
55129 ctx . strokeStyle = color ;
56130 ctx . lineWidth = 2 ;
@@ -69,11 +143,6 @@ function drawCpuGauge(value) {
69143 drawGauge ( ctx , value / 100 , '#00BFFF' , 'CPU Usage' ) ;
70144}
71145
72- function drawGpuGauge ( value ) {
73- const ctx = document . getElementById ( 'gpu-gauge' ) . getContext ( '2d' ) ;
74- drawGauge ( ctx , value / 100 , '#FF4500' , 'GPU Usage' ) ;
75- }
76-
77146function drawGauge ( ctx , percent , color , label ) {
78147 const width = ctx . canvas . width ;
79148 const height = ctx . canvas . height ;
0 commit comments