feat(app): wire the native pipelines browser on the shared session
Register the landed PipelinesScreen at /pipelines through AppSession, with an honest first-connection gate, a native reconnect banner that retains the open list and detail, and an in-place refresh on reconnect. Move the shared connection chrome out of RunsDestination so both destinations use one implementation and one wording. Add destination, registration and reconnect coverage plus an isolated loopback Chrome probe that drives the real runPipelinesApp() composition.
This commit is contained in:
@@ -0,0 +1,195 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../core/transport/connection_state.dart';
|
||||
import 'app_session.dart';
|
||||
import 'server_endpoint.dart';
|
||||
|
||||
/// The full connection screen shown before a destination has ever loaded.
|
||||
///
|
||||
/// A missing native endpoint is a configuration state, not a server failure,
|
||||
/// so it is explained without opening a socket. Otherwise the screen reports
|
||||
/// connecting, then an honest unavailable state with a native Retry action.
|
||||
class ConnectionGate extends StatelessWidget {
|
||||
const ConnectionGate({
|
||||
super.key,
|
||||
required this.session,
|
||||
required this.server,
|
||||
required this.cupertino,
|
||||
});
|
||||
|
||||
final AppSession session;
|
||||
final ServerEndpoint server;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final state = session.connection;
|
||||
if (server.requiresConfiguration) {
|
||||
return _status(
|
||||
context,
|
||||
title: 'Server endpoint not configured',
|
||||
detail:
|
||||
'Build the native app with an explicit Pipelines endpoint, for '
|
||||
'example --dart-define=PIPELINES_SERVER_URL=ws://host:port/connect.',
|
||||
);
|
||||
}
|
||||
if (server.error != null) {
|
||||
return _status(context, title: server.error!, detail: '');
|
||||
}
|
||||
// Only the very first attempt is "connecting". A failed attempt keeps the
|
||||
// same honest unavailable state while the client retries behind it, so the
|
||||
// screen no longer flickers between unavailable and connecting.
|
||||
if (state.kind == ConnectionKind.connecting && state.attempt <= 1) {
|
||||
return _status(
|
||||
context,
|
||||
title: 'Connecting to Pipelines…',
|
||||
detail: '',
|
||||
progress: true,
|
||||
);
|
||||
}
|
||||
return _status(
|
||||
context,
|
||||
title: 'Pipelines server unavailable',
|
||||
detail: state.retrying
|
||||
? 'Retrying automatically. Check that the Pipelines server is running.'
|
||||
: 'Check that the Pipelines server is running, then try again.',
|
||||
onRetry: session.retry,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _status(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
required String detail,
|
||||
bool progress = false,
|
||||
VoidCallback? onRetry,
|
||||
}) {
|
||||
final theme = Theme.of(context);
|
||||
return Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (progress)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: cupertino
|
||||
? const CupertinoActivityIndicator()
|
||||
: const CircularProgressIndicator(),
|
||||
),
|
||||
Semantics(
|
||||
liveRegion: true,
|
||||
child: Text(
|
||||
title,
|
||||
textAlign: TextAlign.center,
|
||||
style: cupertino
|
||||
? CupertinoTheme.of(context).textTheme.navTitleTextStyle
|
||||
: theme.textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
if (detail.isNotEmpty) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
detail,
|
||||
textAlign: TextAlign.center,
|
||||
style: cupertino ? null : theme.textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
if (onRetry != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
if (cupertino)
|
||||
CupertinoButton(onPressed: onRetry, child: const Text('Retry'))
|
||||
else
|
||||
FilledButton(onPressed: onRetry, child: const Text('Retry')),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A compact status bar above retained content after the first connection.
|
||||
class ConnectionBanner extends StatelessWidget {
|
||||
const ConnectionBanner({
|
||||
super.key,
|
||||
required this.session,
|
||||
required this.cupertino,
|
||||
});
|
||||
|
||||
final AppSession session;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final state = session.connection;
|
||||
final refused = session.subscription == RunSubscriptionState.refused;
|
||||
final reconnecting =
|
||||
!session.connected &&
|
||||
(state.kind == ConnectionKind.connecting || state.retrying);
|
||||
final String title;
|
||||
final String detail;
|
||||
final VoidCallback onRetry;
|
||||
if (session.connected && refused) {
|
||||
title = 'Not live — run updates are unavailable.';
|
||||
detail = session.subscriptionError;
|
||||
onRetry = session.resubscribe;
|
||||
} else if (reconnecting) {
|
||||
title = 'Reconnecting to Pipelines…';
|
||||
detail = '';
|
||||
onRetry = session.retry;
|
||||
} else {
|
||||
title = 'Not live — Pipelines server unavailable.';
|
||||
detail = 'Check that the Pipelines server is running.';
|
||||
onRetry = session.retry;
|
||||
}
|
||||
final textStyle = cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodyMedium;
|
||||
return ColoredBox(
|
||||
color: cupertino
|
||||
? CupertinoDynamicColor.resolve(CupertinoColors.systemGrey5, context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
if (reconnecting) ...[
|
||||
cupertino
|
||||
? const CupertinoActivityIndicator(radius: 7)
|
||||
: const SizedBox(
|
||||
width: 14,
|
||||
height: 14,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
],
|
||||
Expanded(
|
||||
child: Semantics(
|
||||
liveRegion: true,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title, style: textStyle),
|
||||
if (detail.isNotEmpty) Text(detail, style: textStyle),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
if (cupertino)
|
||||
CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: onRetry,
|
||||
child: const Text('Retry'),
|
||||
)
|
||||
else
|
||||
TextButton(onPressed: onRetry, child: const Text('Retry')),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import 'app.dart';
|
||||
import 'app_route.dart';
|
||||
import 'app_router.dart';
|
||||
import 'app_session.dart';
|
||||
import 'pipelines_destination.dart';
|
||||
import 'runs_destination.dart';
|
||||
import 'server_endpoint.dart';
|
||||
|
||||
@@ -100,6 +101,8 @@ class _PipelinesAppState extends State<PipelinesApp> {
|
||||
onDestinationSelected: (destination) =>
|
||||
_delegate.goTo(_routeOf(destination)),
|
||||
destinationBodies: {
|
||||
AppDestination.pipelines: (_) =>
|
||||
PipelinesDestination(session: _session, server: widget.server),
|
||||
AppDestination.runs: (_) => RunsDestination(
|
||||
session: _session,
|
||||
server: widget.server,
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../features/pipelines/screen.dart';
|
||||
import '../ui/adaptive/host.dart';
|
||||
import 'app_session.dart';
|
||||
import 'connection_status.dart';
|
||||
import 'server_endpoint.dart';
|
||||
|
||||
/// The Pipelines destination: the read-only browser plus honest status.
|
||||
///
|
||||
/// Before the shared socket accepts its first connection nothing is requested,
|
||||
/// so an offline launch cannot look like an empty pipeline list. After that the
|
||||
/// browser stays mounted through drops; a reconnect advances [syncToken] so the
|
||||
/// list and the open detail refresh in place instead of losing the selection.
|
||||
class PipelinesDestination extends StatelessWidget {
|
||||
const PipelinesDestination({
|
||||
super.key,
|
||||
required this.session,
|
||||
required this.server,
|
||||
});
|
||||
|
||||
final AppSession session;
|
||||
final ServerEndpoint server;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AnimatedBuilder(
|
||||
animation: session,
|
||||
builder: (context, _) {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
if ((server.requiresConfiguration || server.error != null) &&
|
||||
session.endpoint == null) {
|
||||
return ConnectionGate(
|
||||
session: session,
|
||||
server: server,
|
||||
cupertino: cupertino,
|
||||
);
|
||||
}
|
||||
if (!session.everConnected) {
|
||||
if (session.connected) return _pipelinesScreen();
|
||||
return ConnectionGate(
|
||||
session: session,
|
||||
server: server,
|
||||
cupertino: cupertino,
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
children: [
|
||||
if (!session.connected)
|
||||
ConnectionBanner(session: session, cupertino: cupertino),
|
||||
Expanded(child: _pipelinesScreen()),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Widget _pipelinesScreen() => PipelinesScreen(
|
||||
gateway: session.gateway,
|
||||
embedded: true,
|
||||
syncToken: session.connectionEpoch,
|
||||
);
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../core/transport/connection_state.dart';
|
||||
import '../features/runs/screen.dart';
|
||||
import '../ui/adaptive/host.dart';
|
||||
import 'app_session.dart';
|
||||
import 'connection_status.dart';
|
||||
import 'server_endpoint.dart';
|
||||
|
||||
/// The Runs destination: the loaded screen plus an honest connection status.
|
||||
@@ -36,7 +35,7 @@ class RunsDestination extends StatelessWidget {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
if ((server.requiresConfiguration || server.error != null) &&
|
||||
session.endpoint == null) {
|
||||
return _ConnectionScreen(
|
||||
return ConnectionGate(
|
||||
session: session,
|
||||
server: server,
|
||||
cupertino: cupertino,
|
||||
@@ -44,7 +43,7 @@ class RunsDestination extends StatelessWidget {
|
||||
}
|
||||
if (!session.everConnected) {
|
||||
if (session.connected) return _runsScreen();
|
||||
return _ConnectionScreen(
|
||||
return ConnectionGate(
|
||||
session: session,
|
||||
server: server,
|
||||
cupertino: cupertino,
|
||||
@@ -54,7 +53,7 @@ class RunsDestination extends StatelessWidget {
|
||||
children: [
|
||||
if (!session.connected ||
|
||||
session.subscription == RunSubscriptionState.refused)
|
||||
_ConnectionBanner(session: session, cupertino: cupertino),
|
||||
ConnectionBanner(session: session, cupertino: cupertino),
|
||||
Expanded(child: _runsScreen()),
|
||||
],
|
||||
);
|
||||
@@ -69,182 +68,3 @@ class RunsDestination extends StatelessWidget {
|
||||
onBack: onBack,
|
||||
);
|
||||
}
|
||||
|
||||
class _ConnectionScreen extends StatelessWidget {
|
||||
const _ConnectionScreen({
|
||||
required this.session,
|
||||
required this.server,
|
||||
required this.cupertino,
|
||||
});
|
||||
|
||||
final AppSession session;
|
||||
final ServerEndpoint server;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final state = session.connection;
|
||||
if (server.requiresConfiguration) {
|
||||
return _status(
|
||||
context,
|
||||
title: 'Server endpoint not configured',
|
||||
detail:
|
||||
'Build the native app with an explicit Pipelines endpoint, for '
|
||||
'example --dart-define=PIPELINES_SERVER_URL=ws://host:port/connect.',
|
||||
);
|
||||
}
|
||||
if (server.error != null) {
|
||||
return _status(context, title: server.error!, detail: '');
|
||||
}
|
||||
// Only the very first attempt is "connecting". A failed attempt keeps the
|
||||
// same honest unavailable state while the client retries behind it, so the
|
||||
// screen no longer flickers between unavailable and connecting.
|
||||
if (state.kind == ConnectionKind.connecting && state.attempt <= 1) {
|
||||
return _status(
|
||||
context,
|
||||
title: 'Connecting to Pipelines…',
|
||||
detail: '',
|
||||
progress: true,
|
||||
);
|
||||
}
|
||||
return _status(
|
||||
context,
|
||||
title: 'Pipelines server unavailable',
|
||||
detail: state.retrying
|
||||
? 'Retrying automatically. Check that the Pipelines server is running.'
|
||||
: 'Check that the Pipelines server is running, then try again.',
|
||||
onRetry: session.retry,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _status(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
required String detail,
|
||||
bool progress = false,
|
||||
VoidCallback? onRetry,
|
||||
}) {
|
||||
final theme = Theme.of(context);
|
||||
return Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (progress)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: cupertino
|
||||
? const CupertinoActivityIndicator()
|
||||
: const CircularProgressIndicator(),
|
||||
),
|
||||
Semantics(
|
||||
liveRegion: true,
|
||||
child: Text(
|
||||
title,
|
||||
textAlign: TextAlign.center,
|
||||
style: cupertino
|
||||
? CupertinoTheme.of(context).textTheme.navTitleTextStyle
|
||||
: theme.textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
if (detail.isNotEmpty) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
detail,
|
||||
textAlign: TextAlign.center,
|
||||
style: cupertino ? null : theme.textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
if (onRetry != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
if (cupertino)
|
||||
CupertinoButton(onPressed: onRetry, child: const Text('Retry'))
|
||||
else
|
||||
FilledButton(onPressed: onRetry, child: const Text('Retry')),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A compact status bar above the retained Runs screen.
|
||||
class _ConnectionBanner extends StatelessWidget {
|
||||
const _ConnectionBanner({required this.session, required this.cupertino});
|
||||
|
||||
final AppSession session;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final state = session.connection;
|
||||
final refused = session.subscription == RunSubscriptionState.refused;
|
||||
final reconnecting =
|
||||
!session.connected &&
|
||||
(state.kind == ConnectionKind.connecting || state.retrying);
|
||||
final String title;
|
||||
final String detail;
|
||||
final VoidCallback onRetry;
|
||||
if (session.connected && refused) {
|
||||
title = 'Not live — run updates are unavailable.';
|
||||
detail = session.subscriptionError;
|
||||
onRetry = session.resubscribe;
|
||||
} else if (reconnecting) {
|
||||
title = 'Reconnecting to Pipelines…';
|
||||
detail = '';
|
||||
onRetry = session.retry;
|
||||
} else {
|
||||
title = 'Not live — Pipelines server unavailable.';
|
||||
detail = 'Check that the Pipelines server is running.';
|
||||
onRetry = session.retry;
|
||||
}
|
||||
final textStyle = cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodyMedium;
|
||||
return ColoredBox(
|
||||
color: cupertino
|
||||
? CupertinoDynamicColor.resolve(CupertinoColors.systemGrey5, context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
if (reconnecting) ...[
|
||||
cupertino
|
||||
? const CupertinoActivityIndicator(radius: 7)
|
||||
: const SizedBox(
|
||||
width: 14,
|
||||
height: 14,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
],
|
||||
Expanded(
|
||||
child: Semantics(
|
||||
liveRegion: true,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title, style: textStyle),
|
||||
if (detail.isNotEmpty) Text(detail, style: textStyle),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
if (cupertino)
|
||||
CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: onRetry,
|
||||
child: const Text('Retry'),
|
||||
)
|
||||
else
|
||||
TextButton(onPressed: onRetry, child: const Text('Retry')),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,18 +21,31 @@ const double kPipelinesWideBreakpoint = 720;
|
||||
///
|
||||
/// [graphBuilder] is the optional integration hook for the later graph item.
|
||||
/// Without it the Graph tab states that graph rendering is pending.
|
||||
///
|
||||
/// Standalone use keeps the screen's own native scaffolding. The application
|
||||
/// shell sets [embedded] because it already owns the one navigation bar, and
|
||||
/// supplies [syncToken] so a reconnect refreshes in place.
|
||||
class PipelinesScreen extends StatefulWidget {
|
||||
const PipelinesScreen({
|
||||
super.key,
|
||||
required this.gateway,
|
||||
this.graphBuilder,
|
||||
this.onStageSelected,
|
||||
this.embedded = false,
|
||||
this.syncToken = 0,
|
||||
});
|
||||
|
||||
final ApiGateway gateway;
|
||||
final PipelineGraphBuilder? graphBuilder;
|
||||
final ValueChanged<PipelineStageRef>? onStageSelected;
|
||||
|
||||
/// True under the application shell, which owns the single navigation bar.
|
||||
final bool embedded;
|
||||
|
||||
/// Advances when the shared socket is replaced. The mounted controller
|
||||
/// reloads the list and the selected detail without losing the selection.
|
||||
final int syncToken;
|
||||
|
||||
@override
|
||||
State<PipelinesScreen> createState() => _PipelinesScreenState();
|
||||
}
|
||||
@@ -54,6 +67,10 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
_controller.dispose();
|
||||
_controller = PipelinesController(PipelinesRepository(widget.gateway))
|
||||
..load();
|
||||
} else if (oldWidget.syncToken != widget.syncToken) {
|
||||
// The socket was replaced; re-read through the existing controller so the
|
||||
// selected pipeline and requested version survive the reconnect.
|
||||
_controller.load();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +119,7 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
);
|
||||
},
|
||||
);
|
||||
if (widget.embedded) return _embeddedBody(context, body);
|
||||
return useCupertinoControls(context)
|
||||
? _cupertinoShell(context, body)
|
||||
: _materialShell(context, body);
|
||||
@@ -109,6 +127,43 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
/// The shell owns the navigation bar here, so the content keeps a native
|
||||
/// Refresh action without adding a second bar.
|
||||
Widget _embeddedBody(BuildContext context, Widget body) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: _refreshButton(context),
|
||||
),
|
||||
),
|
||||
Expanded(child: body),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _refreshButton(BuildContext context) {
|
||||
if (useCupertinoControls(context)) {
|
||||
return Semantics(
|
||||
button: true,
|
||||
label: 'Refresh',
|
||||
child: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: _controller.load,
|
||||
child: const Icon(CupertinoIcons.refresh),
|
||||
),
|
||||
);
|
||||
}
|
||||
return IconButton(
|
||||
tooltip: 'Refresh',
|
||||
onPressed: _controller.load,
|
||||
icon: const Icon(Icons.refresh),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _divider(BuildContext context) {
|
||||
if (useCupertinoControls(context)) {
|
||||
return Container(
|
||||
@@ -123,13 +178,7 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Pipelines'),
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: 'Refresh',
|
||||
onPressed: _controller.load,
|
||||
icon: const Icon(Icons.refresh),
|
||||
),
|
||||
],
|
||||
actions: [_refreshButton(context)],
|
||||
),
|
||||
body: SafeArea(child: body),
|
||||
);
|
||||
@@ -139,15 +188,7 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: const Text('Pipelines'),
|
||||
trailing: Semantics(
|
||||
button: true,
|
||||
label: 'Refresh',
|
||||
child: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: _controller.load,
|
||||
child: const Icon(CupertinoIcons.refresh),
|
||||
),
|
||||
),
|
||||
trailing: _refreshButton(context),
|
||||
),
|
||||
child: SafeArea(top: false, child: body),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user