@@ -52,31 +52,14 @@ class DaemonCommand extends FlutterCommand {
52
52
Cache .releaseLockEarly ();
53
53
54
54
return appContext.runInZone (() {
55
- Stream <Map <String , dynamic >> commandStream = stdin
56
- .transform (UTF8 .decoder)
57
- .transform (const LineSplitter ())
58
- .where ((String line) => line.startsWith ('[{' ) && line.endsWith ('}]' ))
59
- .map ((String line) {
60
- line = line.substring (1 , line.length - 1 );
61
- return JSON .decode (line);
62
- });
63
-
64
- Daemon daemon = new Daemon (commandStream, (Map <String , dynamic > command) {
65
- stdout.writeln ('[${JSON .encode (command , toEncodable : _jsonEncodeObject )}]' );
66
- }, daemonCommand: this , notifyingLogger: notifyingLogger);
55
+ Daemon daemon = new Daemon (
56
+ stdinCommandStream, stdoutCommandResponse,
57
+ daemonCommand: this , notifyingLogger: notifyingLogger);
67
58
68
59
return daemon.onExit;
69
60
}, onError: _handleError);
70
61
}
71
62
72
- dynamic _jsonEncodeObject (dynamic object) {
73
- if (object is Device )
74
- return _deviceToMap (object);
75
- if (object is OperationResult )
76
- return _operationResultToMap (object);
77
- return object;
78
- }
79
-
80
63
dynamic _handleError (dynamic error, StackTrace stackTrace) {
81
64
printError ('Error from flutter daemon: $error ' , stackTrace);
82
65
return null ;
@@ -306,6 +289,23 @@ class AppDomain extends Domain {
306
289
throw "'$projectDirectory ' does not exist" ;
307
290
308
291
BuildMode buildMode = getBuildModeForName (mode) ?? BuildMode .debug;
292
+
293
+ AppInstance app = startApp (
294
+ device, projectDirectory, target, route,
295
+ buildMode, startPaused, enableHotReload);
296
+
297
+ return < String , dynamic > {
298
+ 'appId' : app.id,
299
+ 'deviceId' : device.id,
300
+ 'directory' : projectDirectory,
301
+ 'supportsRestart' : isRestartSupported (enableHotReload, device)
302
+ };
303
+ }
304
+
305
+ AppInstance startApp (
306
+ Device device, String projectDirectory, String target, String route,
307
+ BuildMode buildMode, bool startPaused, bool enableHotReload) {
308
+
309
309
DebuggingOptions options;
310
310
311
311
switch (buildMode) {
@@ -342,14 +342,12 @@ class AppDomain extends Domain {
342
342
);
343
343
}
344
344
345
- bool supportsRestart = enableHotReload ? device.supportsHotMode : device.supportsRestart;
346
-
347
345
AppInstance app = new AppInstance (_getNewAppId (), runner);
348
346
_apps.add (app);
349
347
_sendAppEvent (app, 'start' , < String , dynamic > {
350
- 'deviceId' : deviceId ,
348
+ 'deviceId' : device.id ,
351
349
'directory' : projectDirectory,
352
- 'supportsRestart' : supportsRestart
350
+ 'supportsRestart' : isRestartSupported (enableHotReload, device)
353
351
});
354
352
355
353
Completer <DebugConnectionInfo > connectionInfoCompleter;
@@ -375,14 +373,12 @@ class AppDomain extends Domain {
375
373
});
376
374
});
377
375
378
- return < String , dynamic > {
379
- 'appId' : app.id,
380
- 'deviceId' : deviceId,
381
- 'directory' : projectDirectory,
382
- 'supportsRestart' : supportsRestart
383
- };
376
+ return app;
384
377
}
385
378
379
+ bool isRestartSupported (bool enableHotReload, Device device) =>
380
+ enableHotReload ? device.supportsHotMode : device.supportsRestart;
381
+
386
382
Future <OperationResult > restart (Map <String , dynamic > args) async {
387
383
String appId = _getStringArg (args, 'appId' , required : true );
388
384
bool fullRestart = _getBoolArg (args, 'fullRestart' ) ?? false ;
@@ -561,6 +557,27 @@ class DeviceDomain extends Domain {
561
557
}
562
558
}
563
559
560
+ Stream <Map <String , dynamic >> get stdinCommandStream => stdin
561
+ .transform (UTF8 .decoder)
562
+ .transform (const LineSplitter ())
563
+ .where ((String line) => line.startsWith ('[{' ) && line.endsWith ('}]' ))
564
+ .map ((String line) {
565
+ line = line.substring (1 , line.length - 1 );
566
+ return JSON .decode (line);
567
+ });
568
+
569
+ void stdoutCommandResponse (Map <String , dynamic > command) {
570
+ stdout.writeln ('[${JSON .encode (command , toEncodable : _jsonEncodeObject )}]' );
571
+ }
572
+
573
+ dynamic _jsonEncodeObject (dynamic object) {
574
+ if (object is Device )
575
+ return _deviceToMap (object);
576
+ if (object is OperationResult )
577
+ return _operationResultToMap (object);
578
+ return object;
579
+ }
580
+
564
581
Map <String , dynamic > _deviceToMap (Device device) {
565
582
return < String , dynamic > {
566
583
'id' : device.id,
0 commit comments