fix an issue where raw json output is written to IDE clients (#65508)
fix an issues where raw json output was written to IDE clients
This commit is contained in:
@@ -545,6 +545,12 @@ class AppDomain extends Domain {
|
||||
final AppInstance app = AppInstance(_getNewAppId(),
|
||||
runner: runner, logToStdout: daemon.logToStdout, logger: logger);
|
||||
_apps.add(app);
|
||||
|
||||
// Set the domain and app for the given AppRunLogger. This allows the logger
|
||||
// to log messages containing the app ID to the host.
|
||||
logger.domain = this;
|
||||
logger.app = app;
|
||||
|
||||
_sendAppEvent(app, 'start', <String, dynamic>{
|
||||
'deviceId': device.id,
|
||||
'directory': projectDirectory,
|
||||
@@ -1105,8 +1111,6 @@ class AppInstance {
|
||||
}
|
||||
|
||||
Future<T> _runInZone<T>(AppDomain domain, FutureOr<T> method()) async {
|
||||
_logger.domain = domain;
|
||||
_logger.app = this;
|
||||
return method();
|
||||
}
|
||||
}
|
||||
@@ -1253,22 +1257,22 @@ class AppRunLogger extends Logger {
|
||||
}) {
|
||||
final int id = _nextProgressId++;
|
||||
|
||||
_sendProgressEvent(<String, dynamic>{
|
||||
'id': id.toString(),
|
||||
'progressId': progressId,
|
||||
'message': message,
|
||||
});
|
||||
_sendProgressEvent(
|
||||
eventId: id.toString(),
|
||||
eventType: progressId,
|
||||
message: message,
|
||||
);
|
||||
|
||||
_status = SilentStatus(
|
||||
timeout: timeout,
|
||||
timeoutConfiguration: timeoutConfiguration,
|
||||
onFinish: () {
|
||||
_status = null;
|
||||
_sendProgressEvent(<String, dynamic>{
|
||||
'id': id.toString(),
|
||||
'progressId': progressId,
|
||||
'finished': true,
|
||||
});
|
||||
_sendProgressEvent(
|
||||
eventId: id.toString(),
|
||||
eventType: progressId,
|
||||
finished: true,
|
||||
);
|
||||
}, stopwatch: Stopwatch())..start();
|
||||
return _status;
|
||||
}
|
||||
@@ -1285,10 +1289,26 @@ class AppRunLogger extends Logger {
|
||||
}
|
||||
}
|
||||
|
||||
void _sendProgressEvent(Map<String, dynamic> event) {
|
||||
void _sendProgressEvent({
|
||||
@required String eventId,
|
||||
@required String eventType,
|
||||
bool finished = false,
|
||||
String message,
|
||||
}) {
|
||||
if (domain == null) {
|
||||
printStatus('event sent after app closed: $event');
|
||||
// If we're sending progress events before an app has started, send the
|
||||
// progress messages as plain status messages.
|
||||
if (message != null) {
|
||||
printStatus(message);
|
||||
}
|
||||
} else {
|
||||
final Map<String, dynamic> event = <String, dynamic>{
|
||||
'id': eventId,
|
||||
'progressId': eventType,
|
||||
if (message != null) 'message': message,
|
||||
if (finished != null) 'finished': finished,
|
||||
};
|
||||
|
||||
domain._sendAppEvent(app, 'progress', event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import 'package:mockito/mockito.dart';
|
||||
import 'package:fake_async/fake_async.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/mocks.dart' as mocks;
|
||||
|
||||
final Platform _kNoAnsiPlatform = FakePlatform(stdoutSupportsAnsi: false);
|
||||
@@ -628,6 +629,15 @@ void main() {
|
||||
expect(lines[3], equals('0123456789' * 3));
|
||||
});
|
||||
|
||||
testUsingContext('AppRunLogger writes plain text statuses when no app is active', () async {
|
||||
final BufferLogger buffer = BufferLogger.test();
|
||||
final AppRunLogger logger = AppRunLogger(parent: buffer);
|
||||
|
||||
logger.startProgress('Test status...', timeout: null).stop();
|
||||
|
||||
expect(buffer.statusText.trim(), equals('Test status...'));
|
||||
});
|
||||
|
||||
testWithoutContext('Error logs are wrapped and can be indented.', () async {
|
||||
final Logger logger = StdoutLogger(
|
||||
terminal: AnsiTerminal(
|
||||
|
||||
Reference in New Issue
Block a user