fdc730422d
Phase 2.3 and 2.4 of docs/plans/floating-windows.md. A floating chat is a window of the chat kind over the app's WindowManager, built from the app-lifetime ChatRuntime, so it shows over every destination and at start without the Chat destination being built. Float and Dock move the same keyed view between the tiling and the window host. The pipelines app keeps one runtime and one ChatWindows; saved chatFloat records (v1 and v2) are brought over once. ChatFloatHost, ChatFloatWindow, the float frames and binding, the controller's float list and FloatingFocusRoot are gone; the workspace only asks whether a chat is out in a window. Every MenuAnchor targets the root overlay (guarded by a test), and menus and tooltips name the Alt chords.
160 lines
5.0 KiB
Dart
160 lines
5.0 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/adaptive/host.dart';
|
|
import 'discovered_server.dart';
|
|
|
|
/// One discovered machine. A machine with one route is used by tapping it. A
|
|
/// machine with several routes (LAN, Tailscale IP, Tailscale name) expands to
|
|
/// a checklist so the operator chooses which of them to save; the first
|
|
/// checked route is dialled first and the rest are backups to the same machine.
|
|
class DiscoveredServerRow extends StatefulWidget {
|
|
const DiscoveredServerRow({
|
|
super.key,
|
|
required this.server,
|
|
required this.onSelect,
|
|
this.enabled = true,
|
|
});
|
|
|
|
final DiscoveredServer server;
|
|
final ValueChanged<DiscoveredServer> onSelect;
|
|
final bool enabled;
|
|
|
|
@override
|
|
State<DiscoveredServerRow> createState() => _DiscoveredServerRowState();
|
|
}
|
|
|
|
class _DiscoveredServerRowState extends State<DiscoveredServerRow> {
|
|
bool _expanded = false;
|
|
late final Set<DiscoveredAddress> _chosen = {widget.server.addresses.first};
|
|
|
|
bool get _multiple => widget.server.addresses.length > 1;
|
|
|
|
void _tap() {
|
|
if (!_multiple) {
|
|
widget.onSelect(widget.server);
|
|
return;
|
|
}
|
|
setState(() => _expanded = !_expanded);
|
|
}
|
|
|
|
void _use() {
|
|
final ordered = [
|
|
for (final address in widget.server.addresses)
|
|
if (_chosen.contains(address)) address,
|
|
];
|
|
widget.onSelect(widget.server.choosing(ordered));
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cupertino = usesCupertinoHost(context);
|
|
final server = widget.server;
|
|
final detail = _multiple
|
|
? '${server.addresses.length} addresses'
|
|
: server.address;
|
|
final subtitle = Text(
|
|
server.passwordRequired ? '$detail · password' : detail,
|
|
);
|
|
final onTap = widget.enabled ? _tap : null;
|
|
final Widget head = cupertino
|
|
? CupertinoListTile(
|
|
key: Key('discovered-${server.address}'),
|
|
leading: const Icon(CupertinoIcons.desktopcomputer),
|
|
title: Text(server.name),
|
|
subtitle: subtitle,
|
|
trailing: _multiple
|
|
? Icon(
|
|
_expanded
|
|
? CupertinoIcons.chevron_up
|
|
: CupertinoIcons.chevron_down,
|
|
)
|
|
: const CupertinoListTileChevron(),
|
|
onTap: onTap,
|
|
)
|
|
: ListTile(
|
|
key: Key('discovered-${server.address}'),
|
|
leading: const Icon(Icons.dns_outlined),
|
|
title: Text(server.name),
|
|
subtitle: subtitle,
|
|
trailing: Icon(
|
|
_multiple
|
|
? (_expanded ? Icons.expand_less : Icons.expand_more)
|
|
: Icons.chevron_right,
|
|
),
|
|
enabled: widget.enabled,
|
|
onTap: onTap,
|
|
);
|
|
if (!_multiple || !_expanded) return head;
|
|
final useLabel = 'Use ${server.name}';
|
|
final use = cupertino
|
|
? CupertinoButton.filled(
|
|
key: Key('discovered-use-${server.address}'),
|
|
onPressed: widget.enabled && _chosen.isNotEmpty ? _use : null,
|
|
child: Text(useLabel),
|
|
)
|
|
: FilledButton(
|
|
key: Key('discovered-use-${server.address}'),
|
|
onPressed: widget.enabled && _chosen.isNotEmpty ? _use : null,
|
|
child: Text(useLabel),
|
|
);
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
head,
|
|
Padding(
|
|
padding: const EdgeInsetsDirectional.only(start: 16, end: 16),
|
|
child: Text(
|
|
'Choose how to reach ${server.name}. Checked addresses are saved '
|
|
'as routes to this one machine; the first is tried first.',
|
|
),
|
|
),
|
|
for (final address in server.addresses)
|
|
_choice(context, cupertino, address),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
child: Align(alignment: AlignmentDirectional.centerStart, child: use),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _choice(
|
|
BuildContext context,
|
|
bool cupertino,
|
|
DiscoveredAddress address,
|
|
) {
|
|
final checked = _chosen.contains(address);
|
|
void toggle(bool? value) => setState(() {
|
|
if (value ?? false) {
|
|
_chosen.add(address);
|
|
} else {
|
|
_chosen.remove(address);
|
|
}
|
|
});
|
|
final key = Key('discovered-route-${address.endpoint}');
|
|
final title = Text(address.label);
|
|
final subtitle = Text(address.endpoint.toString());
|
|
if (cupertino) {
|
|
return CupertinoListTile(
|
|
key: key,
|
|
title: title,
|
|
subtitle: subtitle,
|
|
trailing: CupertinoCheckbox(
|
|
value: checked,
|
|
onChanged: widget.enabled ? toggle : null,
|
|
),
|
|
onTap: widget.enabled ? () => toggle(!checked) : null,
|
|
);
|
|
}
|
|
return CheckboxListTile(
|
|
key: key,
|
|
value: checked,
|
|
onChanged: widget.enabled ? toggle : null,
|
|
title: title,
|
|
subtitle: subtitle,
|
|
controlAffinity: ListTileControlAffinity.leading,
|
|
);
|
|
}
|
|
}
|