Files
pipelines/app/lib/features/settings/saved_server_sign_in_step.dart
T
alan fdc730422d Host floating chats on the shell window system
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.
2026-11-10 21:17:40 +00:00

214 lines
6.2 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../core/servers/machine_access.dart';
import '../../core/servers/server_catalog.dart';
import '../../ui/adaptive/host.dart';
/// What the editor does once a machine is saved: ask it whether this device
/// may use it, then either sign in with its own password or explain why it
/// could not be reached. The machine stays saved whatever happens here.
class SavedServerSignInStep extends StatefulWidget {
const SavedServerSignInStep({
super.key,
required this.server,
required this.authenticator,
required this.onDone,
});
final SavedServer server;
final MachineAuthenticator authenticator;
final VoidCallback onDone;
@override
State<SavedServerSignInStep> createState() => _SavedServerSignInStepState();
}
class _SavedServerSignInStepState extends State<SavedServerSignInStep> {
final _password = TextEditingController();
MachineAccessResult? _result;
bool _busy = true;
String? _error;
@override
void initState() {
super.initState();
_probe();
}
@override
void dispose() {
_password.dispose();
super.dispose();
}
Future<void> _probe() async {
setState(() {
_busy = true;
_error = null;
});
MachineAccessResult result;
try {
result = await widget.authenticator.probe(widget.server);
} catch (error) {
result = MachineAccessResult(MachineAccess.unreachable, detail: '$error');
}
if (!mounted) return;
if (result.connected) {
widget.onDone();
return;
}
setState(() {
_result = result;
_busy = false;
});
}
Future<void> _signIn() async {
if (_password.text.isEmpty) return;
setState(() {
_busy = true;
_error = null;
});
String? problem;
try {
problem = await widget.authenticator.authenticate(
widget.server,
_password.text,
);
} catch (error) {
problem = 'Could not sign in: $error';
}
if (!mounted) return;
if (problem == null) {
widget.onDone();
return;
}
setState(() {
_busy = false;
_error = problem;
});
}
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final name = widget.server.name;
final errorColor = cupertino
? CupertinoColors.systemRed.resolveFrom(context)
: Theme.of(context).colorScheme.error;
final result = _result;
if (result == null) {
return Row(
children: [
cupertino
? const CupertinoActivityIndicator()
: const SizedBox.square(
dimension: 16,
child: CircularProgressIndicator(strokeWidth: 2),
),
const SizedBox(width: 12),
Expanded(
child: Text('Saved. Checking whether $name needs a sign-in…'),
),
],
);
}
final later = cupertino
? CupertinoButton(
key: const Key('server-sign-in-later'),
onPressed: _busy ? null : widget.onDone,
child: const Text('Later'),
)
: TextButton(
key: const Key('server-sign-in-later'),
onPressed: _busy ? null : widget.onDone,
child: const Text('Later'),
);
if (result.needsPassword) {
final field = cupertino
? CupertinoTextField(
key: const Key('server-profile-password'),
controller: _password,
obscureText: true,
autofocus: true,
enabled: !_busy,
placeholder: 'Password',
onSubmitted: (_) => _signIn(),
)
: TextField(
key: const Key('server-profile-password'),
controller: _password,
obscureText: true,
autofocus: true,
enabled: !_busy,
decoration: const InputDecoration(
labelText: 'Password',
border: OutlineInputBorder(),
),
onSubmitted: (_) => _signIn(),
);
final signIn = cupertino
? CupertinoButton.filled(
key: const Key('server-profile-sign-in'),
onPressed: _busy ? null : _signIn,
child: Text(_busy ? 'Signing in…' : 'Sign in'),
)
: FilledButton(
key: const Key('server-profile-sign-in'),
onPressed: _busy ? null : _signIn,
child: Text(_busy ? 'Signing in…' : 'Sign in'),
);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
'$name is saved and asks for its own password: the one chosen '
'when Pipelines was installed there. Other machines\' sign-ins '
'are never reused.',
),
const SizedBox(height: 12),
field,
if (_error != null) ...[
const SizedBox(height: 8),
Text(
_error!,
key: const Key('server-profile-error'),
style: TextStyle(color: errorColor),
),
],
const SizedBox(height: 16),
Row(children: [signIn, const SizedBox(width: 8), later]),
],
);
}
final retry = cupertino
? CupertinoButton.filled(
key: const Key('server-profile-retry'),
onPressed: _busy ? null : _probe,
child: const Text('Try again'),
)
: FilledButton(
key: const Key('server-profile-retry'),
onPressed: _busy ? null : _probe,
child: const Text('Try again'),
);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text('$name is saved, but could not be reached.'),
if (result.detail != null && result.detail!.isNotEmpty) ...[
const SizedBox(height: 8),
Text(
result.detail!,
key: const Key('server-profile-error'),
style: TextStyle(color: errorColor),
),
],
const SizedBox(height: 16),
Row(children: [retry, const SizedBox(width: 8), later]),
],
);
}
}