@@ -6,22 +6,24 @@ function entry({
6
6
RunningConfig,
7
7
envClient
8
8
} ) {
9
- let _devices = [
9
+ let flutterDevices = [
10
10
{
11
11
name :'No devices found.'
12
12
}
13
13
]
14
- let _app ;
14
+ let flutterApp ;
15
+ let selectedDevice ;
15
16
const button = new StatusBarItem ( {
16
17
label :'Detecting devices' ,
17
18
action :( e ) => {
18
19
new ContextMenu ( {
19
20
list :[
20
21
...
21
- _devices . map ( function ( dev ) {
22
+ flutterDevices . map ( device => {
22
23
return {
23
- label :dev . name ,
24
+ label : device . name ,
24
25
action :( ) => {
26
+ selectedDevice = device
25
27
}
26
28
}
27
29
} ) ,
@@ -32,32 +34,11 @@ function entry({
32
34
new ContextMenu ( {
33
35
list :[
34
36
...
35
- RunningConfig . data . workspaceConfig . folders . map ( function ( folder ) {
37
+ RunningConfig . data . workspaceConfig . folders . map ( folder => {
36
38
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 )
61
42
}
62
43
}
63
44
} )
@@ -71,7 +52,13 @@ function entry({
71
52
{
72
53
label :'Hot reload' ,
73
54
action ( ) {
74
- _app . reload ( )
55
+ flutterApp && flutterApp . reload ( )
56
+ }
57
+ } ,
58
+ {
59
+ label :'Close' ,
60
+ action ( ) {
61
+ flutterApp && flutterApp . close ( )
75
62
}
76
63
}
77
64
] ,
@@ -87,15 +74,52 @@ function entry({
87
74
}
88
75
} )
89
76
Flutter . getDevices ( ) . then ( res => {
90
- if ( res . devices . length == 0 ) {
77
+ if ( res . devices . length == 0 ) {
91
78
button . setLabel ( 'No devices found' )
92
79
} 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
95
83
}
96
84
} )
97
85
}
98
86
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
+
99
123
module . exports = {
100
124
entry
101
125
}
0 commit comments