Skip to content
Merged
2 changes: 1 addition & 1 deletion dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 26.2.4-wip

- Remove `package:built_value` dependency from `HotReloadRequest`, `HotReloadResponse`, and `HotRestartRequest` and use standard Dart JSON serialization instead.
- Remove `package:built_value` dependency from `HotReloadRequest`, `HotReloadResponse`, `HotRestartRequest`, and `HotRestartResponse` and use standard Dart JSON serialization instead.

## 26.2.3

Expand Down
44 changes: 23 additions & 21 deletions dwds/lib/data/hot_restart_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,33 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library hot_restart_response;

import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';

part 'hot_restart_response.g.dart';

/// A response to a hot restart request.
abstract class HotRestartResponse
implements Built<HotRestartResponse, HotRestartResponseBuilder> {
static Serializer<HotRestartResponse> get serializer =>
_$hotRestartResponseSerializer;

class HotRestartResponse {
/// The unique identifier matching the request.
String get id;
final String id;

/// Whether the hot restart succeeded on the client.
bool get success;
final bool success;

/// An optional error message if success is false.
@BuiltValueField(wireName: 'error')
String? get errorMessage;

HotRestartResponse._();
factory HotRestartResponse([
void Function(HotRestartResponseBuilder) updates,
]) = _$HotRestartResponse;
final String? errorMessage;

HotRestartResponse({
required this.id,
required this.success,
this.errorMessage,
});

factory HotRestartResponse.fromJson(Map<String, dynamic> json) =>
HotRestartResponse(
id: json['id'] as String,
success: json['success'] as bool,
errorMessage: json['error'] as String?,
);

Map<String, dynamic> toJson() => {
'id': id,
'success': success,
if (errorMessage != null) 'error': errorMessage,
};
}
209 changes: 0 additions & 209 deletions dwds/lib/data/hot_restart_response.g.dart

This file was deleted.

2 changes: 0 additions & 2 deletions dwds/lib/data/serializers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import 'debug_info.dart';
import 'devtools_request.dart';
import 'error_response.dart';
import 'extension_request.dart';
import 'hot_restart_response.dart';
import 'service_extension_request.dart';
import 'service_extension_response.dart';
import 'isolate_events.dart';
Expand All @@ -31,7 +30,6 @@ part 'serializers.g.dart';
DebugInfo,
DevToolsRequest,
DevToolsResponse,
HotRestartResponse,
IsolateExit,
IsolateStart,
ExtensionRequest,
Expand Down
1 change: 0 additions & 1 deletion dwds/lib/data/serializers.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion dwds/lib/src/handlers/dev_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,32 @@ class DevHandler {
}
}

/// Deserializes a message from JSON, handling both built_value serializers
/// and custom fromJson() implementations.
Object? _deserializeMessage(dynamic decoded) {
if (decoded is List && decoded.length == 2 && decoded[0] is String) {
final typeName = decoded[0] as String;
final jsonData = decoded[1] as Map<String, dynamic>;

switch (typeName) {
case 'HotReloadResponse':
return HotReloadResponse.fromJson(jsonData);
case 'HotRestartResponse':
return HotRestartResponse.fromJson(jsonData);
default:
// Fall through to serializers.deserialize
break;
}
}
return serializers.deserialize(decoded);
}

void _handleConnection(SocketConnection injectedConnection) {
_injectedConnections.add(injectedConnection);
AppConnection? appConnection;
injectedConnection.stream.listen((data) async {
try {
final message = serializers.deserialize(jsonDecode(data));
final message = _deserializeMessage(jsonDecode(data));
if (message is ConnectRequest) {
if (appConnection != null) {
throw StateError(
Expand Down
Loading
Loading