214 lines
7.3 KiB
Dart
214 lines
7.3 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../core/transport/pipelines_client.dart' as transport;
|
|
import 'settings_controller.dart';
|
|
import 'settings_controls.dart';
|
|
import 'settings_copy.dart';
|
|
import 'settings_keys.dart';
|
|
import 'settings_trust_warning.dart';
|
|
import 'settings_layout.dart';
|
|
|
|
/// Connection controls: the editable endpoint, the truthful connection card and
|
|
/// the trusted-network warning. Every action goes through the shared client the
|
|
/// controller was given; nothing here opens a second connection.
|
|
class SettingsConnectionSection extends StatelessWidget {
|
|
const SettingsConnectionSection({
|
|
super.key,
|
|
required this.controller,
|
|
required this.serverUrlField,
|
|
});
|
|
|
|
final SettingsController controller;
|
|
final TextEditingController serverUrlField;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: <Widget>[
|
|
SettingsTextField(
|
|
controller: serverUrlField,
|
|
key: SettingsKeys.serverUrl,
|
|
label: 'Server URL',
|
|
placeholder: serverUrlPlaceholder,
|
|
helper: serverUrlHelper,
|
|
error: controller.urlError,
|
|
onChanged: controller.updateServerUrl,
|
|
maxLines: 2,
|
|
),
|
|
const SizedBox(height: settingsTitleGap),
|
|
SettingsActions(
|
|
primaryLabel: controller.primaryActionLabel,
|
|
secondaryLabel: controller.secondaryActionLabel,
|
|
primaryKey: controller.connectionActive
|
|
? SettingsKeys.disconnect
|
|
: SettingsKeys.connect,
|
|
secondaryKey: controller.connectionActive
|
|
? SettingsKeys.connect
|
|
: SettingsKeys.reconnect,
|
|
onPrimary: () => unawaited(
|
|
controller.connectionActive
|
|
? controller.disconnect()
|
|
: controller.connect(),
|
|
),
|
|
onSecondary: () => unawaited(
|
|
controller.connectionActive
|
|
? controller.connect()
|
|
: controller.reconnect(),
|
|
),
|
|
),
|
|
if (controller.endpointSaveError.isNotEmpty) ...<Widget>[
|
|
const SizedBox(height: settingsFieldGap),
|
|
Text(
|
|
controller.endpointSaveError,
|
|
style: settingsTextStyle(context, error: true),
|
|
),
|
|
],
|
|
if (controller.actionError.isNotEmpty) ...<Widget>[
|
|
const SizedBox(height: settingsFieldGap),
|
|
Text(
|
|
controller.actionError,
|
|
style: settingsTextStyle(context, error: true),
|
|
),
|
|
],
|
|
const SizedBox(height: settingsTitleGap),
|
|
SettingsStatusCard(controller: controller),
|
|
const SizedBox(height: settingsTitleGap),
|
|
const SettingsTrustWarning(),
|
|
if (controller.protocolWarning case final warning?) ...<Widget>[
|
|
const SizedBox(height: settingsTitleGap),
|
|
// The web page appends the same alert after the trust card. A live
|
|
// region announces a mismatch the operator did not ask to reveal.
|
|
Semantics(
|
|
liveRegion: true,
|
|
child: Text(
|
|
warning,
|
|
style: settingsTextStyle(context, error: true),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
/// The status card's first line is the state; the remaining lines are the
|
|
/// build/time/reason/backoff facts. Missing ping values stay explicit.
|
|
class SettingsStatusCard extends StatelessWidget {
|
|
const SettingsStatusCard({super.key, required this.controller});
|
|
|
|
final SettingsController controller;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
final state = controller.connection;
|
|
final lines = controller.connectionLines;
|
|
final title = lines.isEmpty ? '' : lines.first;
|
|
final details = lines.length > 1 ? lines.sublist(1) : const <String>[];
|
|
final titleColor = switch (state.kind) {
|
|
transport.ConnectionKind.connected =>
|
|
usesCupertinoControls(context)
|
|
? CupertinoTheme.of(context).primaryColor
|
|
: theme.colorScheme.primary,
|
|
transport.ConnectionKind.disconnected => settingsErrorColor(context),
|
|
_ => settingsTextStyle(context).color,
|
|
};
|
|
final titleWidget = Text(
|
|
title,
|
|
style: settingsTextStyle(
|
|
context,
|
|
title: true,
|
|
).copyWith(color: titleColor),
|
|
);
|
|
return SettingsCard(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
if (state.kind == transport.ConnectionKind.connecting)
|
|
Row(
|
|
children: <Widget>[
|
|
if (usesCupertinoControls(context))
|
|
const CupertinoActivityIndicator()
|
|
else
|
|
const CircularProgressIndicator(strokeWidth: 2),
|
|
const SizedBox(width: settingsControlGap),
|
|
Expanded(child: titleWidget),
|
|
],
|
|
)
|
|
else
|
|
titleWidget,
|
|
for (final line in details) ...<Widget>[
|
|
const SizedBox(height: settingsFieldGap),
|
|
Text(line, style: settingsTextStyle(context, secondary: true)),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Workspace controls. The path is resolved by the execution server, and the
|
|
/// helper says so explicitly; an empty saved value is named "(none)".
|
|
class SettingsWorkspaceSection extends StatelessWidget {
|
|
const SettingsWorkspaceSection({
|
|
super.key,
|
|
required this.controller,
|
|
required this.workspaceField,
|
|
});
|
|
|
|
final SettingsController controller;
|
|
final TextEditingController workspaceField;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final saveError = controller.workspaceSaveError;
|
|
final canSave = canSaveWorkspace(controller.workspaceDraft);
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: <Widget>[
|
|
SettingsTextField(
|
|
controller: workspaceField,
|
|
key: SettingsKeys.workspace,
|
|
label: 'Workspace path (on the server)',
|
|
placeholder: workspacePlaceholder,
|
|
helper: workspaceHelper,
|
|
error: controller.workspaceError,
|
|
onChanged: controller.updateWorkspace,
|
|
),
|
|
const SizedBox(height: settingsTitleGap),
|
|
Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: usesCupertinoControls(context)
|
|
? CupertinoButton.filled(
|
|
key: SettingsKeys.saveWorkspace,
|
|
onPressed: canSave
|
|
? () => unawaited(controller.saveWorkspace())
|
|
: null,
|
|
child: const Text('Save workspace'),
|
|
)
|
|
: FilledButton(
|
|
key: SettingsKeys.saveWorkspace,
|
|
onPressed: canSave
|
|
? () => unawaited(controller.saveWorkspace())
|
|
: null,
|
|
child: const Text('Save workspace'),
|
|
),
|
|
),
|
|
const SizedBox(height: settingsFieldGap),
|
|
Text(
|
|
savedWorkspaceLine(controller.savedWorkspace),
|
|
style: settingsTextStyle(context),
|
|
),
|
|
if (saveError.isNotEmpty) ...<Widget>[
|
|
const SizedBox(height: settingsFieldGap),
|
|
Text(saveError, style: settingsTextStyle(context, error: true)),
|
|
],
|
|
],
|
|
);
|
|
}
|
|
}
|