feat(app): configure and safely switch multi-address servers
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
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_sections.dart';
|
||||
import 'settings_trust_warning.dart';
|
||||
|
||||
/// Status follows the actual attempted address, not just the preferred URL.
|
||||
class ManagedConnectionSection extends StatelessWidget {
|
||||
const ManagedConnectionSection({
|
||||
super.key,
|
||||
required this.client,
|
||||
required this.controller,
|
||||
});
|
||||
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)),
|
||||
),
|
||||
_action(context, 'Disconnect', () => unawaited(client.disconnect())),
|
||||
],
|
||||
),
|
||||
SettingsStatusCard(controller: controller),
|
||||
const SizedBox(height: 12),
|
||||
const SettingsTrustWarning(),
|
||||
if (controller.protocolWarning case final warning?) Text(warning),
|
||||
],
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user