6367cce68a
An assistant reply gets Read aloud beside Copy; while it reads it becomes Pause/Resume and Stop, one reply at a time app-wide. The spoken word is highlighted in the rendered reply (across multi-part replies) and the transcript scrolls only when that word leaves the viewport. Reading stops when its chat closes or is swapped, another reply starts, or the app goes to the background. Markdown is spoken as sentences; code blocks are announced as "Code block.". Speech goes through a SpeechEngine seam with a flutter_tts implementation (Android, macOS, web; hidden on Linux) and a fake for tests. Settings has a Read aloud section: a voice picker grouped by language (device language first, a sample per voice), a rate slider and reset, saved per device. flutter_tts has no Swift package, so macOS/iOS gain the CocoaPods integration (Podfiles with the Runner deployment targets); Android declares the TTS_SERVICE query. The capture fixture gains ?speech=fake.
212 lines
7.4 KiB
Dart
212 lines
7.4 KiB
Dart
import '../terminal/terminal_layout.dart';
|
|
import 'settings_terminal_section.dart';
|
|
import '../../ui/adaptive/segmented_bar.dart';
|
|
import 'dart:async';
|
|
import 'package:flutter/foundation.dart' show kIsWeb;
|
|
|
|
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_font_section.dart';
|
|
import 'settings_animation_section.dart';
|
|
import 'settings_scale_section.dart';
|
|
import '../../ui/motion/animation_speed.dart';
|
|
import '../../ui/theme/app_font_controller.dart';
|
|
import 'settings_group.dart';
|
|
import 'storage/settings_storage_section.dart';
|
|
import 'health/settings_health_section.dart';
|
|
import 'settings_search_page.dart';
|
|
import 'settings_section.dart';
|
|
import 'settings_notifications_section.dart';
|
|
import 'settings_ntfy_section.dart';
|
|
import 'settings_device_delivery_section.dart';
|
|
import '../notification_service/notification_service_bridge.dart';
|
|
import '../notification_service/notification_service_controller.dart';
|
|
import 'settings_android_download_section.dart';
|
|
import 'settings_schedules_section.dart';
|
|
import 'settings_sections.dart';
|
|
import 'settings_sign_in_section.dart';
|
|
import 'security/settings_security_section.dart';
|
|
import 'settings_updates_section.dart';
|
|
import '../updates/app_updates.dart';
|
|
import 'settings_store.dart';
|
|
import 'server_connections.dart';
|
|
import 'saved_servers_section.dart';
|
|
import 'managed_connection_section.dart';
|
|
import 'settings_keyboard_shortcuts_section.dart';
|
|
import 'settings_keys.dart';
|
|
import 'settings_row.dart';
|
|
import 'settings_read_aloud_section.dart';
|
|
import '../chat/speech/speech_controller.dart';
|
|
|
|
part 'settings_page_sections.dart';
|
|
|
|
/// The Settings destination: one searchable page of grouped Material sections.
|
|
///
|
|
/// Local settings render at once. Server-backed sections load lazily (see
|
|
/// [SettingsSearchPage]) and never block the page.
|
|
///
|
|
/// The shared [transport.PipelinesClient] is supplied by the shell. This screen
|
|
/// subscribes to it, connects/disconnects it and pings it on connected, but it
|
|
/// never opens a connection on its own and never disposes the client. One
|
|
/// controller is created in [initState], so rebuilding the screen cannot start
|
|
/// a second connection.
|
|
class SettingsScreen extends StatefulWidget {
|
|
const SettingsScreen({
|
|
super.key,
|
|
required this.client,
|
|
this.initialEndpoint,
|
|
this.store,
|
|
this.ping,
|
|
this.embedded = false,
|
|
this.onOpenSchedules,
|
|
this.notifications,
|
|
this.showSignIn = false,
|
|
this.showAndroidDownload = false,
|
|
this.servers,
|
|
this.deliveryService,
|
|
this.deliveryServiceController,
|
|
this.fonts,
|
|
this.animationSpeed,
|
|
this.terminalLayout,
|
|
this.onShowWalkthrough,
|
|
});
|
|
|
|
/// Opens the first-run walkthrough from the Help and about group. Null
|
|
/// leaves the row present but disabled.
|
|
final VoidCallback? onShowWalkthrough;
|
|
|
|
/// The device's interface font; defaults to the app's shared controller.
|
|
final AppFontController? fonts;
|
|
final AnimationSpeedController? animationSpeed;
|
|
|
|
/// The terminal surface's layout (its mode is chosen here); null is the
|
|
/// device's own.
|
|
final TerminalLayout? terminalLayout;
|
|
|
|
/// Android background delivery; hidden when absent or unsupported.
|
|
final NotificationServiceBridge? deliveryService;
|
|
final NotificationServiceController? deliveryServiceController;
|
|
|
|
final transport.PipelinesClient client;
|
|
|
|
/// Whether to offer the web sign-in (the native app; a browser has its own).
|
|
final bool showSignIn;
|
|
|
|
/// A browser page links the Android app the server offers.
|
|
final bool showAndroidDownload;
|
|
final ServerConnections? servers;
|
|
|
|
/// A fixture/preview seed for the URL field. Persisted settings still load;
|
|
/// this value takes precedence for the draft and is never written by itself.
|
|
final Uri? initialEndpoint;
|
|
|
|
/// The feature's own persistence. Defaults to the `pipelines.next` keys.
|
|
final SettingsStore? store;
|
|
|
|
/// Test seam for the exact ping request. Production uses `client.call('ping')`.
|
|
final PingCallback? ping;
|
|
|
|
/// The application shell already owns the native navigation bar and safe area.
|
|
final bool embedded;
|
|
|
|
/// Opens the saved-schedule list above Settings.
|
|
final VoidCallback? onOpenSchedules;
|
|
|
|
/// The app-level notification capability; absent in connection-only fixtures.
|
|
final NotificationController? notifications;
|
|
|
|
@override
|
|
State<SettingsScreen> createState() => _SettingsScreenState();
|
|
}
|
|
|
|
class _SettingsScreenState extends State<SettingsScreen> {
|
|
final TextEditingController _serverUrlField = TextEditingController();
|
|
final TextEditingController _workspaceField = TextEditingController();
|
|
late final SettingsController _controller;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = SettingsController(
|
|
client: widget.client,
|
|
store: widget.store ?? const SharedPreferencesSettingsStore(),
|
|
initialEndpoint: widget.initialEndpoint,
|
|
defaultEndpoint: defaultServerUrl(),
|
|
ping: widget.ping,
|
|
);
|
|
_controller.addListener(_onSettingsChanged);
|
|
unawaited(_controller.initialize());
|
|
}
|
|
|
|
void _onSettingsChanged() {
|
|
if (!mounted) return;
|
|
_syncField(_serverUrlField, _controller.serverUrl);
|
|
_syncField(_workspaceField, _controller.workspaceDraft);
|
|
setState(() {});
|
|
}
|
|
|
|
/// Follow the controller's value (a restored value or the normalised URL)
|
|
/// without disturbing a field the operator is already typing in.
|
|
void _syncField(TextEditingController field, String value) {
|
|
if (field.text == value) return;
|
|
field.value = TextEditingValue(
|
|
text: value,
|
|
selection: TextSelection.collapsed(offset: value.length),
|
|
);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.removeListener(_onSettingsChanged);
|
|
_controller.dispose();
|
|
_serverUrlField.dispose();
|
|
_workspaceField.dispose();
|
|
// The shared client is owned by the shell and deliberately outlives this
|
|
// screen, so it is not disposed here.
|
|
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) {
|
|
final page = SettingsSearchPage(sections: _pageSections());
|
|
if (widget.embedded) {
|
|
// The shell's floating tab bar sits over this body, and the body reads
|
|
// the bar's height as its bottom padding. The page's rows are controls
|
|
// and text, so they stop at the bar's top edge instead of scrolling
|
|
// under the glass where they cannot be read. The reserved space is
|
|
// removed from the page's own inset so it is not counted twice.
|
|
return Padding(
|
|
padding: EdgeInsets.only(bottom: MediaQuery.paddingOf(context).bottom),
|
|
child: MediaQuery.removePadding(
|
|
context: context,
|
|
removeBottom: true,
|
|
child: SafeArea(bottom: false, child: page),
|
|
),
|
|
);
|
|
}
|
|
return Scaffold(
|
|
extendBodyBehindAppBar: true,
|
|
appBar: const SegmentedBar(title: 'Settings'),
|
|
body: SafeArea(bottom: false, child: page),
|
|
);
|
|
}
|
|
}
|