1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:io';
Process daemon;
// To use, start from the console and enter:
// version: print version
// shutdown: terminate the server
// start: start an app
// stopAll: stop any running app
// devices: list devices
Future<Null> main() async {
daemon = await Process.start('dart', ['bin/flutter_tools.dart', 'daemon']);
print('daemon process started, pid: ${daemon.pid}');
daemon.stdout
.transform(UTF8.decoder)
.transform(const LineSplitter())
.listen((String line) => print('<== $line'));
daemon.stderr.listen((dynamic data) => stderr.add(data));
stdout.write('> ');
stdin.transform(UTF8.decoder).transform(const LineSplitter()).listen((String line) {
if (line == 'version' || line == 'v') {
_send({'method': 'daemon.version'});
} else if (line == 'shutdown' || line == 'q') {
_send({'method': 'daemon.shutdown'});
} else if (line == 'start') {
_send({'method': 'app.start'});
} else if (line == 'stopAll') {
_send({'method': 'app.stopAll'});
} else if (line == 'devices') {
_send({'method': 'device.getDevices'});
} else {
print('command not understood: $line');
}
stdout.write('> ');
});
daemon.exitCode.then((int code) {
print('daemon exiting ($code)');
exit(code);
});
}
int id = 0;
void _send(Map<String, dynamic> map) {
map['id'] = id++;
String str = '[${JSON.encode(map)}]';
daemon.stdin.writeln(str);
print('==> $str');
}