Unverified Commit 04e4b117 authored by Devon Carew's avatar Devon Carew Committed by GitHub

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
parent 8eadbb31
...@@ -545,6 +545,12 @@ class AppDomain extends Domain { ...@@ -545,6 +545,12 @@ class AppDomain extends Domain {
final AppInstance app = AppInstance(_getNewAppId(), final AppInstance app = AppInstance(_getNewAppId(),
runner: runner, logToStdout: daemon.logToStdout, logger: logger); runner: runner, logToStdout: daemon.logToStdout, logger: logger);
_apps.add(app); _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>{ _sendAppEvent(app, 'start', <String, dynamic>{
'deviceId': device.id, 'deviceId': device.id,
'directory': projectDirectory, 'directory': projectDirectory,
...@@ -1105,8 +1111,6 @@ class AppInstance { ...@@ -1105,8 +1111,6 @@ class AppInstance {
} }
Future<T> _runInZone<T>(AppDomain domain, FutureOr<T> method()) async { Future<T> _runInZone<T>(AppDomain domain, FutureOr<T> method()) async {
_logger.domain = domain;
_logger.app = this;
return method(); return method();
} }
} }
...@@ -1253,22 +1257,22 @@ class AppRunLogger extends Logger { ...@@ -1253,22 +1257,22 @@ class AppRunLogger extends Logger {
}) { }) {
final int id = _nextProgressId++; final int id = _nextProgressId++;
_sendProgressEvent(<String, dynamic>{ _sendProgressEvent(
'id': id.toString(), eventId: id.toString(),
'progressId': progressId, eventType: progressId,
'message': message, message: message,
}); );
_status = SilentStatus( _status = SilentStatus(
timeout: timeout, timeout: timeout,
timeoutConfiguration: timeoutConfiguration, timeoutConfiguration: timeoutConfiguration,
onFinish: () { onFinish: () {
_status = null; _status = null;
_sendProgressEvent(<String, dynamic>{ _sendProgressEvent(
'id': id.toString(), eventId: id.toString(),
'progressId': progressId, eventType: progressId,
'finished': true, finished: true,
}); );
}, stopwatch: Stopwatch())..start(); }, stopwatch: Stopwatch())..start();
return _status; return _status;
} }
...@@ -1285,10 +1289,26 @@ class AppRunLogger extends Logger { ...@@ -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) { 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 { } 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); domain._sendAppEvent(app, 'progress', event);
} }
} }
......
...@@ -15,6 +15,7 @@ import 'package:mockito/mockito.dart'; ...@@ -15,6 +15,7 @@ import 'package:mockito/mockito.dart';
import 'package:fake_async/fake_async.dart'; import 'package:fake_async/fake_async.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/mocks.dart' as mocks; import '../../src/mocks.dart' as mocks;
final Platform _kNoAnsiPlatform = FakePlatform(stdoutSupportsAnsi: false); final Platform _kNoAnsiPlatform = FakePlatform(stdoutSupportsAnsi: false);
...@@ -628,6 +629,15 @@ void main() { ...@@ -628,6 +629,15 @@ void main() {
expect(lines[3], equals('0123456789' * 3)); 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 { testWithoutContext('Error logs are wrapped and can be indented.', () async {
final Logger logger = StdoutLogger( final Logger logger = StdoutLogger(
terminal: AnsiTerminal( terminal: AnsiTerminal(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment