@@ -21,6 +21,7 @@ const {
2121} = imports . ui . extension ; //Extension
2222
2323const { to_string } = require ( "./lib/tostring" ) ;
24+ const { readFileAsync } = require ( "./lib/readFileAsync" ) ;
2425const Graphs = require ( './lib/Graphs' ) ;
2526const {
2627 timeout_add,
@@ -484,26 +485,16 @@ class MCSM extends Applet.IconApplet {
484485 posConfigure = i ;
485486 }
486487 }
487- //~ global.log("posConfigure: " + posConfigure);
488488 if ( posConfigure != - 1 ) {
489489 menuChildren [ posConfigure ] . destroy ( ) ;
490- //~ let context_menu_item_configure = new PopupMenu.PopupSubMenuMenuItem(_("Configure..."));
491490 this . context_menu_item_configure = new PopupMenu . PopupSubMenuMenuItem ( _ ( "Configure..." ) ) ;
492- //~ context_menu_item_configure.menu.addAction(_("General"), () => { this.configureApplet(0) });
493- //~ context_menu_item_configure.menu.addAction(_("CPU"), () => { this.configureApplet(1) });
494- //~ context_menu_item_configure.menu.addAction(_("Memory"), () => { this.configureApplet(2) });
495- //~ context_menu_item_configure.menu.addAction(_("Network"), () => { this.configureApplet(3) });
496- //~ context_menu_item_configure.menu.addAction(_("Disk IO"), () => { this.configureApplet(4) });
497- //~ context_menu_item_configure.menu.addAction(_("Disk Usage"), () => { this.configureApplet(5) });
498- //~ context_menu_item_configure.menu.addAction(_("Colors"), () => { this.configureApplet(6) });
499491 this . context_menu_item_configure . menu . addAction ( _ ( "General" ) , ( ) => { this . configureApplet ( 0 ) } ) ;
500492 this . context_menu_item_configure . menu . addAction ( _ ( "CPU" ) , ( ) => { this . configureApplet ( 1 ) } ) ;
501493 this . context_menu_item_configure . menu . addAction ( _ ( "Memory" ) , ( ) => { this . configureApplet ( 2 ) } ) ;
502494 this . context_menu_item_configure . menu . addAction ( _ ( "Network" ) , ( ) => { this . configureApplet ( 3 ) } ) ;
503495 this . context_menu_item_configure . menu . addAction ( _ ( "Disk IO" ) , ( ) => { this . configureApplet ( 4 ) } ) ;
504496 this . context_menu_item_configure . menu . addAction ( _ ( "Disk Usage" ) , ( ) => { this . configureApplet ( 5 ) } ) ;
505497 this . context_menu_item_configure . menu . addAction ( _ ( "Colors" ) , ( ) => { this . configureApplet ( 6 ) } ) ;
506- //~ this._applet_context_menu.addMenuItem(context_menu_item_configure, posConfigure);
507498 this . _applet_context_menu . addMenuItem ( this . context_menu_item_configure , posConfigure ) ;
508499 }
509500 }
@@ -585,19 +576,21 @@ class MCSM extends Applet.IconApplet {
585576 }
586577 var ret = "" ;
587578 if ( GLib . file_test ( NETWORK_DEVICES_STATUS_PATH , GLib . FileTest . EXISTS ) ) {
588- let [ succes , status ] = GLib . file_get_contents ( NETWORK_DEVICES_STATUS_PATH ) ;
589- status = to_string ( status ) . trim ( ) ;
590- ret += status ;
579+ readFileAsync ( NETWORK_DEVICES_STATUS_PATH ) . then ( ( status ) => {
580+ ret += status ;
581+ } ) ;
591582 } else {
592583 const net_dir_path = "/sys/class/net" ;
593584 const net_dir = Gio . file_new_for_path ( net_dir_path ) ;
594585 const children = net_dir . enumerate_children ( "standard::name,standard::type" , Gio . FileQueryInfoFlags . NONE , null ) ;
595586 for ( let child of children ) {
596587 let name = child . get_name ( ) ;
597588 let operstate_file_path = `${ net_dir_path } /${ name } /operstate` ;
598- let [ net_success , net_status ] = GLib . file_get_contents ( operstate_file_path ) ;
599- net_status = to_string ( net_status ) . trim ( ) ;
600- ret += `${ name } :${ net_status } ` ;
589+
590+ readFileAsync ( operstate_file_path ) . then ( ( net_status ) => {
591+ net_status = net_status . trim ( ) ;
592+ ret += `${ name } :${ net_status } ` ;
593+ } ) ;
601594 }
602595 }
603596 var returnedDevices = ret . trim ( ) . split ( " " ) ;
@@ -756,10 +749,8 @@ class MCSM extends Applet.IconApplet {
756749 if ( ! this . Mem_enabled ) return ;
757750 let old , duration ;
758751 if ( DEBUG ) old = Date . now ( ) ;
759- var contents = "" ;
760- let [ success , contents_array ] = GLib . file_get_contents ( "/proc/meminfo" ) ;
761- if ( success ) {
762- contents = to_string ( contents_array ) ;
752+
753+ readFileAsync ( "/proc/meminfo" ) . then ( ( contents ) => {
763754 var data = [ ] ;
764755 const lines = contents . split ( "\n" ) ;
765756 const p = 1024 ;
@@ -798,18 +789,16 @@ class MCSM extends Applet.IconApplet {
798789 duration = Date . now ( ) - old ;
799790 global . log ( UUID + " - get_mem_info Duration: " + duration + " ms." ) ;
800791 }
801- }
792+ } ) ;
802793 }
803794
804795 get_cpu_info ( ) {
805796 if ( ! this . isRunning ) return ;
806797 if ( ! this . CPU_enabled ) return ;
807798 let old , duration ;
808799 if ( DEBUG ) old = Date . now ( ) ;
809- var contents = "" ;
810- let [ success , contents_array ] = GLib . file_get_contents ( "/proc/stat" ) ;
811- if ( success ) {
812- contents = to_string ( contents_array ) ;
800+
801+ readFileAsync ( "/proc/stat" ) . then ( ( contents ) => {
813802 var data = [ ] ;
814803 const lines = contents . split ( "\n" ) ;
815804 var ret = "" ;
@@ -883,11 +872,12 @@ class MCSM extends Applet.IconApplet {
883872 this . oldCPUvalues = values ;
884873
885874 this . multiCpuProvider . setData ( data ) ;
886- }
887- if ( DEBUG ) {
888- duration = Date . now ( ) - old ;
889- global . log ( UUID + " - get_cpu_info Duration: " + duration + " ms." ) ;
890- }
875+
876+ if ( DEBUG ) {
877+ duration = Date . now ( ) - old ;
878+ global . log ( UUID + " - get_cpu_info Duration: " + duration + " ms." ) ;
879+ }
880+ } ) ;
891881 }
892882
893883 get_net_info ( ) {
@@ -999,44 +989,47 @@ class MCSM extends Applet.IconApplet {
999989 deviceGrans [ d [ "id" ] ] = d [ "discGran" ] ;
1000990 }
1001991 var data = [ ] ;
1002- let diskstats = ( to_string ( GLib . file_get_contents ( "/proc/diskstats" ) [ 1 ] ) ) . trim ( ) . split ( "\n" ) ;
1003- var sum_read = 0 ;
1004- var sum_write = 0 ;
1005- for ( let line of diskstats ) {
1006- if ( line . includes ( "loop" ) ) continue ;
1007- line = line . trim ( ) ;
1008- line = line . replace ( / \ + / g, " " ) ;
1009- let infos = line . split ( " " ) ;
1010- let _dev = infos [ 2 ] ;
1011- if ( usedDevices . indexOf ( _dev ) < 0 ) continue ;
1012- let discGran = 1 * deviceGrans [ _dev ] ;
1013- let [ _read , _write ] = [ 1 * infos [ 5 ] * discGran , 1 * infos [ 9 ] * discGran ] ;
992+ readFileAsync ( "/proc/diskstats" ) . then ( ( result ) => {
993+ let diskstats = result . trim ( ) . split ( "\n" ) ;
994+
995+ var sum_read = 0 ;
996+ var sum_write = 0 ;
997+ for ( let line of diskstats ) {
998+ if ( line . includes ( "loop" ) ) continue ;
999+ line = line . trim ( ) ;
1000+ line = line . replace ( / \ + / g, " " ) ;
1001+ let infos = line . split ( " " ) ;
1002+ let _dev = infos [ 2 ] ;
1003+ if ( usedDevices . indexOf ( _dev ) < 0 ) continue ;
1004+ let discGran = 1 * deviceGrans [ _dev ] ;
1005+ let [ _read , _write ] = [ 1 * infos [ 5 ] * discGran , 1 * infos [ 9 ] * discGran ] ;
1006+ if ( this . Disk_mergeAll ) {
1007+ sum_read = 1 * sum_read + _read ;
1008+ sum_write = 1 * sum_write + _write ;
1009+ } else {
1010+ data . push ( {
1011+ "id" : _dev ,
1012+ "name" : deviceNames [ _dev ] ,
1013+ "read" : _read ,
1014+ "write" : _write
1015+ } ) ;
1016+ }
1017+
1018+ }
10141019 if ( this . Disk_mergeAll ) {
1015- sum_read = 1 * sum_read + _read ;
1016- sum_write = 1 * sum_write + _write ;
1017- } else {
10181020 data . push ( {
1019- "id" : _dev ,
1020- "name" : deviceNames [ _dev ] ,
1021- "read" : _read ,
1022- "write" : _write
1021+ "id" : "Disks" ,
1022+ "name" : _ ( "Disks" ) ,
1023+ "read" : sum_read ,
1024+ "write" : sum_write
10231025 } ) ;
10241026 }
1025-
1026- }
1027- if ( this . Disk_mergeAll ) {
1028- data . push ( {
1029- "id" : "Disks" ,
1030- "name" : _ ( "Disks" ) ,
1031- "read" : sum_read ,
1032- "write" : sum_write
1033- } ) ;
1034- }
1035- this . diskProvider . setData ( data ) ;
1036- if ( DEBUG ) {
1037- duration = Date . now ( ) - old ;
1038- global . log ( UUID + " - get_disk_info Duration: " + duration + " ms." ) ;
1039- }
1027+ this . diskProvider . setData ( data ) ;
1028+ if ( DEBUG ) {
1029+ duration = Date . now ( ) - old ;
1030+ global . log ( UUID + " - get_disk_info Duration: " + duration + " ms." ) ;
1031+ }
1032+ } ) ;
10401033 }
10411034
10421035 get_disk_usage ( ) {
0 commit comments