Files
pipelines/app/lib/features/settings/settings_copy.dart
T
alan abd696b0d9 feat(app): add native Settings connection and workspace screen
Add the Settings destination under lib/features/settings with an editable
websocket endpoint, truthful connection states, one ping per connect/mount,
workspace validation and persistence under new feature-owned keys. Material
and Cupertino controls, wrapping copy at large text, pending ping state, and
isolated probe tools plus widget/unit coverage.
2026-10-21 17:39:18 +01:00

114 lines
4.4 KiB
Dart

import '../../core/transport/pipelines_client.dart' as transport;
/// Field and explanatory copy, matching the current web Settings destination
/// (web/src/settings.js) and the Android SettingsScreen it quotes.
const String serverUrlPlaceholder = 'ws://192.168.1.20:8081/connect';
const String serverUrlHelper =
'ws:// on a trusted LAN/VPN, or wss:// through a proxy/VPN. '
'No authentication is used.';
const String workspacePlaceholder = '/Users/you/repos/pipelines';
const String workspaceHelper =
'An absolute directory that already exists on the execution server. For '
'Docker, mount the host directory at the same absolute path with its '
"owner's UID/GID. This is not the phone's storage.";
const String workspacePathError =
'The workspace must be an absolute path that exists on the execution '
'server.';
const String trustTitle = 'Trusted LAN/VPN only';
const String trustBody =
'The Pipelines API has no authentication and is not internet-safe. Do not '
'expose it to untrusted networks, and never enter provider credentials '
'here \u2014 the app stores none.';
/// The workspace draft is valid when it is untouched (empty) or absolute. A
/// relative path is the one rejected value; the execution server resolves the
/// path, so the phone's filesystem is irrelevant.
String? validateWorkspacePath(String value) {
final trimmed = value.trim();
if (trimmed.isEmpty) return null;
if (!trimmed.startsWith('/')) return workspacePathError;
return null;
}
/// Saving requires a real absolute path, not just "no error": the web Settings
/// page deliberately refuses a blank field and records that strictness.
bool canSaveWorkspace(String value) {
final trimmed = value.trim();
return trimmed.isNotEmpty && validateWorkspacePath(trimmed) == null;
}
/// The persisted workspace line. An absent value is named, never rendered as a
/// zero or an empty gap.
String savedWorkspaceLine(String value) {
final trimmed = value.trim();
return 'Saved workspace: ${trimmed.isEmpty ? '(none)' : trimmed}';
}
/// The exact shared connecting sentence used by the banner and status card.
String connectingLabel(int attempt) => 'Connecting (attempt $attempt)\u2026';
/// `Server build {version} ({commit})`, with whichever parts the ping reported.
String serverBuildLabel({String? version, String? commit}) {
final v = (version ?? '').trim();
final c = (commit ?? '').trim();
final parts = <String>[if (v.isNotEmpty) v, if (c.isNotEmpty) '($c)'];
if (parts.isEmpty) return '';
return 'Server build ${parts.join(' ')}';
}
/// The pending sentence shown between `Connected` and the ping reply. It is a
/// request in flight, not a missing value.
const String serverDetailsPending = 'Loading server details\u2026';
/// The status card's lines in the web/Android order. While the ping is in
/// flight the card says it is loading. A completed reply names the build and
/// time, saying "unavailable" only when that reply omitted them; a failed ping
/// is one explicit line instead of two "unavailable" lines plus the error.
List<String> connectionCardLines(
transport.ConnectionState state, {
String? buildVersion,
String? buildCommit,
String? serverTime,
String pingError = '',
bool pingInFlight = false,
}) {
switch (state.kind) {
case transport.ConnectionKind.connected:
final build = serverBuildLabel(
version: buildVersion,
commit: buildCommit,
);
final time = (serverTime ?? '').trim();
final failure = pingError.trim();
if (pingInFlight && build.isEmpty && time.isEmpty && failure.isEmpty) {
return const <String>['Connected', serverDetailsPending];
}
if (failure.isNotEmpty && build.isEmpty && time.isEmpty) {
return <String>['Connected', failure];
}
return <String>[
'Connected',
build.isEmpty ? 'Server build unavailable' : build,
time.isEmpty ? 'Server time unavailable' : 'Server time $time',
if (failure.isNotEmpty) failure,
];
case transport.ConnectionKind.connecting:
return <String>[connectingLabel(state.attempt)];
case transport.ConnectionKind.disconnected:
final reason = state.reason.trim();
return <String>[
'Disconnected',
if (reason.isNotEmpty) reason,
if (state.retrying) 'Retrying with backoff\u2026',
];
case transport.ConnectionKind.idle:
return const <String>['Not connected'];
}
}