@@ -20,7 +20,6 @@ import 'src/context_runner.dart';
20
20
import 'src/doctor.dart' ;
21
21
import 'src/globals.dart' as globals;
22
22
import 'src/reporting/crash_reporting.dart' ;
23
- import 'src/reporting/first_run.dart' ;
24
23
import 'src/reporting/reporting.dart' ;
25
24
import 'src/runner/flutter_command.dart' ;
26
25
import 'src/runner/flutter_command_runner.dart' ;
@@ -115,7 +114,7 @@ Future<int> run(
115
114
// Triggering [runZoned]'s error callback does not necessarily mean that
116
115
// we stopped executing the body. See https://github.com/dart-lang/sdk/issues/42150.
117
116
if (firstError == null ) {
118
- return await _exit (0 , shutdownHooks: shutdownHooks);
117
+ return await exitWithHooks (0 , shutdownHooks: shutdownHooks);
119
118
}
120
119
121
120
// We already hit some error, so don't return success. The error path
@@ -151,22 +150,22 @@ Future<int> _handleToolError(
151
150
globals.printError ('${error .message }\n ' );
152
151
globals.printError ("Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and options." );
153
152
// Argument error exit code.
154
- return _exit (64 , shutdownHooks: shutdownHooks);
153
+ return exitWithHooks (64 , shutdownHooks: shutdownHooks);
155
154
} else if (error is ToolExit ) {
156
155
if (error.message != null ) {
157
156
globals.printError (error.message! );
158
157
}
159
158
if (verbose) {
160
159
globals.printError ('\n $stackTrace \n ' );
161
160
}
162
- return _exit (error.exitCode ?? 1 , shutdownHooks: shutdownHooks);
161
+ return exitWithHooks (error.exitCode ?? 1 , shutdownHooks: shutdownHooks);
163
162
} else if (error is ProcessExit ) {
164
163
// We've caught an exit code.
165
164
if (error.immediate) {
166
165
exit (error.exitCode);
167
166
return error.exitCode;
168
167
} else {
169
- return _exit (error.exitCode, shutdownHooks: shutdownHooks);
168
+ return exitWithHooks (error.exitCode, shutdownHooks: shutdownHooks);
170
169
}
171
170
} else {
172
171
// We've crashed; emit a log report.
@@ -176,7 +175,7 @@ Future<int> _handleToolError(
176
175
// Print the stack trace on the bots - don't write a crash report.
177
176
globals.stdio.stderrWrite ('$error \n ' );
178
177
globals.stdio.stderrWrite ('$stackTrace \n ' );
179
- return _exit (1 , shutdownHooks: shutdownHooks);
178
+ return exitWithHooks (1 , shutdownHooks: shutdownHooks);
180
179
}
181
180
182
181
// Report to both [Usage] and [CrashReportSender].
@@ -217,7 +216,7 @@ Future<int> _handleToolError(
217
216
final File file = await _createLocalCrashReport (details);
218
217
await globals.crashReporter! .informUser (details, file);
219
218
220
- return _exit (1 , shutdownHooks: shutdownHooks);
219
+ return exitWithHooks (1 , shutdownHooks: shutdownHooks);
221
220
// This catch catches all exceptions to ensure the message below is printed.
222
221
} catch (error, st) { // ignore: avoid_catches_without_on_clauses
223
222
globals.stdio.stderrWrite (
@@ -283,76 +282,3 @@ Future<File> _createLocalCrashReport(CrashDetails details) async {
283
282
284
283
return crashFile;
285
284
}
286
-
287
- Future <int > _exit (int code, {required ShutdownHooks shutdownHooks}) async {
288
- // Need to get the boolean returned from `messenger.shouldDisplayLicenseTerms()`
289
- // before invoking the print welcome method because the print welcome method
290
- // will set `messenger.shouldDisplayLicenseTerms()` to false
291
- final FirstRunMessenger messenger =
292
- FirstRunMessenger (persistentToolState: globals.persistentToolState! );
293
- final bool legacyAnalyticsMessageShown =
294
- messenger.shouldDisplayLicenseTerms ();
295
-
296
- // Prints the welcome message if needed for legacy analytics.
297
- globals.flutterUsage.printWelcome ();
298
-
299
- // Ensure that the consent message has been displayed for unified analytics
300
- if (globals.analytics.shouldShowMessage) {
301
- globals.logger.printStatus (globals.analytics.getConsentMessage);
302
- if (! globals.flutterUsage.enabled) {
303
- globals.printStatus (
304
- 'Please note that analytics reporting was already disabled, '
305
- 'and will continue to be disabled.\n ' );
306
- }
307
-
308
- // Because the legacy analytics may have also sent a message,
309
- // the conditional below will print additional messaging informing
310
- // users that the two consent messages they are receiving is not a
311
- // bug
312
- if (legacyAnalyticsMessageShown) {
313
- globals.logger
314
- .printStatus ('You have received two consent messages because '
315
- 'the flutter tool is migrating to a new analytics system. '
316
- 'Disabling analytics collection will disable both the legacy '
317
- 'and new analytics collection systems. '
318
- 'You can disable analytics reporting by running `flutter --disable-analytics`\n ' );
319
- }
320
-
321
- // Invoking this will onboard the flutter tool onto
322
- // the package on the developer's machine and will
323
- // allow for events to be sent to Google Analytics
324
- // on subsequent runs of the flutter tool (ie. no events
325
- // will be sent on the first run to allow developers to
326
- // opt out of collection)
327
- globals.analytics.clientShowedMessage ();
328
- }
329
-
330
- // Send any last analytics calls that are in progress without overly delaying
331
- // the tool's exit (we wait a maximum of 250ms).
332
- if (globals.flutterUsage.enabled) {
333
- final Stopwatch stopwatch = Stopwatch ()..start ();
334
- await globals.flutterUsage.ensureAnalyticsSent ();
335
- globals.printTrace ('ensureAnalyticsSent: ${stopwatch .elapsedMilliseconds }ms' );
336
- }
337
-
338
- // Run shutdown hooks before flushing logs
339
- await shutdownHooks.runShutdownHooks (globals.logger);
340
-
341
- final Completer <void > completer = Completer <void >();
342
-
343
- // Give the task / timer queue one cycle through before we hard exit.
344
- Timer .run (() {
345
- try {
346
- globals.printTrace ('exiting with code $code ' );
347
- exit (code);
348
- completer.complete ();
349
- // This catches all exceptions because the error is propagated on the
350
- // completer.
351
- } catch (error, stackTrace) { // ignore: avoid_catches_without_on_clauses
352
- completer.completeError (error, stackTrace);
353
- }
354
- });
355
-
356
- await completer.future;
357
- return code;
358
- }
0 commit comments