Skip to content

Commit

Permalink
[gui] simplify function for extracting update from rpc reply
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-toterman committed Sep 12, 2024
1 parent 6a3f021 commit e655413
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/client/gui/lib/grpc_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ extension on RpcMessage {
String get repr => '$runtimeType${toProto3Json()}';
}

T checkForUpdate<T extends RpcMessage>(T t) {
final updateInfo = switch (t) {
void checkForUpdate(RpcMessage message) {
final updateInfo = switch (message) {
LaunchReply launchReply => launchReply.updateInfo,
InfoReply infoReply => infoReply.updateInfo,
ListReply listReply => listReply.updateInfo,
Expand All @@ -35,8 +35,6 @@ T checkForUpdate<T extends RpcMessage>(T t) {
};

providerContainer.read(updateProvider.notifier).set(updateInfo);

return t;
}

void Function(StreamNotification<RpcMessage>) logGrpc(RpcMessage request) {
Expand Down Expand Up @@ -80,7 +78,7 @@ class GrpcClient {
logger.i('Sent ${request.repr}');
yield* _client
.launch(Stream.value(request))
.map(checkForUpdate)
.doOnData(checkForUpdate)
.doOnEach(logGrpc(request))
.map(Either.left);
for (final mountRequest in mountRequests) {
Expand All @@ -103,7 +101,7 @@ class GrpcClient {
logger.i('Sent ${request.repr}');
return _client
.start(Stream.value(request))
.map(checkForUpdate)
.doOnData(checkForUpdate)
.doOnEach(logGrpc(request))
.firstOrNull;
}
Expand Down Expand Up @@ -137,7 +135,7 @@ class GrpcClient {
logger.i('Sent ${request.repr}');
return _client
.restart(Stream.value(request))
.map(checkForUpdate)
.doOnData(checkForUpdate)
.doOnEach(logGrpc(request))
.firstOrNull;
}
Expand Down Expand Up @@ -188,7 +186,7 @@ class GrpcClient {
);
return _client
.info(Stream.value(request))
.map(checkForUpdate)
.doOnData(checkForUpdate)
.last
.then((r) => r.details.toList());
}
Expand Down Expand Up @@ -226,7 +224,7 @@ class GrpcClient {
logger.i('Sent ${request.repr}');
return _client
.networks(Stream.value(request))
.map(checkForUpdate)
.doOnData(checkForUpdate)
.doOnEach(logGrpc(request))
.last
.then((r) => r.interfaces);
Expand All @@ -237,7 +235,7 @@ class GrpcClient {
logger.i('Sent ${request.repr}');
return _client
.version(Stream.value(request))
.map(checkForUpdate)
.doOnData(checkForUpdate)
.doOnEach(logGrpc(request))
.last
.then((reply) => reply.version);
Expand Down

0 comments on commit e655413

Please sign in to comment.