1- #include "fastfetch.h"
2- #include "common/io/io.h"
31#include "battery.h"
2+ #include "common/io/io.h"
3+ #include "detection/temps/temps_linux.h"
44#include "util/stringUtils.h"
55
66#include <dirent.h>
77
8- static void parseBattery (FFstrbuf * dir , FFlist * results )
8+ static void parseBattery (FFstrbuf * dir , const char * id , FFBatteryOptions * options , FFlist * results )
99{
1010 uint32_t dirLength = dir -> length ;
1111
@@ -65,7 +65,26 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
6565 ffReadFileBuffer (dir -> chars , & result -> status );
6666 ffStrbufSubstrBefore (dir , dirLength );
6767
68+ ffStrbufAppendS (dir , "/cycle_count" );
69+ ffReadFileBuffer (dir -> chars , & testBatteryBuffer );
70+ ffStrbufSubstrBefore (dir , dirLength );
71+ if (dir -> length )
72+ result -> cycleCount = (int32_t ) ffStrbufToUInt (& testBatteryBuffer , 0 );
73+
6874 result -> temperature = FF_BATTERY_TEMP_UNSET ;
75+ if (options -> temp )
76+ {
77+ const FFlist * tempsResult = ffDetectTemps ();
78+
79+ FF_LIST_FOR_EACH (FFTempValue , value , * tempsResult )
80+ {
81+ if (ffStrbufEqualS (& value -> name , id ))
82+ {
83+ result -> temperature = value -> value ;
84+ break ;
85+ }
86+ }
87+ }
6988}
7089
7190const char * ffDetectBattery (FFBatteryOptions * options , FFlist * results )
@@ -84,7 +103,7 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results)
84103
85104 uint32_t baseDirLength = baseDir .length ;
86105
87- DIR * dirp = opendir (baseDir .chars );
106+ FF_AUTO_CLOSE_DIR DIR * dirp = opendir (baseDir .chars );
88107 if (dirp == NULL )
89108 return "opendir(batteryDir) == NULL" ;
90109
@@ -95,12 +114,10 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results)
95114 continue ;
96115
97116 ffStrbufAppendS (& baseDir , entry -> d_name );
98- parseBattery (& baseDir , results );
117+ parseBattery (& baseDir , entry -> d_name , options , results );
99118 ffStrbufSubstrBefore (& baseDir , baseDirLength );
100119 }
101120
102- closedir (dirp );
103-
104121 if (results -> length == 0 )
105122 return "batteryDir doesn't contain any battery folder" ;
106123
0 commit comments