Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gui launch bridged error #3897

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/client/gui/lib/catalogue/launch_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ class _LaunchFormState extends ConsumerState<LaunchForm> {
super.dispose();
}

final bridgedNetworkProvider = daemonSettingProvider('local.bridged-network');

@override
Widget build(BuildContext context) {
final imageInfo = ref.watch(launchingImageProvider);
final randomName = ref.watch(randomNameProvider);
final vmNames = ref.watch(vmNamesProvider);
final deletedVms = ref.watch(deletedVmsProvider);
final networks = ref.watch(networksProvider);
final bridgedNetworkSetting = ref.watch(bridgedNetworkProvider).valueOrNull;

final closeButton = IconButton(
icon: const Icon(Icons.close),
Expand Down Expand Up @@ -99,19 +103,30 @@ class _LaunchFormState extends ConsumerState<LaunchForm> {
onSaved: (value) => launchRequest.diskSpace = '${value!}B',
);

final validBridgedNetwork = networks.contains(bridgedNetworkSetting);
final bridgedSwitch = FormField<bool>(
enabled: validBridgedNetwork,
initialValue: false,
onSaved: (value) {
if (value!) {
launchRequest.networkOptions
.add(LaunchRequest_NetworkOptions(id: 'bridged'));
}
},
builder: (field) => Switch(
label: 'Connect to bridged network',
value: field.value!,
onChanged: field.didChange,
),
builder: (field) {
final message = networks.isEmpty
? 'No networks found.'
: validBridgedNetwork
? "Connect to the bridged network.\nOnce established, you won't be able to unset the connection."
: 'No valid bridged network is set.\nYou can set one in the Settings page.';

return Switch(
label: message,
value: validBridgedNetwork ? field.value! : false,
enabled: validBridgedNetwork,
onChanged: field.didChange,
);
},
);

final mountPointsView = MountPointsView(
Expand Down
13 changes: 8 additions & 5 deletions src/client/gui/lib/grpc_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,21 @@ class GrpcClient {
Future<void>? cancel,
}) async* {
logger.i('Sent ${request.repr}');
final launchStream = _client.launch(Stream.value(request));
cancel?.then((_) => launchStream.cancel());
yield* launchStream
final launchReplyStream = _client.launch(Stream.value(request));
cancel?.then((_) => launchReplyStream.cancel());
final launchStream = launchReplyStream
.doOnData(checkForUpdate)
.doOnEach(logGrpc(request))
.map(Either.left);
.map(Either<LaunchReply, MountReply>.left);
await for (final launchReply in launchStream) {
yield launchReply;
}
for (final mountRequest in mountRequests) {
logger.i('Sent ${mountRequest.repr}');
yield* _client
.mount(Stream.value(mountRequest))
.doOnEach(logGrpc(mountRequest))
.map(Either.right);
.map((Either<LaunchReply, MountReply>.right));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/client/gui/lib/settings/virtualization_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class VirtualizationSettings extends ConsumerWidget {
Dropdown<String>(
label: 'Bridged network',
width: 260,
value: networks.contains(bridgedNetwork) ? bridgedNetwork : null,
items: Map.fromIterable(networks),
value: networks.contains(bridgedNetwork) ? bridgedNetwork : '',
items: {'': 'None', ...Map.fromIterable(networks)},
onChanged: (value) {
ref.read(bridgedNetworkProvider.notifier).set(value!).onError(
ref.notifyError((e) => 'Failed to set bridged network: $e'));
Expand Down
8 changes: 5 additions & 3 deletions src/client/gui/lib/switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Switch extends StatelessWidget {
final String label;
final bool trailingSwitch;
final double size;
final bool enabled;

const Switch({
super.key,
Expand All @@ -14,6 +15,7 @@ class Switch extends StatelessWidget {
this.label = '',
this.trailingSwitch = false,
this.size = 25,
this.enabled = true,
});

@override
Expand All @@ -22,10 +24,10 @@ class Switch extends StatelessWidget {
height: size,
child: FittedBox(
child: CupertinoSwitch(
activeColor: CupertinoColors.activeBlue,
trackColor: const Color(0xffd9d9d9),
activeTrackColor: CupertinoColors.activeBlue,
inactiveTrackColor: const Color(0xffd9d9d9),
value: value,
onChanged: onChanged,
onChanged: enabled ? onChanged : null,
),
),
);
Expand Down
2 changes: 1 addition & 1 deletion src/client/gui/lib/vm_details/vm_details_bridge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class _BridgedDetailsState extends ConsumerState<BridgedDetails> {
final message = networks.isEmpty
? 'No networks found.'
: validBridgedNetwork
? "Once connection is established, you won't be able to unset it."
? "Once established, you won't be able to unset the connection."
: 'No valid bridged network is set.';

return CheckboxListTile(
Expand Down
Loading