079924d19a
- Removing the primary machine hands pipelines/runs to the next saved machine on native hosts; removing the last machine returns to the connect screen instead of stranding the app on "Server endpoint not configured". - Add server probes the new machine and asks for its own password in the same page; Settings rows show Connected / Sign in required / Unreachable with the reason and offer Sign in; no other machine's credential is ever reused. - Unreachable addresses explain why: a TLS failure against an IP points at the Tailscale name, a non-Pipelines answer points at the port. - Discovered machines list every advertised route (LAN, Tailscale IP, Tailscale name) as a checklist; chosen routes are saved as one machine. - tool/connection_probe.dart replays the native login and websocket against real addresses for diagnosis.
212 lines
6.1 KiB
Dart
212 lines
6.1 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]),
|
|
],
|
|
);
|
|
}
|
|
}
|