8476cfd740
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.
139 lines
4.5 KiB
Dart
139 lines
4.5 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import '../core/transport/pipelines_client.dart';
|
|
import '../shell/adaptive_shell.dart';
|
|
import '../shell/destination.dart';
|
|
import '../features/settings/settings_screen.dart';
|
|
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';
|
|
|
|
/// Composes the live application around one [AppSession] and one [Router].
|
|
///
|
|
/// Tests may inject the client and route-information provider; the session
|
|
/// owns the socket either way, so there is never a second app-level connection.
|
|
class PipelinesApp extends StatefulWidget {
|
|
const PipelinesApp({
|
|
super.key,
|
|
required this.server,
|
|
this.client,
|
|
this.cupertino,
|
|
this.routeInformationProvider,
|
|
});
|
|
|
|
final ServerEndpoint server;
|
|
final PipelinesClient? client;
|
|
final bool? cupertino;
|
|
|
|
/// Test seam: the Router's initial and subsequent route information.
|
|
final RouteInformationProvider? routeInformationProvider;
|
|
|
|
@override
|
|
State<PipelinesApp> createState() => _PipelinesAppState();
|
|
}
|
|
|
|
class _PipelinesAppState extends State<PipelinesApp> {
|
|
late final AppSession _session;
|
|
late final AppRouterDelegate _delegate;
|
|
late final RouteInformationProvider _provider;
|
|
late final bool _ownsProvider;
|
|
late final RouterConfig<AppRoute> _config;
|
|
late final bool _cupertino;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_session = AppSession(endpoint: widget.server.uri, client: widget.client);
|
|
_ownsProvider = widget.routeInformationProvider == null;
|
|
_provider =
|
|
widget.routeInformationProvider ??
|
|
PlatformRouteInformationProvider(
|
|
initialRouteInformation: initialRouteInformation(),
|
|
);
|
|
// A malformed or unknown boot path renders Pipelines, so make the address
|
|
// bar agree with the rendered destination instead of showing a dead link.
|
|
final initial = AppRoute.parse(_provider.value.uri.path);
|
|
if (_provider.value.uri.path != initial.path) {
|
|
_provider.routerReportsNewRouteInformation(
|
|
RouteInformation(uri: Uri(path: initial.path)),
|
|
type: RouteInformationReportingType.neglect,
|
|
);
|
|
}
|
|
_cupertino = widget.cupertino ?? _platformIsCupertino;
|
|
_delegate = AppRouterDelegate(
|
|
initial: initial,
|
|
cupertino: _cupertino,
|
|
onPopToRuns: () => _delegate.goTo(AppRoute.runs),
|
|
builder: _buildShell,
|
|
);
|
|
_config = RouterConfig<AppRoute>(
|
|
routeInformationParser: const AppRouteParser(),
|
|
routerDelegate: _delegate,
|
|
routeInformationProvider: _provider,
|
|
);
|
|
unawaited(_session.start());
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_delegate.dispose();
|
|
if (_ownsProvider) {
|
|
(_provider as PlatformRouteInformationProvider).dispose();
|
|
}
|
|
_session.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) =>
|
|
MyApp.router(cupertino: _cupertino, routerConfig: _config);
|
|
|
|
Widget _buildShell(BuildContext context, AppRoute route) => AdaptiveShell(
|
|
cupertino: _cupertino,
|
|
destination: _destinationOf(route.kind),
|
|
onDestinationSelected: (destination) =>
|
|
_delegate.goTo(_routeOf(destination)),
|
|
destinationBodies: {
|
|
AppDestination.pipelines: (_) =>
|
|
PipelinesDestination(session: _session, server: widget.server),
|
|
AppDestination.runs: (_) => RunsDestination(
|
|
session: _session,
|
|
server: widget.server,
|
|
initialRunId: route.runId,
|
|
onRunSelected: (id) => _delegate.goTo(AppRoute.run(id)),
|
|
onBack: () => _delegate.goTo(AppRoute.runs),
|
|
),
|
|
AppDestination.settings: (_) => SettingsScreen(
|
|
client: _session.client,
|
|
initialEndpoint: _session.endpoint,
|
|
embedded: true,
|
|
),
|
|
},
|
|
);
|
|
|
|
AppDestination _destinationOf(AppRouteKind kind) => switch (kind) {
|
|
AppRouteKind.pipelines => AppDestination.pipelines,
|
|
AppRouteKind.runs => AppDestination.runs,
|
|
AppRouteKind.chat => AppDestination.chat,
|
|
AppRouteKind.settings => AppDestination.settings,
|
|
};
|
|
|
|
AppRoute _routeOf(AppDestination destination) => switch (destination) {
|
|
AppDestination.pipelines => AppRoute.pipelines,
|
|
AppDestination.runs => AppRoute.runs,
|
|
AppDestination.chat => AppRoute.chat,
|
|
AppDestination.settings => AppRoute.settings,
|
|
};
|
|
|
|
bool get _platformIsCupertino =>
|
|
defaultTargetPlatform == TargetPlatform.iOS ||
|
|
defaultTargetPlatform == TargetPlatform.macOS;
|
|
}
|