Skip to content
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Commit cab8678

Browse files
committed
✨ Integrated the environment client
1 parent ef4434f commit cab8678

File tree

4 files changed

+63
-39
lines changed

4 files changed

+63
-39
lines changed

main.js

+57-33
Original file line numberDiff line numberDiff line change
@@ -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+
99123
module.exports = {
100124
entry
101125
}

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "flutter-plugin-graviton",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"main": "main.js",
55
"mainSrc": "main.js",
66
"mainDev": "dist/main.js",
@@ -9,7 +9,7 @@
99
"build": "gvsdk --entry package.json --target plugin --mode release"
1010
},
1111
"dependencies": {
12-
"flutter-node": "^0.1.1"
12+
"flutter-node": "^0.1.2"
1313
},
1414
"license": "MIT",
1515
"devDependencies": {

readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Flutter
22

3-
This is a flutter plugin for Graviton Editor v2, this is still on an alpha.
3+
This is a flutter plugin for Graviton Editor v2, this might be a little unstable. Create an issue if it's needed.
44

55
Features:
66
* Run a project to your devices ( not emulators yet )

0 commit comments

Comments
 (0)