Files
pipelines/app/lib/features/settings/settings_copy.dart
T
alan 3ec580c2d9 Restyle Settings as flat grouped list sections (F9) and scroll it behind the bar (F1)
Servers become rows with a selection mark, addresses as subtitles and a
Use/Edit/Remove menu plus an Add server row; the connection is a status row
with address and Reconnect/Disconnect rows; Templates and Schedules are
chevron rows in a Library group. Material groups are flat surfaceContainer
surfaces with primary titleSmall headers (no Cards); Cupertino uses
inset-grouped sections on the grouped background, switches for the ntfy
choices. The trust warning is a footer, helper copy is shortened, Save
workspace is a legible tonal/plain button, and the column starts at the
bar's inset (max 720) instead of being centred. The page pads by the top
media padding instead of a top SafeArea.
2026-10-31 03:07:20 +00:00

113 lines
4.3 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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:// only on a trusted LAN/VPN, otherwise wss://. Use the web '
'proxy’s /connect address when sign-in is required.';
const String workspacePlaceholder = '/Users/you/repos/pipelines';
const String workspaceHelper =
'An existing absolute directory on the execution server, not the '
"phone's storage. With Docker, mount it at the same path and owner.";
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 =
'Direct API access has no authentication: keep ws:// on a trusted '
'LAN/VPN, prefer wss://, and use the authenticated web address remotely. '
'Never enter provider credentials here.';
/// 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'];
}
}