Skip to content

Commit 4c8b0a3

Browse files
DanTupandrewkolos
andauthored
[flutter_tool] Change the startup message for the "flutter daemon" command (#160444)
There have been some reports of the Flutter daemon not starting up properly (for ex. flutter/flutter#143625), but it turns out that when starting successfully, it just prints "Starting device daemon..." and then nothing more. This is confusing and can lead users to think other issues are because the daemon hasn't started properly. There's not a great hook to print that this "finished" starting up (because it does async polling in the background), so I just updated the message of the text and moved it to after the creation of the daemon. Fixes flutter/flutter#143625 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [N/A] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Andrew Kolos <andrewrkolos@gmail.com>
1 parent c3fcb25 commit 4c8b0a3

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

packages/flutter_tools/lib/src/commands/daemon.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ class DaemonCommand extends FlutterCommand {
8686
).run();
8787
return FlutterCommandResult.success();
8888
}
89-
globals.printStatus('Starting device daemon...');
9089
final Daemon daemon = Daemon(
9190
DaemonConnection(
9291
daemonStreams: DaemonStreams.fromStdio(globals.stdio, logger: globals.logger),
9392
logger: globals.logger,
9493
),
9594
notifyingLogger: asLogger<NotifyingLogger>(globals.logger),
9695
);
96+
globals.printStatus('Device daemon started.');
9797
final int code = await daemon.onExit;
9898
if (code != 0) {
9999
throwToolExit('Daemon exited with non-zero exit code: $code', exitCode: code);

packages/flutter_tools/test/integration.shard/daemon_mode_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,42 @@ void main() {
2727
daemonProcess.kill();
2828
});
2929

30+
testWithoutContext('startup events', () async {
31+
final BasicProject project = BasicProject();
32+
await project.setUpIn(tempDir);
33+
34+
const ProcessManager processManager = LocalProcessManager();
35+
daemonProcess = await processManager.start(
36+
<String>[flutterBin, ...getLocalEngineArguments(), '--show-test-device', 'daemon'],
37+
workingDirectory: tempDir.path,
38+
);
39+
40+
final StreamController<String> stdout = StreamController<String>.broadcast();
41+
transformToLines(daemonProcess.stdout).listen((String line) => stdout.add(line));
42+
final Stream<Map<String, Object?>> stream =
43+
stdout.stream
44+
.map<Map<String, Object?>?>(parseFlutterResponse)
45+
.where((Map<String, Object?>? value) => value != null)
46+
.cast<Map<String, Object?>>();
47+
48+
final [
49+
Map<String, Object?> connectedEvent,
50+
Map<String, Object?> logMessage,
51+
] = await Future.wait(<Future<Map<String, Object?>>>[
52+
stream.firstWhere((Map<String, Object?> e) => e['event'] == 'daemon.connected'),
53+
stream.firstWhere((Map<String, Object?> e) => e['event'] == 'daemon.logMessage'),
54+
]);
55+
56+
// Check the connected message has a version.
57+
final Map<String, Object?> connectedParams = connectedEvent['params']! as Map<String, Object?>;
58+
expect(connectedParams['version'], isNotNull);
59+
60+
// Check we got the startup message.
61+
final Map<String, Object?> logParams = logMessage['params']! as Map<String, Object?>;
62+
expect(logParams['level'], 'status');
63+
expect(logParams['message'], 'Device daemon started.');
64+
});
65+
3066
testWithoutContext('device.getDevices', () async {
3167
final BasicProject project = BasicProject();
3268
await project.setUpIn(tempDir);

0 commit comments

Comments
 (0)