@@ -6,22 +6,24 @@ function entry({
66 RunningConfig,
77 envClient
88} ) {
9- let _devices = [
9+ let flutterDevices = [
1010 {
1111 name :'No devices found.'
1212 }
1313 ]
14- let _app ;
14+ let flutterApp ;
15+ let selectedDevice ;
1516 const button = new StatusBarItem ( {
1617 label :'Detecting devices' ,
1718 action :( e ) => {
1819 new ContextMenu ( {
1920 list :[
2021 ...
21- _devices . map ( function ( dev ) {
22+ flutterDevices . map ( device => {
2223 return {
23- label :dev . name ,
24+ label : device . name ,
2425 action :( ) => {
26+ selectedDevice = device
2527 }
2628 }
2729 } ) ,
@@ -32,32 +34,11 @@ function entry({
3234 new ContextMenu ( {
3335 list :[
3436 ...
35- RunningConfig . data . workspaceConfig . folders . map ( function ( folder ) {
37+ RunningConfig . data . workspaceConfig . folders . map ( folder => {
3638 return {
37- label :folder . path ,
38- action :( ) => {
39- _app = new Flutter . app ( {
40- path :RunningConfig . data . workspaceConfig . folders [ 0 ] . path . replace ( / \\ / g, '\\\\' ) ,
41- deviceId :_devices [ 0 ] . id
42- } )
43- _app . run ( {
44- onData :function ( data ) {
45- console . log ( data )
46- } ,
47- onExit :function ( data ) {
48- console . log ( data )
49- } ,
50- onClose :function ( data ) {
51- console . log ( data )
52- }
53- } )
54- RunningConfig . on ( 'tabSaved' , function ( {
55- parentFolder
56- } ) {
57- if ( parentFolder == folder . path ) { //Check if the modified tab is from the flutter app
58- _app . reload ( )
59- }
60- } )
39+ label : folder . path ,
40+ action ( ) {
41+ runApp ( flutterApp , folder , selectedDevice , envClient , RunningConfig )
6142 }
6243 }
6344 } )
@@ -71,7 +52,13 @@ function entry({
7152 {
7253 label :'Hot reload' ,
7354 action ( ) {
74- _app . reload ( )
55+ flutterApp && flutterApp . reload ( )
56+ }
57+ } ,
58+ {
59+ label :'Close' ,
60+ action ( ) {
61+ flutterApp && flutterApp . close ( )
7562 }
7663 }
7764 ] ,
@@ -87,15 +74,52 @@ function entry({
8774 }
8875 } )
8976 Flutter . getDevices ( ) . then ( res => {
90- if ( res . devices . length == 0 ) {
77+ if ( res . devices . length == 0 ) {
9178 button . setLabel ( 'No devices found' )
9279 } else {
93- button . setLabel ( res . devices [ 0 ] . name )
94- _devices = res . devices
80+ selectedDevice = res . devices [ 0 ]
81+ button . setLabel ( selectedDevice . name )
82+ flutterDevices = res . devices
9583 }
9684 } )
9785}
9886
87+ function runApp ( flutterApp , folder , selectedDevice , envClient , RunningConfig ) {
88+ if ( ! selectedDevice ) return
89+ flutterApp = new Flutter . app ( {
90+ path : folder . path ,
91+ deviceId : selectedDevice . id
92+ } )
93+ const flutterEnv = new envClient ( {
94+ name : 'Flutter'
95+ } )
96+ flutterEnv . on ( 'start' , ( ) => {
97+ flutterApp . run ( {
98+ onData :function ( data ) {
99+ console . log ( data )
100+ } ,
101+ onExit :function ( data ) {
102+ console . log ( data )
103+ } ,
104+ onClose :function ( data ) {
105+ console . log ( data )
106+ }
107+ } )
108+ RunningConfig . on ( 'tabSaved' , ( { parentFolder } ) => {
109+ if ( parentFolder == folder . path ) {
110+ flutterApp . reload ( ) ;
111+ }
112+ } )
113+ } )
114+ flutterEnv . on ( 'stop' , ( ) => {
115+ flutterApp && flutterApp . close ( )
116+ } )
117+ flutterEnv . on ( 'reload' , ( ) => {
118+ flutterApp && flutterApp . reload ( )
119+ } )
120+ }
121+
122+
99123module . exports = {
100124 entry
101125}
0 commit comments