@@ -172,6 +172,7 @@ class MCSM extends Applet.IconApplet {
172172 this . settings . bind ( "Disk_devicesList" , "Disk_devicesList" ) ;
173173 this . settings . bind ( "labelsOn" , "labelsOn" ) ;
174174 this . settings . bind ( "borderOn" , "borderOn" ) ;
175+ this . settings . bind ( "graphStep" , "graphStep" ) ;
175176 this . settings . bind ( "graphSpacing" , "graphSpacing" ) ;
176177 this . settings . bind ( "percentAtEndOfLine" , "percentAtEndOfLine" ) ;
177178 this . settings . bind ( "CPU_labelOn" , "CPU_labelOn" ) ;
@@ -188,7 +189,7 @@ class MCSM extends Applet.IconApplet {
188189 this . settings . bind ( "backgroundColor" , "backgroundColor" ) ;
189190 this . settings . bind ( "CPU_enabled" , "CPU_enabled" ) ;
190191 this . settings . bind ( "CPU_squared" , "CPU_squared" ) ;
191- this . settings . bind ( "CPU_width" , "CPU_width" ) ;
192+ this . settings . bind ( "CPU_width" , "CPU_width" , ( ) => { this . adjust_CPU_width ( ) } ) ;
192193 this . settings . bind ( "CPU_mergeAll" , "CPU_mergeAll" ) ;
193194 this . settings . bind ( "CPU_color0" , "CPU_color0" ) ;
194195 this . settings . bind ( "CPU_color1" , "CPU_color1" ) ;
@@ -201,7 +202,7 @@ class MCSM extends Applet.IconApplet {
201202 this . settings . bind ( "CPU_activity_80_100" , "CPU_activity_80_100" ) ;
202203 this . settings . bind ( "Mem_enabled" , "Mem_enabled" ) ;
203204 this . settings . bind ( "Mem_squared" , "Mem_squared" ) ;
204- this . settings . bind ( "Mem_width" , "Mem_width" ) ;
205+ this . settings . bind ( "Mem_width" , "Mem_width" , ( ) => { this . adjust_Mem_width ( ) } ) ;
205206 this . settings . bind ( "Mem_startAt12Oclock" , "Mem_startAt12Oclock" ) ;
206207 this . settings . bind ( "Mem_colorUsedup" , "Mem_colorUsedup" ) ;
207208 this . settings . bind ( "Mem_colorCache" , "Mem_colorCache" ) ;
@@ -211,20 +212,20 @@ class MCSM extends Applet.IconApplet {
211212 this . settings . bind ( "Mem_swapWidth" , "Mem_swapWidth" ) ;
212213 this . settings . bind ( "Net_enabled" , "Net_enabled" ) ;
213214 this . settings . bind ( "Net_squared" , "Net_squared" ) ;
214- this . settings . bind ( "Net_width" , "Net_width" ) ;
215+ this . settings . bind ( "Net_width" , "Net_width" , ( ) => { this . adjust_Net_width ( ) } ) ;
215216 this . settings . bind ( "Net_mergeAll" , "Net_mergeAll" ) ;
216217 this . settings . bind ( "Net_autoscale" , "Net_autoscale" ) ;
217218 this . settings . bind ( "Net_logscale" , "Net_logscale" ) ;
218219 this . settings . bind ( "Disk_enabled" , "Disk_enabled" ) ;
219220 this . settings . bind ( "Disk_squared" , "Disk_squared" ) ;
220- this . settings . bind ( "Disk_width" , "Disk_width" ) ;
221+ this . settings . bind ( "Disk_width" , "Disk_width" , ( ) => { this . adjust_Disk_width ( ) } ) ;
221222 this . settings . bind ( "Disk_mergeAll" , "Disk_mergeAll" ) ;
222223 this . settings . bind ( "Disk_autoscale" , "Disk_autoscale" ) ;
223224 this . settings . bind ( "Disk_logscale" , "Disk_logscale" ) ;
224225 this . settings . bind ( "DiskUsage_enabled" , "DiskUsage_enabled" ) ;
225226 this . settings . bind ( "DiskUsage_labelOn" , "DiskUsage_labelOn" ) ;
226227 this . settings . bind ( "DiskUsage_squared" , "DiskUsage_squared" ) ;
227- this . settings . bind ( "DiskUsage_width" , "DiskUsage_width" ) ;
228+ this . settings . bind ( "DiskUsage_width" , "DiskUsage_width" , ( ) => { this . adjust_DiskUsage_width ( ) } ) ;
228229 this . settings . bind ( "DiskUsage_mergeAll" , "DiskUsage_mergeAll" ) ;
229230 //this.settings.bind("DiskUsage_chartType", "DiskUsage_chartType");
230231 this . DiskUsage_chartType = "bar" ;
@@ -291,6 +292,7 @@ class MCSM extends Applet.IconApplet {
291292 this . multiCpuProvider = new MultiCpuDataProvider ( this ) ;
292293 this . swapProvider = new SwapDataProvider ( this ) ;
293294 this . buffcachesharedProvider = new BufferCacheSharedDataProvider ( this ) ;
295+ this . lastDataNet = { } ;
294296 this . networkProvider = new NetDataProvider ( this ) ;
295297 this . diskProvider = new DiskDataProvider ( this ) ;
296298 this . diskUsageProvider = new DiskUsageDataProvider ( this ) ;
@@ -323,6 +325,51 @@ class MCSM extends Applet.IconApplet {
323325 this . actor . add_actor ( this . graphArea ) ;
324326 this . graphArea . connect ( 'repaint' , ( area ) => this . onGraphRepaint ( area ) ) ;
325327 }
328+
329+ adjust_CPU_width ( ) {
330+ if ( this . graphStep === 1 ) return ;
331+ let CPU_width = Math . max (
332+ Math . min ( this . graphStep , 16 ) ,
333+ Math . round ( this . CPU_width / this . graphStep ) * this . graphStep
334+ ) ;
335+ this . CPU_width = CPU_width ;
336+ }
337+
338+ adjust_Mem_width ( ) {
339+ if ( this . graphStep === 1 ) return ;
340+ let Mem_width = Math . max (
341+ Math . min ( this . graphStep , 16 ) ,
342+ Math . round ( this . Mem_width / this . graphStep ) * this . graphStep
343+ ) ;
344+ this . Mem_width = Mem_width ;
345+ }
346+
347+ adjust_Net_width ( ) {
348+ if ( this . graphStep === 1 ) return ;
349+ let Net_width = Math . max (
350+ Math . min ( this . graphStep , 16 ) ,
351+ Math . round ( this . Net_width / this . graphStep ) * this . graphStep
352+ ) ;
353+ this . Net_width = Net_width ;
354+ }
355+
356+ adjust_Disk_width ( ) {
357+ if ( this . graphStep === 1 ) return ;
358+ let Disk_width = Math . max (
359+ Math . min ( this . graphStep , 16 ) ,
360+ Math . round ( this . Disk_width / this . graphStep ) * this . graphStep
361+ ) ;
362+ this . Disk_width = Disk_width ;
363+ }
364+
365+ adjust_DiskUsage_width ( ) {
366+ if ( this . graphStep === 1 ) return ;
367+ let DiskUsage_width = Math . max (
368+ Math . min ( this . graphStep , 16 ) ,
369+ Math . round ( this . DiskUsage_width / this . graphStep ) * this . graphStep
370+ ) ;
371+ this . DiskUsage_width = DiskUsage_width ;
372+ }
326373
327374 set_panelHeight ( ) {
328375 this . iconSize = this . getPanelIconSize ( St . IconType . FULLCOLOR ) ;
@@ -842,7 +889,8 @@ class MCSM extends Applet.IconApplet {
842889 idleValue = 1 * idleValue ;
843890 let total = totalValue - this . oldCPU_Total_Values [ 0 ] ;
844891 let idle = idleValue - this . oldCPU_Idle_Values [ 0 ] ;
845- data . push ( ( total - idle ) / total ) ;
892+ if ( total != 0 )
893+ data . push ( ( total - idle ) / total ) ;
846894 this . oldCPU_Total_Values [ 0 ] = totalValue ;
847895 this . oldCPU_Idle_Values [ 0 ] = idleValue ;
848896 for ( let i = 1 , len = values . length ; i < len ; i ++ ) {
@@ -864,7 +912,8 @@ class MCSM extends Applet.IconApplet {
864912 i ++ ;
865913 continue ;
866914 }
867- data . push ( ( total - idle ) / total ) ;
915+ if ( total != 0 )
916+ data . push ( ( total - idle ) / total ) ;
868917 i ++ ;
869918 }
870919 }
@@ -879,51 +928,16 @@ class MCSM extends Applet.IconApplet {
879928 }
880929 } ) ;
881930 }
882-
883- get_net_info ( ) {
884- if ( ! this . isRunning ) return ;
885- if ( ! this . Net_enabled ) return ;
886- const net_dir_path = "/sys/class/net" ;
887- let old , duration ;
888- if ( DEBUG ) old = Date . now ( ) ;
889- var ret = "" ;
890- if ( GLib . file_test ( NETWORK_DEVICES_STATUS_PATH , GLib . FileTest . EXISTS ) ) {
891- let [ success , line ] = GLib . file_get_contents ( NETWORK_DEVICES_STATUS_PATH ) ;
892- let names_status = to_string ( line ) . trim ( ) . split ( " " ) ;
893- for ( let name_status of names_status ) {
894- let [ name , status ] = name_status . split ( ":" ) ;
895- if ( status == "up" ) {
896- let rx_bytes_path = `${ net_dir_path } /${ name } /statistics/rx_bytes` ;
897- let tx_bytes_path = `${ net_dir_path } /${ name } /statistics/tx_bytes` ;
898- let [ rx_success , rx_bytes ] = GLib . file_get_contents ( rx_bytes_path ) ;
899- let [ tx_success , tx_bytes ] = GLib . file_get_contents ( tx_bytes_path ) ;
900- rx_bytes = to_string ( rx_bytes ) . trim ( ) ;
901- tx_bytes = to_string ( tx_bytes ) . trim ( ) ;
902- ret = ret + `${ name } :${ rx_bytes } :${ tx_bytes } ` ;
903- }
904- }
905- } else {
906- const net_dir = Gio . file_new_for_path ( net_dir_path ) ;
907- const children = net_dir . enumerate_children ( "standard::name,standard::type" , Gio . FileQueryInfoFlags . NONE , null ) ;
908- for ( let child of children ) {
909- let name = child . get_name ( ) ;
910- let operstate_file_path = `${ net_dir_path } /${ name } /operstate` ;
911- let [ net_success , net_status ] = GLib . file_get_contents ( operstate_file_path ) ;
912- net_status = to_string ( net_status ) . trim ( ) ;
913- if ( net_status == "up" ) {
914- let rx_bytes_path = `${ net_dir_path } /${ name } /statistics/rx_bytes` ;
915- let tx_bytes_path = `${ net_dir_path } /${ name } /statistics/tx_bytes` ;
916- let [ rx_success , rx_bytes ] = GLib . file_get_contents ( rx_bytes_path ) ;
917- let [ tx_success , tx_bytes ] = GLib . file_get_contents ( tx_bytes_path ) ;
918- rx_bytes = to_string ( rx_bytes ) . trim ( ) ;
919- tx_bytes = to_string ( tx_bytes ) . trim ( ) ;
920- ret = ret + `${ name } :${ rx_bytes } :${ tx_bytes } ` ;
921- }
922- }
923- children . close ( null ) ;
931+
932+ set_net_devices_data ( ) {
933+ let dataNet = JSON . parse ( JSON . stringify ( this . lastDataNet , null , 4 ) ) ;
934+ var datastring = "" ;
935+ for ( let name of Object . keys ( dataNet ) ) {
936+ let rx = dataNet [ name ] [ "rx" ] ;
937+ let tx = dataNet [ name ] [ "tx" ] ;
938+ datastring += name + ":" + rx + ":" + tx + " " ;
924939 }
925-
926- ret = ret . trim ( ) ;
940+ datastring = datastring . trim ( ) ;
927941 var allowedInterfaces = [ ] ;
928942 var names = { } ;
929943 for ( let dev of this . Net_devicesList ) {
@@ -934,7 +948,7 @@ class MCSM extends Applet.IconApplet {
934948 }
935949 var data = [ ] ;
936950 var disabledDevices = [ ] ;
937- let netInfo = ret . split ( " " ) ;
951+ let netInfo = datastring . split ( " " ) ;
938952 var sum_rx = 0 ;
939953 var sum_tx = 0 ;
940954 for ( let info of netInfo ) {
@@ -965,6 +979,60 @@ class MCSM extends Applet.IconApplet {
965979 disabledDevices = [ ] ;
966980 }
967981 this . networkProvider . setData ( data , disabledDevices ) ;
982+ }
983+
984+ get_net_info ( ) {
985+ if ( ! this . isRunning ) return ;
986+ if ( ! this . Net_enabled ) return ;
987+ const net_dir_path = "/sys/class/net" ;
988+ let old , duration ;
989+ if ( DEBUG ) old = Date . now ( ) ;
990+ if ( GLib . file_test ( NETWORK_DEVICES_STATUS_PATH , GLib . FileTest . EXISTS ) ) {
991+ readFileAsync ( NETWORK_DEVICES_STATUS_PATH ) . then ( ( result ) => {
992+ let names_status = result . trim ( ) . split ( " " ) ;
993+ for ( let name_status of names_status ) {
994+ let [ name , status ] = name_status . split ( ":" ) ;
995+ if ( status == "up" ) {
996+ var rx_bytes = "" , tx_bytes = "" ;
997+ let rx_bytes_path = `${ net_dir_path } /${ name } /statistics/rx_bytes` ;
998+ let tx_bytes_path = `${ net_dir_path } /${ name } /statistics/tx_bytes` ;
999+ readFileAsync ( rx_bytes_path ) . then ( ( outputR ) => {
1000+ rx_bytes = outputR . trim ( ) ;
1001+ readFileAsync ( tx_bytes_path ) . then ( ( outputT ) => {
1002+ tx_bytes = outputT . trim ( ) ;
1003+ this . lastDataNet [ "" + name ] = { "rx" : parseInt ( rx_bytes ) , "tx" : parseInt ( tx_bytes ) } ;
1004+ } ) ;
1005+ } ) ;
1006+ }
1007+ }
1008+ } ) ;
1009+ } else {
1010+ const net_dir = Gio . file_new_for_path ( net_dir_path ) ;
1011+ const children = net_dir . enumerate_children ( "standard::name,standard::type" , Gio . FileQueryInfoFlags . NONE , null ) ;
1012+ for ( let child of children ) {
1013+ let name = child . get_name ( ) ;
1014+ let operstate_file_path = `${ net_dir_path } /${ name } /operstate` ;
1015+ readFileAsync ( operstate_file_path ) . then ( ( output ) => {
1016+ let net_status = output . trim ( ) ;
1017+ if ( net_status == "up" ) {
1018+ let rx_bytes_path = `${ net_dir_path } /${ name } /statistics/rx_bytes` ;
1019+ let tx_bytes_path = `${ net_dir_path } /${ name } /statistics/tx_bytes` ;
1020+
1021+ readFileAsync ( rx_bytes_path ) . then ( ( outputR ) => {
1022+ let rx_bytes = outputR . trim ( ) ;
1023+ readFileAsync ( tx_bytes_path ) . then ( ( outputT ) => {
1024+ let tx_bytes = outputT . trim ( ) ;
1025+ this . lastDataNet [ "" + name ] = { "rx" : parseInt ( rx_bytes ) , "tx" : parseInt ( tx_bytes ) } ;
1026+ } ) ;
1027+ } ) ;
1028+ }
1029+ } ) ;
1030+
1031+ }
1032+ children . close ( null ) ;
1033+ }
1034+ this . set_net_devices_data ( ) ;
1035+
9681036 if ( DEBUG ) {
9691037 duration = Date . now ( ) - old ;
9701038 global . log ( UUID + " - get_net_info Duration: " + duration + " ms." ) ;
0 commit comments