diff --git a/app/lib/features/settings/managed_connection_section.dart b/app/lib/features/settings/managed_connection_section.dart index d07cb0c8..3bf7700f 100644 --- a/app/lib/features/settings/managed_connection_section.dart +++ b/app/lib/features/settings/managed_connection_section.dart @@ -5,12 +5,23 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import '../../core/transport/pipelines_client.dart'; -import '../../ui/adaptive/host.dart'; import 'settings_controller.dart'; +import 'settings_group.dart'; +import 'settings_row.dart'; import 'settings_sections.dart'; -import 'settings_trust_warning.dart'; +import 'settings_theme.dart'; -/// Status follows the actual attempted address, not just the preferred URL. +/// The short line under the managed connection's rows. +const String managedConnectionHelp = + 'Reconnect tries the preferred address first, then the backups.'; + +/// The browser-only addition to [managedConnectionHelp]. +const String managedConnectionWebHelp = + 'In a browser the connection stays on this page’s origin.'; + +/// The saved-server connection: its state, the address actually attempted and +/// Reconnect / Disconnect rows. Status follows the actual attempted address, +/// not just the preferred URL. class ManagedConnectionSection extends StatelessWidget { const ManagedConnectionSection({ super.key, @@ -20,43 +31,49 @@ class ManagedConnectionSection extends StatelessWidget { final PipelinesClient client; final SettingsController controller; - Widget _action(BuildContext context, String text, VoidCallback? press) => - usesCupertinoHost(context) - ? CupertinoButton(onPressed: press, child: Text(text)) - : TextButton(onPressed: press, child: Text(text)); - @override - Widget build(BuildContext context) => Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - SelectableText('Current address: ${client.endpoint ?? 'Not connected'}'), - const SizedBox(height: 8), - const Text( - 'Reconnect tries the preferred address first. A dropped or ' - 'unreachable connection tries this server’s backup addresses automatically.', - ), - if (kIsWeb) - const Text( - 'In a browser, the connection stays on this page’s ' - 'origin. Use a saved server to open its page; native apps use automatic address fallback.', - ), - Wrap( - spacing: 8, - children: [ - _action( - context, - 'Reconnect', - client.endpoints.isEmpty - ? null - : () => unawaited(client.connectAny(client.endpoints)), + Widget build(BuildContext context) { + final cupertino = usesCupertinoControls(context); + return SettingsGroup( + title: 'Connection', + leadingRows: true, + footer: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Text( + kIsWeb + ? '$managedConnectionHelp $managedConnectionWebHelp' + : managedConnectionHelp, ), - _action(context, 'Disconnect', () => unawaited(client.disconnect())), + const SizedBox(height: 12), + settingsConnectionFooter(controller), ], ), - SettingsStatusCard(controller: controller), - const SizedBox(height: 12), - const SettingsTrustWarning(), - if (controller.protocolWarning case final warning?) Text(warning), - ], - ); + children: [ + SettingsStatusRow(controller: controller), + SettingsRow( + leading: Icon(cupertino ? CupertinoIcons.link : Icons.link), + title: const Text('Current address'), + subtitle: SelectableText('${client.endpoint ?? 'Not connected'}'), + ), + SettingsRow( + action: true, + enabled: client.endpoints.isNotEmpty, + leading: Icon( + cupertino ? CupertinoIcons.arrow_clockwise : Icons.refresh, + ), + title: const Text('Reconnect'), + onTap: () => unawaited(client.connectAny(client.endpoints)), + ), + SettingsRow( + action: true, + leading: Icon( + cupertino ? CupertinoIcons.stop_circle : Icons.link_off, + ), + title: const Text('Disconnect'), + onTap: () => unawaited(client.disconnect()), + ), + ], + ); + } } diff --git a/app/lib/features/settings/saved_server_row.dart b/app/lib/features/settings/saved_server_row.dart new file mode 100644 index 00000000..af928c24 --- /dev/null +++ b/app/lib/features/settings/saved_server_row.dart @@ -0,0 +1,121 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../../core/servers/server_catalog.dart'; +import 'settings_row.dart'; +import 'settings_theme.dart'; + +/// What a saved server's menu can do. +enum SavedServerAction { use, edit, remove } + +/// The key of a saved server's actions menu button. +ValueKey savedServerMenuKey(String id) => + ValueKey('settings.server.$id.menu'); + +/// One saved server: a selection mark, the name, "Selected server" on the +/// active one and each address (preferred, then backups) as subtitle lines. +/// Tapping another server uses it; the trailing menu offers Use, Edit and +/// Remove. +class SavedServerRow extends StatelessWidget { + const SavedServerRow({ + super.key, + required this.server, + required this.selected, + required this.busy, + required this.onAction, + }); + + final SavedServer server; + final bool selected; + final bool busy; + final ValueChanged onAction; + + String _label(SavedServerAction action) => switch (action) { + SavedServerAction.use => 'Use ${server.name}', + SavedServerAction.edit => 'Edit ${server.name}', + SavedServerAction.remove => 'Remove ${server.name}', + }; + + List get _actions => [ + if (!selected) SavedServerAction.use, + SavedServerAction.edit, + SavedServerAction.remove, + ]; + + Future _cupertinoMenu(BuildContext context) async { + final action = await showCupertinoModalPopup( + context: context, + builder: (context) => CupertinoActionSheet( + title: Text(server.name), + actions: [ + for (final action in _actions) + CupertinoActionSheetAction( + isDestructiveAction: action == SavedServerAction.remove, + onPressed: () => Navigator.pop(context, action), + child: Text(_label(action)), + ), + ], + cancelButton: CupertinoActionSheetAction( + onPressed: () => Navigator.pop(context), + child: const Text('Cancel'), + ), + ), + ); + if (action != null) onAction(action); + } + + @override + Widget build(BuildContext context) { + final cupertino = usesCupertinoControls(context); + final Widget menu = cupertino + ? CupertinoButton( + key: savedServerMenuKey(server.id), + padding: EdgeInsets.zero, + onPressed: busy ? null : () => _cupertinoMenu(context), + child: Icon( + CupertinoIcons.ellipsis_circle, + semanticLabel: '${server.name} actions', + ), + ) + : PopupMenuButton( + key: savedServerMenuKey(server.id), + enabled: !busy, + tooltip: '${server.name} actions', + onSelected: onAction, + itemBuilder: (context) => >[ + for (final action in _actions) + PopupMenuItem(value: action, child: Text(_label(action))), + ], + ); + final Widget mark = selected + ? Icon( + cupertino + ? CupertinoIcons.checkmark_circle_fill + : Icons.check_circle, + semanticLabel: 'Selected', + color: cupertino + ? CupertinoTheme.of(context).primaryColor + : Theme.of(context).colorScheme.primary, + ) + : Icon( + cupertino ? CupertinoIcons.circle : Icons.radio_button_unchecked, + color: cupertino + ? CupertinoColors.tertiaryLabel.resolveFrom(context) + : null, + ); + return SettingsRow( + leading: mark, + title: Text(server.name), + subtitle: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (selected) const Text('Selected server'), + for (final (index, address) in server.endpoints.indexed) + Text('${index == 0 ? 'Preferred' : 'Backup $index'}: $address'), + ], + ), + trailing: menu, + onTap: selected || busy ? null : () => onAction(SavedServerAction.use), + ); + } +} diff --git a/app/lib/features/settings/saved_servers_section.dart b/app/lib/features/settings/saved_servers_section.dart index 0e52c963..26767aff 100644 --- a/app/lib/features/settings/saved_servers_section.dart +++ b/app/lib/features/settings/saved_servers_section.dart @@ -6,7 +6,11 @@ import 'package:flutter/material.dart'; import '../../core/servers/server_catalog.dart'; import '../../ui/adaptive/host.dart'; import 'saved_server_editor.dart'; +import 'saved_server_row.dart'; import 'server_connections.dart'; +import 'settings_group.dart'; +import 'settings_row.dart'; +import 'settings_theme.dart'; class _ServerSaveFailure implements Exception { const _ServerSaveFailure(this.message); @@ -79,73 +83,46 @@ class SavedServersSection extends StatelessWidget { if (confirmed == true) await connections.remove(server.id); } - Widget _button(BuildContext context, String label, VoidCallback? press) => - usesCupertinoHost(context) - ? CupertinoButton(onPressed: press, child: Text(label)) - : TextButton(onPressed: press, child: Text(label)); + void _act(BuildContext context, SavedServer server, SavedServerAction act) { + switch (act) { + case SavedServerAction.use: + unawaited(connections.select(server.id)); + case SavedServerAction.edit: + unawaited(_edit(context, server)); + case SavedServerAction.remove: + unawaited(_remove(context, server)); + } + } @override Widget build(BuildContext context) => ListenableBuilder( listenable: connections, - builder: (context, _) => Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - for (final server in connections.catalog.servers) ...[ - Text( - server.name, - style: const TextStyle(fontWeight: FontWeight.w600), - ), - if (server.id == connections.catalog.active?.id) - const Text('Selected server'), - for (final (index, address) in server.endpoints.indexed) - Text('${index == 0 ? 'Preferred' : 'Backup $index'}: $address'), - Wrap( - spacing: 8, - children: [ - if (server.id != connections.catalog.active?.id) - _button( - context, - 'Use ${server.name}', - connections.busy - ? null - : () => unawaited(connections.select(server.id)), - ), - _button( - context, - 'Edit ${server.name}', - connections.busy - ? null - : () => unawaited(_edit(context, server)), - ), - _button( - context, - 'Remove ${server.name}', - connections.busy - ? null - : () => unawaited(_remove(context, server)), - ), - ], - ), - const SizedBox(height: 12), - ], - Align( - alignment: AlignmentDirectional.centerStart, - child: _button( - context, - 'Add server', - connections.busy ? null : () => unawaited(_edit(context)), - ), - ), - if (connections.error != null) - Text( - connections.error!, - style: TextStyle( - color: usesCupertinoHost(context) - ? CupertinoColors.systemRed.resolveFrom(context) - : Theme.of(context).colorScheme.error, + builder: (context, _) { + final cupertino = usesCupertinoHost(context); + final error = connections.error; + return SettingsGroup( + title: 'Servers', + leadingRows: true, + footer: error == null + ? null + : Text(error, style: TextStyle(color: settingsErrorColor(context))), + children: [ + for (final server in connections.catalog.servers) + SavedServerRow( + server: server, + selected: server.id == connections.catalog.active?.id, + busy: connections.busy, + onAction: (act) => _act(context, server, act), ), + SettingsRow( + action: true, + enabled: !connections.busy, + leading: Icon(cupertino ? CupertinoIcons.add : Icons.add), + title: const Text('Add server'), + onTap: () => unawaited(_edit(context)), ), - ], - ), + ], + ); + }, ); } diff --git a/app/lib/features/settings/settings_android_download_section.dart b/app/lib/features/settings/settings_android_download_section.dart index 313adaa2..49c2d9a1 100644 --- a/app/lib/features/settings/settings_android_download_section.dart +++ b/app/lib/features/settings/settings_android_download_section.dart @@ -73,7 +73,7 @@ class _SettingsAndroidDownloadSectionState Widget build(BuildContext context) { final cupertino = usesCupertinoHost(context); final muted = cupertino - ? CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith( + ? CupertinoTheme.of(context).textTheme.textStyle.copyWith( color: CupertinoColors.secondaryLabel.resolveFrom(context), ) : Theme.of(context).textTheme.bodySmall?.copyWith( @@ -81,18 +81,12 @@ class _SettingsAndroidDownloadSectionState ); final update = _update; if (_loading) { - return Padding( - padding: const EdgeInsets.all(16), - child: Text('Checking for the Android app…', style: muted), - ); + return Text('Checking for the Android app…', style: muted); } if (update == null) { - return Padding( - padding: const EdgeInsets.all(16), - child: Text( - 'This server offers no Android app yet. Build one with ./install --apk.', - style: muted, - ), + return Text( + 'This server offers no Android app yet. Build one with ./install --apk.', + style: muted, ); } final button = cupertino @@ -107,30 +101,27 @@ class _SettingsAndroidDownloadSectionState icon: const Icon(Icons.download), label: const Text('Download APK'), ); - return Padding( - padding: const EdgeInsets.all(16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text('Pipelines for Android · build ${update.versionCode}'), - if (update.notes.isNotEmpty) ...[ - const SizedBox(height: 4), - Text(update.notes, style: muted), - ], - const SizedBox(height: 12), - button, - const SizedBox(height: 8), - Text( - 'Open it on the phone, allow installs from this browser, then sign ' - 'in under Settings. Later builds arrive through Check for updates.', - style: muted, - ), - if (_message case final message?) ...[ - const SizedBox(height: 8), - Text(message, style: muted), - ], + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('Pipelines for Android · build ${update.versionCode}'), + if (update.notes.isNotEmpty) ...[ + const SizedBox(height: 4), + Text(update.notes, style: muted), ], - ), + const SizedBox(height: 12), + button, + const SizedBox(height: 8), + Text( + 'Open it on the phone and allow installs from this browser; later ' + 'builds arrive through Check for updates.', + style: muted, + ), + if (_message case final message?) ...[ + const SizedBox(height: 8), + Text(message, style: muted), + ], + ], ); } } diff --git a/app/lib/features/settings/settings_controls.dart b/app/lib/features/settings/settings_controls.dart index c86eae1d..6d87ddfb 100644 --- a/app/lib/features/settings/settings_controls.dart +++ b/app/lib/features/settings/settings_controls.dart @@ -1,4 +1,3 @@ -import '../../ui/theme/app_theme.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -189,37 +188,3 @@ class SettingsActions extends StatelessWidget { ); } } - -/// One standard settings card: a Material [Card] or an inset-grouped Cupertino -/// section, both using theme surfaces and native corner/padding defaults. -class SettingsCard extends StatelessWidget { - const SettingsCard({super.key, required this.child}); - - final Widget child; - - @override - Widget build(BuildContext context) { - if (usesCupertinoControls(context)) { - return CupertinoListSection.insetGrouped( - backgroundColor: AppColors.groupedBackground, - margin: EdgeInsets.zero, - children: [ - SizedBox( - width: double.infinity, - child: Padding( - padding: const EdgeInsets.all(settingsCardPadding), - child: child, - ), - ), - ], - ); - } - return Card( - margin: EdgeInsets.zero, - child: Padding( - padding: const EdgeInsets.all(settingsCardPadding), - child: child, - ), - ); - } -} diff --git a/app/lib/features/settings/settings_copy.dart b/app/lib/features/settings/settings_copy.dart index b3cd1a7d..93277be4 100644 --- a/app/lib/features/settings/settings_copy.dart +++ b/app/lib/features/settings/settings_copy.dart @@ -5,15 +5,14 @@ import '../../core/transport/pipelines_client.dart' as transport; const String serverUrlPlaceholder = 'ws://192.168.1.20:8081/connect'; const String serverUrlHelper = - 'ws:// only on a trusted LAN/VPN, or wss:// for TLS. ' - 'Use the authenticated web proxy’s /connect address when sign-in is required.'; + '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 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."; + '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 ' @@ -22,9 +21,9 @@ const String workspacePathError = const String trustTitle = 'Trusted LAN/VPN only'; const String trustBody = - 'Use the authenticated web address for remote access. Direct API access ' - 'has no authentication and must stay on a trusted LAN/VPN. ws:// traffic ' - 'is unencrypted; prefer wss://. Never enter provider credentials here.'; + '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 diff --git a/app/lib/features/settings/settings_group.dart b/app/lib/features/settings/settings_group.dart new file mode 100644 index 00000000..e17ba071 --- /dev/null +++ b/app/lib/features/settings/settings_group.dart @@ -0,0 +1,151 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../../ui/theme/app_theme.dart'; +import 'settings_layout.dart'; +import 'settings_theme.dart'; + +/// One grouped Settings section: a short header, a flat rounded group of rows +/// and an optional one-line footer. +/// +/// Material draws the header in the theme's primary `titleSmall` and the rows +/// on a flat `surfaceContainer` with hairline dividers (no elevation). +/// Cupertino uses the stock inset-grouped [CupertinoListSection], whose rows +/// sit on `secondarySystemGroupedBackground` over the page's +/// `systemGroupedBackground`. +class SettingsGroup extends StatelessWidget { + const SettingsGroup({ + super.key, + required this.children, + this.title, + this.footer, + this.leadingRows = false, + }); + + final String? title; + final List children; + + /// A short line (or two) under the group: helper copy, a warning. + final Widget? footer; + + /// Whether the rows carry leading icons: Cupertino then starts its + /// dividers at the titles (the stock inset), otherwise at the row text. + final bool leadingRows; + + @override + Widget build(BuildContext context) { + final title = this.title; + final footer = this.footer; + if (usesCupertinoControls(context)) { + return CupertinoListSection.insetGrouped( + margin: EdgeInsets.zero, + backgroundColor: AppColors.groupedBackground, + header: title == null + ? null + : Text(title, style: settingsHeaderStyle(context)), + footer: footer == null ? null : _footer(context, footer), + additionalDividerMargin: leadingRows ? null : 6, + children: children.isEmpty ? null : children, + ); + } + final theme = Theme.of(context); + return Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + if (title != null) + Padding( + padding: const EdgeInsetsDirectional.fromSTEB( + settingsRowInset, + 0, + settingsRowInset, + settingsTitleGap, + ), + child: Semantics( + header: true, + child: Text(title, style: settingsHeaderStyle(context)), + ), + ), + if (children.isNotEmpty) + Material( + type: MaterialType.card, + color: theme.colorScheme.surfaceContainer, + elevation: 0, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(settingsGroupRadius), + ), + clipBehavior: Clip.antiAlias, + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + for (final (index, child) in children.indexed) ...[ + if (index > 0) + Divider( + height: 1, + thickness: 1, + indent: settingsRowInset, + color: theme.colorScheme.outlineVariant, + ), + child, + ], + ], + ), + ), + if (footer != null) _footer(context, footer), + ], + ); + } + + Widget _footer(BuildContext context, Widget footer) { + final cupertino = usesCupertinoControls(context); + // Cupertino: the footnote size the stock plain list section uses for + // its own header and footer. + final style = cupertino + ? settingsTextStyle(context, secondary: true).copyWith(fontSize: 13) + : Theme.of(context).textTheme.bodySmall?.copyWith( + color: Theme.of(context).colorScheme.onSurfaceVariant, + ); + final text = DefaultTextStyle.merge(style: style, child: footer); + // The Cupertino section pads its own footer. + if (cupertino) return text; + return Padding( + padding: const EdgeInsetsDirectional.fromSTEB( + settingsRowInset, + settingsFieldGap + 2, + settingsRowInset, + 0, + ), + child: text, + ); + } +} + +/// A group header's text style. +TextStyle settingsHeaderStyle(BuildContext context) { + if (usesCupertinoControls(context)) { + return settingsTextStyle(context).copyWith(fontWeight: FontWeight.w600); + } + final theme = Theme.of(context); + return (theme.textTheme.titleSmall ?? const TextStyle()).copyWith( + color: theme.colorScheme.primary, + ); +} + +/// Free-form content inside a group (a text field, a status block), padded +/// like a row so its edges line up with the rows' text. +class SettingsGroupItem extends StatelessWidget { + const SettingsGroupItem({super.key, required this.child}); + + final Widget child; + + @override + Widget build(BuildContext context) => SizedBox( + width: double.infinity, + child: Padding( + padding: EdgeInsetsDirectional.symmetric( + horizontal: usesCupertinoControls(context) ? 20 : settingsRowInset, + vertical: 12, + ), + child: child, + ), + ); +} diff --git a/app/lib/features/settings/settings_layout.dart b/app/lib/features/settings/settings_layout.dart index 10ab480c..2ac7d7d9 100644 --- a/app/lib/features/settings/settings_layout.dart +++ b/app/lib/features/settings/settings_layout.dart @@ -4,34 +4,38 @@ /// from the active Material or Cupertino theme, so text scaling and platform /// defaults are never overridden here. /// -/// The rhythm follows the web Settings page: one centred column, an 8px gap -/// between a section's compact title and its grouped body, and 16px between -/// sections. The web's 12px field label and helper lines are secondary type in -/// [settingsTextStyle]/[SettingsTextField], not fixed sizes. +/// The page is a column of grouped sections. It starts at the top bar's own +/// side inset, so on a wide window the groups line up under the title pill +/// instead of floating in the middle, and stops growing at a reading width. library; -/// A comfortable reading width on wide windows; the body is centred inside it. +/// The widest the column of groups grows on a wide window. const double settingsContentMaxWidth = 720; -/// Space between the Settings sections (web `.settings` grid gap). -const double settingsSectionGap = 16; +/// Space between the Settings groups. +const double settingsSectionGap = 24; -/// Space between a compact section title and its grouped body, and between the -/// blocks inside a section (web `.settings-section` grid gap). +/// Space between a group's header and its rows, and between stacked blocks +/// inside a row. const double settingsTitleGap = 8; /// Space between a field label and its field, and between stacked secondary -/// lines (web `.settings-field` gap). +/// lines. const double settingsFieldGap = 4; /// Space between wrapped action buttons. const double settingsControlGap = 8; -/// Page insets on narrow windows: a little more room above the first title, -/// and a clear run-out below the last section (web `.settings` padding). -const double settingsPageTopPadding = 20; -const double settingsPageSidePadding = 16; +/// The page's side inset: the segmented bar's own, so the groups' edge lines +/// up with the title pill. +const double settingsPageSidePadding = 12; + +/// Space below the top bar (added to its height) and below the last group. +const double settingsPageTopPadding = 8; const double settingsPageBottomPadding = 32; -/// Padding inside a standard Material card / Cupertino inset row. -const double settingsCardPadding = 16; +/// The inset of a row's text inside a Material group (the [ListTile] default). +const double settingsRowInset = 16; + +/// The corner radius of a Material group. +const double settingsGroupRadius = 16; diff --git a/app/lib/features/settings/settings_notifications_section.dart b/app/lib/features/settings/settings_notifications_section.dart index 7364c55b..0b1fdc24 100644 --- a/app/lib/features/settings/settings_notifications_section.dart +++ b/app/lib/features/settings/settings_notifications_section.dart @@ -1,7 +1,9 @@ import 'package:flutter/widgets.dart'; import '../attention/notify/notification_controller.dart'; +import '../attention/notify/notification_models.dart'; import '../attention/ui/notification_permission_tile.dart'; +import 'settings_group.dart'; /// The Settings entry for the browser notification permission. /// @@ -10,24 +12,28 @@ import '../attention/ui/notification_permission_tile.dart'; /// Enable action. The controller is shared with the Runs attention surface, so /// the permission shown here is the one that gates the live notices. class SettingsNotificationsSection extends StatelessWidget { - const SettingsNotificationsSection({ - super.key, - required this.controller, - }); + const SettingsNotificationsSection({super.key, required this.controller}); final NotificationController controller; @override Widget build(BuildContext context) => AnimatedBuilder( animation: controller, - builder: (context, _) => NotificationPermissionTile( - state: controller.permission, - asked: controller.asked, - onRequest: () { - // The platform answer updates the controller; the AnimationBuilder above - // redraws the tile with its own words. - controller.requestPermission(); - }, + builder: (context, _) => SettingsGroup( + title: notificationSectionTitle, + children: [ + SettingsGroupItem( + child: NotificationPermissionTile( + state: controller.permission, + asked: controller.asked, + onRequest: () { + // The platform answer updates the controller; the + // AnimationBuilder above redraws the tile with its own words. + controller.requestPermission(); + }, + ), + ), + ], ), ); } diff --git a/app/lib/features/settings/settings_ntfy_section.dart b/app/lib/features/settings/settings_ntfy_section.dart index e9e9a3c3..77ea450a 100644 --- a/app/lib/features/settings/settings_ntfy_section.dart +++ b/app/lib/features/settings/settings_ntfy_section.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; import '../../core/api_gateway.dart'; import 'ntfy_settings_controller.dart'; -import 'settings_layout.dart'; +import 'settings_group.dart'; import 'settings_theme.dart'; /// The section title for the server's ntfy notification choices. @@ -93,36 +93,24 @@ class _SettingsNtfySectionState extends State { enabled ? (value) => _controller.toggle(setting.key, value) : null, ), ]; - return Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Text( - ntfySectionSubtitle, - style: settingsTextStyle(context, secondary: true), - ), - if (status.isNotEmpty) ...[ - const SizedBox(height: settingsFieldGap), - Text(status, style: settingsTextStyle(context, secondary: true)), - ], - const SizedBox(height: settingsFieldGap), - if (cupertino) - CupertinoListSection.insetGrouped( - margin: EdgeInsets.zero, - children: tiles, - ) - else - ...tiles, - if (_controller.error.isNotEmpty) ...[ - const SizedBox(height: settingsFieldGap), - Semantics( - liveRegion: true, - child: Text( - _controller.error, - key: ntfyErrorKey, - style: settingsTextStyle(context, error: true), + final retry = values == null && widget.connected && !_controller.loading; + return SettingsGroup( + title: ntfySectionTitle, + footer: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + const Text(ntfySectionSubtitle), + if (status.isNotEmpty) Text(status), + if (_controller.error.isNotEmpty) + Semantics( + liveRegion: true, + child: Text( + _controller.error, + key: ntfyErrorKey, + style: TextStyle(color: settingsErrorColor(context)), + ), ), - ), - if (values == null && widget.connected && !_controller.loading) + if (_controller.error.isNotEmpty && retry) Align( alignment: AlignmentDirectional.centerStart, child: cupertino @@ -137,7 +125,8 @@ class _SettingsNtfySectionState extends State { ), ), ], - ], + ), + children: tiles, ); } @@ -151,16 +140,14 @@ class _SettingsNtfySectionState extends State { return CupertinoListTile( key: ntfySettingKey(setting.key), title: Text(setting.label), - trailing: CupertinoCheckbox( - value: value, - onChanged: onChanged == null ? null : (next) => onChanged(next!), - ), + // iOS settings rows toggle with a switch; an unchecked checkbox is + // nearly invisible on the grouped row. + trailing: CupertinoSwitch(value: value, onChanged: onChanged), onTap: onChanged == null ? null : () => onChanged(!value), ); } return CheckboxListTile( key: ntfySettingKey(setting.key), - contentPadding: EdgeInsets.zero, title: Text(setting.label), value: value, onChanged: onChanged == null ? null : (next) => onChanged(next!), diff --git a/app/lib/features/settings/settings_page_body.dart b/app/lib/features/settings/settings_page_body.dart new file mode 100644 index 00000000..48f0f423 --- /dev/null +++ b/app/lib/features/settings/settings_page_body.dart @@ -0,0 +1,63 @@ +import 'package:flutter/cupertino.dart'; + +import '../../ui/theme/app_theme.dart'; +import 'settings_layout.dart'; +import 'settings_theme.dart'; + +/// The Settings page's scrolling column of groups. +/// +/// It scrolls behind the floating top bar: instead of a top [SafeArea] it pads +/// its start by the bar's height (the top media padding), and its end by the +/// floating tab bar's (the bottom media padding), so at rest nothing is hidden +/// and scrolled groups pass behind the glass pills. The column starts at the +/// bar's own side inset, so the groups line up under the title pill, and stops +/// at [settingsContentMaxWidth] on a wide window. Cupertino paints the page in +/// the grouped background its inset-grouped sections are designed for. +class SettingsPageBody extends StatelessWidget { + const SettingsPageBody({super.key, required this.children}); + + final List children; + + @override + Widget build(BuildContext context) { + final insets = MediaQuery.paddingOf(context); + // The inset-grouped section already pads above its own header. + final gap = usesCupertinoControls(context) + ? settingsTitleGap + : settingsSectionGap; + final Widget list = SingleChildScrollView( + key: const ValueKey('settings.scroll'), + padding: EdgeInsets.fromLTRB( + insets.left + settingsPageSidePadding, + insets.top + settingsPageTopPadding, + insets.right + settingsPageSidePadding, + insets.bottom + settingsPageBottomPadding, + ), + child: Align( + alignment: AlignmentDirectional.topStart, + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: settingsContentMaxWidth), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + for (final (index, child) in children.indexed) ...[ + if (index > 0) SizedBox(height: gap), + child, + ], + ], + ), + ), + ), + ); + if (!usesCupertinoControls(context)) return list; + return ColoredBox( + color: settingsCupertinoBackground.resolveFrom(context), + child: list, + ); + } +} + +/// The Cupertino Settings page background: the system grouped background, so +/// the inset sections' rows read as raised cards in light and dark. +const CupertinoDynamicColor settingsCupertinoBackground = + AppColors.groupedBackground; diff --git a/app/lib/features/settings/settings_row.dart b/app/lib/features/settings/settings_row.dart new file mode 100644 index 00000000..42ab2d04 --- /dev/null +++ b/app/lib/features/settings/settings_row.dart @@ -0,0 +1,86 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import 'settings_theme.dart'; + +/// One row of a [SettingsGroup]: Material [ListTile], Cupertino +/// [CupertinoListTile]. The subtitle wraps (the Cupertino tile otherwise caps +/// it at one line), so addresses and status details stay readable at large +/// text. +class SettingsRow extends StatelessWidget { + const SettingsRow({ + super.key, + required this.title, + this.subtitle, + this.leading, + this.trailing, + this.onTap, + this.chevron = false, + this.action = false, + this.enabled = true, + }); + + final Widget title; + final Widget? subtitle; + final Widget? leading; + final Widget? trailing; + final VoidCallback? onTap; + + /// A navigation row: shows the platform's disclosure chevron. + final bool chevron; + + /// A command row (Reconnect, Add server): the title takes the accent + /// colour, as a button would. + final bool action; + final bool enabled; + + Widget _wrapping(Widget child) => Builder( + builder: (context) => DefaultTextStyle( + style: DefaultTextStyle.of(context).style, + child: child, + ), + ); + + @override + Widget build(BuildContext context) { + final tap = enabled ? onTap : null; + final subtitle = this.subtitle; + if (usesCupertinoControls(context)) { + final accent = CupertinoTheme.of(context).primaryColor; + final disabled = CupertinoColors.tertiaryLabel.resolveFrom(context); + return CupertinoListTile( + leading: leading == null + ? null + : IconTheme.merge( + data: IconThemeData(color: enabled ? accent : disabled), + child: leading!, + ), + title: DefaultTextStyle.merge( + style: TextStyle( + color: !enabled + ? disabled + : action + ? accent + : null, + ), + child: title, + ), + subtitle: subtitle == null ? null : _wrapping(subtitle), + trailing: + trailing ?? (chevron ? const CupertinoListTileChevron() : null), + onTap: tap, + ); + } + final scheme = Theme.of(context).colorScheme; + return ListTile( + enabled: enabled, + leading: leading, + iconColor: action ? scheme.primary : null, + textColor: action ? scheme.primary : null, + title: title, + subtitle: subtitle, + trailing: trailing ?? (chevron ? const Icon(Icons.chevron_right) : null), + onTap: tap, + ); + } +} diff --git a/app/lib/features/settings/settings_schedules_section.dart b/app/lib/features/settings/settings_schedules_section.dart index ce129bf5..811de3f9 100644 --- a/app/lib/features/settings/settings_schedules_section.dart +++ b/app/lib/features/settings/settings_schedules_section.dart @@ -1,8 +1,8 @@ -import '../../ui/theme/app_theme.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'settings_keys.dart'; +import 'settings_row.dart'; import 'settings_theme.dart'; /// The Settings entry to the saved-schedule list. @@ -13,37 +13,23 @@ const String settingsSchedulesLabel = 'Browse schedules'; const String settingsSchedulesSecondary = 'Saved run configurations for every pipeline.'; +/// A navigation row (chevron) for a Settings group. class SettingsSchedulesSection extends StatelessWidget { const SettingsSchedulesSection({super.key, required this.onOpen}); final VoidCallback onOpen; @override - Widget build(BuildContext context) { - if (usesCupertinoControls(context)) { - return CupertinoListSection.insetGrouped( - backgroundColor: AppColors.groupedBackground, - margin: EdgeInsets.zero, - children: [ - CupertinoListTile( - key: SettingsKeys.schedules, - title: const Text(settingsSchedulesLabel), - subtitle: const Text(settingsSchedulesSecondary), - trailing: const CupertinoListTileChevron(), - onTap: onOpen, - ), - ], - ); - } - return Card( - margin: EdgeInsets.zero, - child: ListTile( - key: SettingsKeys.schedules, - title: const Text(settingsSchedulesLabel), - subtitle: const Text(settingsSchedulesSecondary), - trailing: const Icon(Icons.chevron_right), - onTap: onOpen, - ), - ); - } + Widget build(BuildContext context) => SettingsRow( + key: SettingsKeys.schedules, + leading: Icon( + usesCupertinoControls(context) + ? CupertinoIcons.calendar + : Icons.event_repeat_outlined, + ), + title: const Text(settingsSchedulesLabel), + subtitle: const Text(settingsSchedulesSecondary), + chevron: true, + onTap: onOpen, + ); } diff --git a/app/lib/features/settings/settings_screen.dart b/app/lib/features/settings/settings_screen.dart index 19d2c55c..9497598f 100644 --- a/app/lib/features/settings/settings_screen.dart +++ b/app/lib/features/settings/settings_screen.dart @@ -6,11 +6,11 @@ import 'package:flutter/material.dart'; import '../../core/transport/pipelines_client.dart' as transport; import '../attention/notify/notification_controller.dart'; -import '../attention/notify/notification_models.dart'; import 'default_endpoint.dart'; import 'settings_controller.dart'; import 'settings_controls.dart'; -import 'settings_layout.dart'; +import 'settings_group.dart'; +import 'settings_page_body.dart'; import 'settings_notifications_section.dart'; import 'settings_ntfy_section.dart'; import 'settings_android_download_section.dart'; @@ -24,7 +24,6 @@ import 'settings_templates_section.dart'; import 'server_connections.dart'; import 'saved_servers_section.dart'; import 'managed_connection_section.dart'; -import '../../ui/adaptive/floating_bar_layout.dart'; /// The Settings destination: the server connection and the server-side /// workspace, in native Material (native platforms) or Cupertino (iOS) controls. @@ -133,148 +132,79 @@ class _SettingsScreenState extends State { super.dispose(); } + String get _endpoint => widget.servers == null + ? _controller.serverUrl + : widget.client.endpoint?.toString() ?? ''; + + void _reconnectAfterSignIn() { + final endpoint = widget.client.endpoint; + if (endpoint != null) { + widget.client.connectAny( + widget.client.endpoints.isEmpty ? [endpoint] : widget.client.endpoints, + ); + } + } + @override Widget build(BuildContext context) { - // The content scrolls behind a floating tab bar and pads its end clear of - // it (or of the system inset on its own page). - final content = SafeArea( - bottom: false, - child: SingleChildScrollView( - // Web `.settings` page insets: 20 above the title, 16 at the sides and - // a clear 32 below the last section. - padding: withFloatingBarClearance( - context, - const EdgeInsetsDirectional.fromSTEB( - settingsPageSidePadding, - settingsPageTopPadding, - settingsPageSidePadding, - settingsPageBottomPadding, + final servers = widget.servers; + final content = SettingsPageBody( + children: [ + if (servers != null) ...[ + SavedServersSection(connections: servers), + ManagedConnectionSection( + client: widget.client, + controller: _controller, ), - ), - child: Center( - child: ConstrainedBox( - constraints: const BoxConstraints( - maxWidth: settingsContentMaxWidth, - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - if (widget.servers != null) ...[ - _SettingsSection( - title: 'Servers', - child: SavedServersSection(connections: widget.servers!), - ), - const SizedBox(height: settingsSectionGap), - ], - _SettingsSection( - title: 'Connection', - child: widget.servers != null - ? ManagedConnectionSection( - client: widget.client, - controller: _controller, - ) - : SettingsConnectionSection( - controller: _controller, - serverUrlField: _serverUrlField, - ), - ), - // A phone signs in at the web login; a browser has its own. - if (widget.showSignIn) ...[ - const SizedBox(height: settingsSectionGap), - _SettingsSection( - title: 'Sign in', - child: SettingsSignInSection( - endpoint: widget.servers == null - ? _controller.serverUrl - : widget.client.endpoint?.toString() ?? '', - onChanged: () { - final endpoint = widget.client.endpoint; - if (endpoint != null) { - widget.client.connectAny( - widget.client.endpoints.isEmpty - ? [endpoint] - : widget.client.endpoints, - ); - } - }, - ), - ), - ], - // The web page links the Android app the server offers. - if (widget.showAndroidDownload) ...[ - const SizedBox(height: settingsSectionGap), - const _SettingsSection( - title: 'Android app', - child: SettingsAndroidDownloadSection(), - ), - ], - // A phone installs newer builds from the server. - if (widget.showSignIn && appUpdatesSupported) ...[ - const SizedBox(height: settingsSectionGap), - _SettingsSection( - title: 'App updates', - child: SettingsUpdatesSection( - endpoint: widget.servers == null - ? _controller.serverUrl - : widget.client.endpoint?.toString() ?? '', - ), - ), - ], - const SizedBox(height: settingsSectionGap), - _SettingsSection( - title: 'Workspace', - child: SettingsWorkspaceSection( - controller: _controller, - workspaceField: _workspaceField, - ), - ), - if (widget.notifications != null) ...[ - const SizedBox(height: settingsSectionGap), - _SettingsSection( - title: notificationSectionTitle, - child: SettingsNotificationsSection( - controller: widget.notifications!, - ), - ), - ], - // The server's ntfy choices, beside the in-app permission. - const SizedBox(height: settingsSectionGap), - _SettingsSection( - title: ntfySectionTitle, - child: SettingsNtfySection( - gateway: widget.client, - connected: - widget.client.state.kind == - transport.ConnectionKind.connected, - ), - ), - if (widget.onOpenSchedules != null) ...[ - const SizedBox(height: settingsSectionGap), - _SettingsSection( - title: 'Schedules', - child: SettingsSchedulesSection( - onOpen: widget.onOpenSchedules!, - ), - ), - ], - if (widget.onOpenTemplates != null) ...[ - const SizedBox(height: settingsSectionGap), - _SettingsSection( - title: 'Templates', - child: SettingsTemplatesSection( - onOpen: widget.onOpenTemplates!, - ), - ), - ], - ], + ] else + SettingsConnectionSection( + controller: _controller, + serverUrlField: _serverUrlField, + ), + // A phone signs in at the web login; a browser has its own. + if (widget.showSignIn) + _single( + 'Sign in', + SettingsSignInSection( + endpoint: _endpoint, + onChanged: _reconnectAfterSignIn, ), ), + // The web page links the Android app the server offers. + if (widget.showAndroidDownload) + _single('Android app', const SettingsAndroidDownloadSection()), + // A phone installs newer builds from the server. + if (widget.showSignIn && appUpdatesSupported) + _single('App updates', SettingsUpdatesSection(endpoint: _endpoint)), + SettingsWorkspaceSection( + controller: _controller, + workspaceField: _workspaceField, ), - ), + if (widget.notifications case final notifications?) + SettingsNotificationsSection(controller: notifications), + // The server's ntfy choices, beside the in-app permission. + SettingsNtfySection( + gateway: widget.client, + connected: + widget.client.state.kind == transport.ConnectionKind.connected, + ), + if (widget.onOpenSchedules != null || widget.onOpenTemplates != null) + SettingsGroup( + title: 'Library', + leadingRows: true, + children: [ + if (widget.onOpenSchedules case final open?) + SettingsSchedulesSection(onOpen: open), + if (widget.onOpenTemplates case final open?) + SettingsTemplatesSection(onOpen: open), + ], + ), + ], ); if (widget.embedded) return content; if (usesCupertinoControls(context)) { return CupertinoPageScaffold( + backgroundColor: settingsCupertinoBackground, navigationBar: const SegmentedBar(cupertino: true, title: 'Settings'), child: content, ); @@ -285,29 +215,10 @@ class _SettingsScreenState extends State { body: content, ); } -} - -/// One grouped Settings section: a compact title followed by its body at the -/// web's 8px title gap. Sections are separated by [settingsSectionGap]. A null -/// title lets a body (the notification tile) draw its own compact heading. -class _SettingsSection extends StatelessWidget { - const _SettingsSection({required this.child, this.title}); - - final String? title; - final Widget child; - - @override - Widget build(BuildContext context) { - final title = this.title; - return Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - if (title != null) ...[ - Text(title, style: settingsTextStyle(context, title: true)), - const SizedBox(height: settingsTitleGap), - ], - child, - ], - ); - } + + /// A group holding one free-form block (a form, a status with buttons). + Widget _single(String title, Widget child) => SettingsGroup( + title: title, + children: [SettingsGroupItem(child: child)], + ); } diff --git a/app/lib/features/settings/settings_sections.dart b/app/lib/features/settings/settings_sections.dart index b80b729c..ccf038df 100644 --- a/app/lib/features/settings/settings_sections.dart +++ b/app/lib/features/settings/settings_sections.dart @@ -3,16 +3,20 @@ 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_group.dart'; import 'settings_keys.dart'; -import 'settings_trust_warning.dart'; import 'settings_layout.dart'; +import 'settings_status_row.dart'; +import 'settings_trust_warning.dart'; -/// Connection controls: the editable endpoint, the truthful connection card and -/// the trusted-network warning. Every action goes through the shared client the +export 'settings_status_row.dart'; + +/// Connection controls for a single endpoint: the editable URL with Connect / +/// Disconnect, the connection's status row and the trusted-network warning as +/// the group's footer. Every action goes through the shared client the /// controller was given; nothing here opens a second connection. class SettingsConnectionSection extends StatelessWidget { const SettingsConnectionSection({ @@ -26,133 +30,89 @@ class SettingsConnectionSection extends StatelessWidget { @override Widget build(BuildContext context) { - return Column( - crossAxisAlignment: CrossAxisAlignment.stretch, + final errors = [ + if (controller.endpointSaveError.isNotEmpty) controller.endpointSaveError, + if (controller.actionError.isNotEmpty) controller.actionError, + ]; + return SettingsGroup( + title: 'Connection', + footer: settingsConnectionFooter(controller), children: [ - 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(), + SettingsGroupItem( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + 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(), + ), + ), + for (final error in errors) ...[ + const SizedBox(height: settingsFieldGap), + Text(error, style: settingsTextStyle(context, error: true)), + ], + ], ), ), - if (controller.endpointSaveError.isNotEmpty) ...[ - const SizedBox(height: settingsFieldGap), - Text( - controller.endpointSaveError, - style: settingsTextStyle(context, error: true), - ), - ], - if (controller.actionError.isNotEmpty) ...[ - 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?) ...[ - 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), - ), - ), - ], + SettingsStatusRow(controller: controller), ], ); } } -/// 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 []; - 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: [ - if (state.kind == transport.ConnectionKind.connecting) - Row( - children: [ - if (usesCupertinoControls(context)) - const CupertinoActivityIndicator() - else - const CircularProgressIndicator(strokeWidth: 2), - const SizedBox(width: settingsControlGap), - Expanded(child: titleWidget), - ], - ) - else - titleWidget, - for (final line in details) ...[ - const SizedBox(height: settingsFieldGap), - Text(line, style: settingsTextStyle(context, secondary: true)), - ], - ], +/// The Connection group's footer: the trust warning, then a protocol +/// mismatch when the server reports one. +Widget settingsConnectionFooter(SettingsController controller) => Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + const SettingsTrustWarning(), + if (controller.protocolWarning case final warning?) + Builder( + // A live region announces a mismatch the operator did not ask to + // reveal. + builder: (context) => Padding( + padding: const EdgeInsets.only(top: settingsTitleGap), + child: Semantics( + liveRegion: true, + child: Text( + warning, + style: TextStyle(color: settingsErrorColor(context)), + ), + ), + ), ), - ); - } -} + ], +); /// Workspace controls. The path is resolved by the execution server, and the -/// helper says so explicitly; an empty saved value is named "(none)". +/// helper says so explicitly; an empty saved value is named "(none)". Save +/// stays a legible tonal (Cupertino: plain) button while it is unavailable. class SettingsWorkspaceSection extends StatelessWidget { const SettingsWorkspaceSection({ super.key, @@ -167,46 +127,55 @@ class SettingsWorkspaceSection extends StatelessWidget { Widget build(BuildContext context) { final saveError = controller.workspaceSaveError; final canSave = canSaveWorkspace(controller.workspaceDraft); - return Column( - crossAxisAlignment: CrossAxisAlignment.stretch, + final save = canSave ? () => unawaited(controller.saveWorkspace()) : null; + return SettingsGroup( + title: 'Workspace', children: [ - SettingsTextField( - controller: workspaceField, - key: SettingsKeys.workspace, - label: 'Workspace path (on the server)', - placeholder: workspacePlaceholder, - helper: workspaceHelper, - error: controller.workspaceError, - onChanged: controller.updateWorkspace, + SettingsGroupItem( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + 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), + Wrap( + spacing: settingsControlGap, + runSpacing: settingsFieldGap, + crossAxisAlignment: WrapCrossAlignment.center, + children: [ + if (usesCupertinoControls(context)) + CupertinoButton( + key: SettingsKeys.saveWorkspace, + padding: EdgeInsets.zero, + onPressed: save, + child: const Text('Save workspace'), + ) + else + FilledButton.tonal( + key: SettingsKeys.saveWorkspace, + onPressed: save, + child: const Text('Save workspace'), + ), + Text( + savedWorkspaceLine(controller.savedWorkspace), + style: settingsTextStyle(context, secondary: true), + ), + ], + ), + if (saveError.isNotEmpty) ...[ + const SizedBox(height: settingsFieldGap), + Text(saveError, style: settingsTextStyle(context, error: true)), + ], + ], + ), ), - 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) ...[ - const SizedBox(height: settingsFieldGap), - Text(saveError, style: settingsTextStyle(context, error: true)), - ], ], ); } diff --git a/app/lib/features/settings/settings_status_row.dart b/app/lib/features/settings/settings_status_row.dart new file mode 100644 index 00000000..8860ab2c --- /dev/null +++ b/app/lib/features/settings/settings_status_row.dart @@ -0,0 +1,66 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../../core/transport/pipelines_client.dart' as transport; +import 'settings_controller.dart'; +import 'settings_row.dart'; +import 'settings_theme.dart'; + +/// The connection's state as one row: a status icon, the state as the title +/// and the build/time/reason/backoff facts as its subtitle lines. Missing ping +/// values stay explicit. +class SettingsStatusRow extends StatelessWidget { + const SettingsStatusRow({super.key, required this.controller}); + + final SettingsController controller; + + @override + Widget build(BuildContext context) { + final cupertino = usesCupertinoControls(context); + final state = controller.connection; + final lines = controller.connectionLines; + final title = lines.isEmpty ? '' : lines.first; + final details = lines.length > 1 ? lines.sublist(1) : const []; + final connectedColor = cupertino + ? CupertinoColors.systemGreen.resolveFrom(context) + : Theme.of(context).colorScheme.primary; + final Color? color = switch (state.kind) { + transport.ConnectionKind.connected => connectedColor, + transport.ConnectionKind.disconnected => settingsErrorColor(context), + _ => null, + }; + final Widget leading = switch (state.kind) { + transport.ConnectionKind.connecting => + cupertino + ? const CupertinoActivityIndicator() + : const SizedBox.square( + dimension: 20, + child: CircularProgressIndicator(strokeWidth: 2), + ), + transport.ConnectionKind.connected => Icon( + cupertino ? CupertinoIcons.checkmark_circle_fill : Icons.check_circle, + color: color, + ), + transport.ConnectionKind.disconnected => Icon( + cupertino ? CupertinoIcons.xmark_circle_fill : Icons.error_outline, + color: color, + ), + transport.ConnectionKind.idle => Icon( + cupertino ? CupertinoIcons.circle : Icons.radio_button_unchecked, + ), + }; + return SettingsRow( + leading: leading, + title: Text( + title, + style: TextStyle(color: color, fontWeight: FontWeight.w600), + ), + subtitle: details.isEmpty + ? null + : Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [for (final line in details) Text(line)], + ), + ); + } +} diff --git a/app/lib/features/settings/settings_templates_section.dart b/app/lib/features/settings/settings_templates_section.dart index 9d1ee0b1..5c8b7398 100644 --- a/app/lib/features/settings/settings_templates_section.dart +++ b/app/lib/features/settings/settings_templates_section.dart @@ -1,52 +1,36 @@ -import '../../ui/theme/app_theme.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'settings_keys.dart'; +import 'settings_row.dart'; import 'settings_theme.dart'; /// The Settings entry to the Templates gallery. /// -/// The row wording matches the current web Settings page: `Browse templates` -/// with the server-catalogue secondary line, under its `Templates` heading. It -/// only opens the route; loading the catalogue is the gallery's own read. +/// The row wording matches the web Settings page: `Browse templates` with the +/// server-catalogue secondary line. It only opens the route; loading the +/// catalogue is the gallery's own read. const String settingsTemplatesLabel = 'Browse templates'; const String settingsTemplatesSecondary = 'Reusable pipeline definitions offered by the server.'; +/// A navigation row (chevron) for a Settings group. class SettingsTemplatesSection extends StatelessWidget { const SettingsTemplatesSection({super.key, required this.onOpen}); final VoidCallback onOpen; @override - Widget build(BuildContext context) { - if (usesCupertinoControls(context)) { - return CupertinoListSection.insetGrouped( - backgroundColor: AppColors.groupedBackground, - margin: EdgeInsets.zero, - children: [ - CupertinoListTile( - key: SettingsKeys.templates, - title: const Text(settingsTemplatesLabel), - subtitle: const Text(settingsTemplatesSecondary), - trailing: const CupertinoListTileChevron(), - onTap: onOpen, - ), - ], - ); - } - return Card( - margin: EdgeInsets.zero, - clipBehavior: Clip.antiAlias, - child: ListTile( - key: SettingsKeys.templates, - leading: const Icon(Icons.widgets_outlined), - title: const Text(settingsTemplatesLabel), - subtitle: const Text(settingsTemplatesSecondary), - trailing: const Icon(Icons.chevron_right), - onTap: onOpen, - ), - ); - } + Widget build(BuildContext context) => SettingsRow( + key: SettingsKeys.templates, + leading: Icon( + usesCupertinoControls(context) + ? CupertinoIcons.square_grid_2x2 + : Icons.widgets_outlined, + ), + title: const Text(settingsTemplatesLabel), + subtitle: const Text(settingsTemplatesSecondary), + chevron: true, + onTap: onOpen, + ); } diff --git a/app/lib/features/settings/settings_trust_warning.dart b/app/lib/features/settings/settings_trust_warning.dart index 9f6fe116..5b759d1b 100644 --- a/app/lib/features/settings/settings_trust_warning.dart +++ b/app/lib/features/settings/settings_trust_warning.dart @@ -1,12 +1,13 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'settings_controls.dart'; import 'settings_copy.dart'; import 'settings_layout.dart'; +import 'settings_theme.dart'; -/// The trusted-network warning, using the app's exact web/Android copy. It is a -/// card, not a dialog: no confirmation is required to read it. +/// The trusted-network warning, shown as the Connection group's footer: a +/// warning icon, the title in the error colour and the short body. It is not a +/// dialog: no confirmation is required to read it. class SettingsTrustWarning extends StatelessWidget { const SettingsTrustWarning({super.key}); @@ -15,30 +16,25 @@ class SettingsTrustWarning extends StatelessWidget { final icon = usesCupertinoControls(context) ? CupertinoIcons.exclamationmark_triangle : Icons.warning_amber_rounded; - return SettingsCard( - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Icon(icon, color: settingsErrorColor(context)), - const SizedBox(width: settingsControlGap), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - trustTitle, - style: settingsTextStyle(context, title: true, error: true), - ), - const SizedBox(height: settingsFieldGap), - Text( - trustBody, - style: settingsTextStyle(context, secondary: true), - ), - ], - ), + final error = settingsErrorColor(context); + return Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Icon(icon, color: error, semanticLabel: 'Warning'), + const SizedBox(width: settingsControlGap), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + trustTitle, + style: TextStyle(color: error, fontWeight: FontWeight.w600), + ), + const Text(trustBody), + ], ), - ], - ), + ), + ], ); } } diff --git a/app/test/features/settings/saved_server_editor_save_test.dart b/app/test/features/settings/saved_server_editor_save_test.dart index d7120f5d..02453f6f 100644 --- a/app/test/features/settings/saved_server_editor_save_test.dart +++ b/app/test/features/settings/saved_server_editor_save_test.dart @@ -8,6 +8,8 @@ import 'package:pipelines_app/core/servers/server_catalog_store.dart'; import 'package:pipelines_app/features/settings/saved_servers_section.dart'; import 'package:pipelines_app/features/settings/server_connections.dart'; +import 'saved_server_menu.dart'; + class _ControlledStore extends MemoryServerCatalogStore { _ControlledStore({super.catalog}); @@ -38,6 +40,7 @@ Future _openEditor( ) : MaterialApp(home: Scaffold(body: body)), ); + if (edit) await openSavedServerMenu(tester); await tester.tap(find.text(edit ? 'Edit Home' : 'Add server')); await tester.pumpAndSettle(); await tester.enterText( diff --git a/app/test/features/settings/saved_server_menu.dart b/app/test/features/settings/saved_server_menu.dart new file mode 100644 index 00000000..d41ff816 --- /dev/null +++ b/app/test/features/settings/saved_server_menu.dart @@ -0,0 +1,15 @@ +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +/// Opens the only saved server's actions menu (Use, Edit, Remove). +Future openSavedServerMenu(WidgetTester tester) async { + await tester.tap( + find.byWidgetPredicate((widget) { + final key = widget.key; + return key is ValueKey && + key.value.startsWith('settings.server.') && + key.value.endsWith('.menu'); + }), + ); + await tester.pumpAndSettle(); +} diff --git a/app/test/features/settings/saved_servers_test.dart b/app/test/features/settings/saved_servers_test.dart index 6ecb689f..c303ea94 100644 --- a/app/test/features/settings/saved_servers_test.dart +++ b/app/test/features/settings/saved_servers_test.dart @@ -6,6 +6,8 @@ import 'package:pipelines_app/core/servers/server_catalog_store.dart'; import 'package:pipelines_app/features/settings/saved_servers_section.dart'; import 'package:pipelines_app/features/settings/server_connections.dart'; +import 'saved_server_menu.dart'; + SavedServer profile(String id, List urls) => SavedServer.validated(id: id, name: id, endpoints: urls); @@ -140,6 +142,7 @@ void main() { find.text('Backup 1: ws://192.168.1.2:8083/connect'), findsOneWidget, ); + await openSavedServerMenu(tester); await tester.tap(find.text('Edit Home')); await tester.pumpAndSettle(); await tester.enterText( diff --git a/app/test/features/settings/settings_layout_test.dart b/app/test/features/settings/settings_layout_test.dart index d2ad241a..958c424d 100644 --- a/app/test/features/settings/settings_layout_test.dart +++ b/app/test/features/settings/settings_layout_test.dart @@ -1,48 +1,110 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/core/servers/server_catalog.dart'; +import 'package:pipelines_app/core/servers/server_catalog_store.dart'; import 'package:pipelines_app/core/transport/pipelines_client.dart' as transport; import 'package:pipelines_app/features/attention/notify/notification_controller.dart'; import 'package:pipelines_app/features/attention/notify/notification_store.dart'; +import 'package:pipelines_app/features/settings/saved_server_row.dart'; +import 'package:pipelines_app/features/settings/saved_servers_section.dart'; +import 'package:pipelines_app/features/settings/server_connections.dart'; +import 'package:pipelines_app/features/settings/settings_group.dart'; import 'package:pipelines_app/features/settings/settings_layout.dart'; import 'package:pipelines_app/features/settings/settings_screen.dart'; import 'package:pipelines_app/features/settings/settings_store.dart'; import 'package:pipelines_app/features/settings/settings_trust_warning.dart'; +import 'package:pipelines_app/ui/theme/app_theme.dart'; import 'fake_channel.dart'; void main() { - testWidgets('sections use one centred column and the web rhythm', ( + testWidgets('groups start at the bar inset and stop at the reading width', ( + tester, + ) async { + await _pump(tester, size: const Size(1200, 1600)); + + final groups = find.byType(SettingsGroup); + expect(groups, findsWidgets); + for (final group in groups.evaluate()) { + final rect = tester.getRect(find.byWidget(group.widget)); + // The column starts where the bar's title pill does, not centred. + expect(rect.left, closeTo(settingsPageSidePadding, 0.01)); + expect(rect.width, closeTo(settingsContentMaxWidth, 0.01)); + } + // A header's text lines up with its rows' text. + final header = tester.getRect(find.text('Connection')); + expect( + header.left, + closeTo(settingsPageSidePadding + settingsRowInset, 0.01), + ); + }); + + testWidgets('Material groups are flat surfaces, not elevated cards', ( tester, ) async { await _pump(tester); - final connection = tester.getRect(find.text('Connection')); - final serverUrlLabel = tester.getRect(find.text('Server URL')); - final warning = tester.getRect(find.byType(SettingsTrustWarning)); - final workspace = tester.getRect(find.text('Workspace')); - - // One column: the 720px reading width is centred in an 800px window. - expect(connection.left, closeTo(40, 0.01)); - expect(connection.right, closeTo(760, 0.01)); - - // The compact title sits 8px above its grouped body, and sections are 16px - // apart, as on the web Settings page. - expect( - serverUrlLabel.top - connection.bottom, - closeTo(settingsTitleGap, 0.01), + expect(find.byType(Card), findsNothing); + final surfaces = tester.widgetList( + find.descendant( + of: find.byType(SettingsGroup), + matching: find.byType(Material), + ), ); - expect(workspace.top - warning.bottom, closeTo(settingsSectionGap, 0.01)); + final scheme = Theme.of( + tester.element(find.byType(SettingsGroup).first), + ).colorScheme; + final groupSurfaces = surfaces.where( + (material) => material.color == scheme.surfaceContainer, + ); + expect(groupSurfaces, isNotEmpty); + for (final material in groupSurfaces) { + expect(material.elevation, 0); + } + // The trust warning is the Connection group's footer, not a card. + expect(find.byType(SettingsTrustWarning), findsOneWidget); + final title = tester.widget(find.text('Connection')); + final theme = Theme.of(tester.element(find.text('Connection'))); + expect(title.style?.color, theme.colorScheme.primary); + }); - // The field label is a compact secondary line, not a second title. - final label = tester.widget(find.text('Server URL')); - final theme = Theme.of(tester.element(find.text('Server URL'))); - expect(label.style?.color, theme.colorScheme.onSurfaceVariant); - expect(label.style?.fontSize, theme.textTheme.labelMedium?.fontSize); + testWidgets('content starts below the bar and scrolls behind it', ( + tester, + ) async { + const barHeight = 72.0; + await _pump(tester, topPadding: barHeight); + + final first = tester.getRect(find.byType(SettingsGroup).first); + expect(first.top, closeTo(barHeight + settingsPageTopPadding, 0.01)); + // No top SafeArea: the scroll view itself reaches the top edge. expect( - label.style?.fontSize, - lessThan(theme.textTheme.titleMedium!.fontSize!), + tester.getRect(find.byKey(const ValueKey('settings.scroll'))).top, + 0, + ); + }); + + testWidgets('Cupertino uses inset-grouped sections on the grouped page', ( + tester, + ) async { + await _pump(tester, platform: TargetPlatform.iOS); + + expect(find.byType(Card), findsNothing); + expect(find.byType(CupertinoListSection), findsWidgets); + for (final section in tester.widgetList( + find.byType(CupertinoListSection), + )) { + expect(section.type, CupertinoListSectionType.insetGrouped); + } + final context = tester.element(find.byType(SettingsGroup).first); + expect( + find.byWidgetPredicate( + (widget) => + widget is ColoredBox && + widget.color == AppColors.groupedBackground.resolveFrom(context), + ), + findsWidgets, ); }); @@ -72,14 +134,69 @@ void main() { ); expect(find.byType(CupertinoTextField), findsNWidgets(2)); }); + + for (final cupertino in [false, true]) { + testWidgets('server rows show which server is selected ($cupertino)', ( + tester, + ) async { + final connections = ServerConnections( + store: MemoryServerCatalogStore( + catalog: ServerCatalog( + servers: [ + SavedServer.validated( + id: 'Home', + name: 'Home', + endpoints: const ['wss://home.test/connect'], + ), + SavedServer.validated( + id: 'Work', + name: 'Work', + endpoints: const ['wss://work.test/connect'], + ), + ], + selectedId: 'Home', + ), + ), + onSelected: (_) async {}, + ); + addTearDown(connections.dispose); + await connections.load(); + final body = SingleChildScrollView( + child: SavedServersSection(connections: connections), + ); + await tester.pumpWidget( + cupertino + ? CupertinoApp(home: CupertinoPageScaffold(child: body)) + : MaterialApp(home: Scaffold(body: body)), + ); + + expect(find.byType(SavedServerRow), findsNWidgets(2)); + expect(find.text('Selected server'), findsOneWidget); + expect( + find.byWidgetPredicate( + (widget) => widget is Icon && widget.semanticLabel == 'Selected', + ), + findsOneWidget, + ); + expect(find.text('Preferred: wss://work.test/connect'), findsOneWidget); + expect(find.byKey(savedServerMenuKey('Home')), findsOneWidget); + expect(find.text('Add server'), findsOneWidget); + // Tapping another server's row uses it. + await tester.tap(find.text('Work')); + await tester.pumpAndSettle(); + expect(connections.catalog.active?.id, 'Work'); + }); + } } Future _pump( WidgetTester tester, { TargetPlatform platform = TargetPlatform.android, NotificationController? notifications, + Size size = const Size(800, 1600), + double topPadding = 0, }) async { - await tester.binding.setSurfaceSize(const Size(800, 1600)); + await tester.binding.setSurfaceSize(size); addTearDown(() => tester.binding.setSurfaceSize(null)); final factory = FakeChannelFactory(); final client = transport.PipelinesClient(channelFactory: factory.call); @@ -87,10 +204,19 @@ Future _pump( await tester.pumpWidget( MaterialApp( theme: ThemeData(platform: platform), - home: SettingsScreen( - client: client, - store: MemorySettingsStore(), - notifications: notifications, + builder: (context, child) => MediaQuery( + data: MediaQuery.of( + context, + ).copyWith(padding: EdgeInsets.only(top: topPadding)), + child: child!, + ), + home: Scaffold( + body: SettingsScreen( + client: client, + store: MemorySettingsStore(), + notifications: notifications, + embedded: true, + ), ), ), ); diff --git a/app/test/features/settings/settings_ntfy_section_test.dart b/app/test/features/settings/settings_ntfy_section_test.dart index f63e967b..fe3b63d1 100644 --- a/app/test/features/settings/settings_ntfy_section_test.dart +++ b/app/test/features/settings/settings_ntfy_section_test.dart @@ -48,10 +48,10 @@ bool _checked(WidgetTester tester, String key, {required bool cupertino}) { final tile = find.byKey(ntfySettingKey(key)); if (cupertino) { return tester - .widget( - find.descendant(of: tile, matching: find.byType(CupertinoCheckbox)), + .widget( + find.descendant(of: tile, matching: find.byType(CupertinoSwitch)), ) - .value!; + .value; } return tester.widget(tile).value!; }