Persist exact tab locations including Settings under Pipelines
This commit is contained in:
@@ -40,6 +40,8 @@ import 'schedules_destination.dart';
|
||||
import 'search_destination.dart';
|
||||
import 'server_endpoint.dart';
|
||||
import 'templates_destination.dart';
|
||||
import 'tab_locations.dart';
|
||||
import 'tab_locations_store.dart';
|
||||
|
||||
/// The application's return-to-foreground policy for the shared socket.
|
||||
///
|
||||
@@ -76,8 +78,10 @@ class PipelinesApp extends StatefulWidget {
|
||||
this.androidFeedReader = fetchLatestUpdate,
|
||||
this.androidInstaller = downloadAndInstall,
|
||||
this.webRefresher = refreshWebPage,
|
||||
this.tabLocationsStore,
|
||||
});
|
||||
|
||||
final TabLocationsStore? tabLocationsStore;
|
||||
final ServerEndpoint server;
|
||||
final PipelinesClient? client;
|
||||
final bool? cupertino;
|
||||
@@ -219,6 +223,19 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
// a dropped or unknown query is canonicalised away.
|
||||
final location = routeLocation(_provider.value.uri);
|
||||
final initial = AppRoute.parse(location);
|
||||
final nativeDefault =
|
||||
widget.routeInformationProvider == null &&
|
||||
!kIsWeb &&
|
||||
const [
|
||||
'',
|
||||
'/',
|
||||
].contains(WidgetsBinding.instance.platformDispatcher.defaultRouteName);
|
||||
final restoreTab = !widget.resetRoute && (location == '/' || nativeDefault);
|
||||
_tabLocations = TabLocations(
|
||||
widget.tabLocationsStore ??
|
||||
SharedPreferencesTabLocationsStore(scope: _navigationScope),
|
||||
);
|
||||
_tabLocations.record(initial, visited: !restoreTab);
|
||||
if (location != initial.path) {
|
||||
_provider.routerReportsNewRouteInformation(
|
||||
RouteInformation(uri: Uri.parse(initial.path)),
|
||||
@@ -248,7 +265,9 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
);
|
||||
_delegate.addListener(_routeChanged);
|
||||
// Seed retained destinations for deep links as well as later navigation.
|
||||
_routeChanged();
|
||||
_rememberChatRoute(initial);
|
||||
_rememberBodyRoute(_delegate.shellRoute);
|
||||
unawaited(_restoreTabLocations(restoreTab));
|
||||
_chatQuestionNotices = ChatQuestionNotices(
|
||||
gateway: _session.gateway,
|
||||
canNotify: () => _notifications.canNotify,
|
||||
@@ -344,6 +363,7 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabLocations.dispose();
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_deliveryHandoff?.dispose();
|
||||
_session.removeListener(_attentionSessionChanged);
|
||||
@@ -502,21 +522,49 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
setState(() => _pendingRunSearch = null);
|
||||
}
|
||||
|
||||
/// Drops a pending request once the shell leaves the run it names.
|
||||
///
|
||||
/// The mounted detail is the only consumer, and it exists only after the run's
|
||||
/// detail has loaded. Backing out while that read is still pending, or leaving
|
||||
/// a failed detail, would otherwise keep the request for the next unrelated
|
||||
/// visit to the same run. Search/Templates/Schedules pages above the run keep
|
||||
/// it, because the shell route underneath them still names that run.
|
||||
/// The last route each tab showed, so switching tabs returns to where the
|
||||
/// operator left it; tapping the open tab again goes to its root.
|
||||
final Map<AppDestination, AppRoute> _tabRoutes = {};
|
||||
/// The last location within each tab, including Settings under Pipelines.
|
||||
/// Explicit Back is separate from tab selection and same-tab retaps.
|
||||
String get _navigationScope =>
|
||||
widget.serverId ?? widget.server.uri?.toString() ?? '';
|
||||
|
||||
late final TabLocations _tabLocations;
|
||||
Map<AppDestination, AppRoute> get _tabRoutes => _tabLocations.routes;
|
||||
// A Settings visit owns the Pipelines tab's return location, but must not
|
||||
// clear the still-mounted Pipelines body's selection or editor underneath.
|
||||
final _bodyRoutes = <AppDestination, AppRoute>{};
|
||||
|
||||
void _rememberBodyRoute(AppRoute route) {
|
||||
_bodyRoutes[_destinationOf(route.kind)] = route;
|
||||
}
|
||||
|
||||
Future<void> _restoreTabLocations(bool restoreActive) async {
|
||||
final revision = _tabLocations.revision;
|
||||
final restored = await _tabLocations.restore(restoreActive: restoreActive);
|
||||
if (!mounted) return;
|
||||
// The Router first consumes its boot URL. Apply saved navigation afterward,
|
||||
// and never jump over a user move that happened while preferences loaded.
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
if (restored != null && revision == _tabLocations.revision) {
|
||||
_delegate.goTo(restored);
|
||||
} else {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
WidgetsBinding.instance.ensureVisualUpdate();
|
||||
}
|
||||
|
||||
void _rememberChatRoute(AppRoute route) {
|
||||
if (route.kind == AppRouteKind.chat && route.chatSessionId != null) {
|
||||
_chatWorkspaceRoute = route;
|
||||
}
|
||||
}
|
||||
|
||||
AppRoute? _chatWorkspaceRoute;
|
||||
Set<String>? _availableChatSessionIds;
|
||||
|
||||
void _selectDestination(AppDestination destination) {
|
||||
final current = _destinationOf(_delegate.shellRoute.kind);
|
||||
final current = tabForRoute(_delegate.route);
|
||||
final last = _tabRoutes[destination];
|
||||
if (destination == AppDestination.chat && current == destination) {
|
||||
final reopened = chatRouteForRetap(
|
||||
@@ -529,17 +577,14 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
_delegate.goTo(reopened ?? _routeOf(destination));
|
||||
return;
|
||||
}
|
||||
_delegate.goTo(
|
||||
destination == current || last == null ? _routeOf(destination) : last,
|
||||
);
|
||||
_delegate.goTo(last ?? _routeOf(destination));
|
||||
}
|
||||
|
||||
void _routeChanged() {
|
||||
final shown = _delegate.shellRoute;
|
||||
_tabRoutes[_destinationOf(shown.kind)] = shown;
|
||||
if (shown.kind == AppRouteKind.chat && shown.chatSessionId != null) {
|
||||
_chatWorkspaceRoute = shown;
|
||||
}
|
||||
final shown = _delegate.route;
|
||||
_tabLocations.record(shown);
|
||||
_rememberBodyRoute(_delegate.shellRoute);
|
||||
_rememberChatRoute(shown);
|
||||
final pending = _pendingRunSearch;
|
||||
if (!mounted || pending == null) return;
|
||||
final route = _delegate.shellRoute;
|
||||
@@ -603,10 +648,14 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
Widget _shellFor(AppRoute route, int attentionCount) {
|
||||
// Each tab is built from the route it last showed, so switching tabs keeps
|
||||
// an open run, pipeline or chat instead of resetting it.
|
||||
AppRoute tab(AppDestination destination) =>
|
||||
_destinationOf(route.kind) == destination
|
||||
? route
|
||||
: _tabRoutes[destination] ?? _routeOf(destination);
|
||||
AppRoute tab(AppDestination destination) {
|
||||
if (_destinationOf(route.kind) == destination) return route;
|
||||
final saved = _tabRoutes[destination];
|
||||
return saved != null && _destinationOf(saved.kind) == destination
|
||||
? saved
|
||||
: _bodyRoutes[destination] ?? _routeOf(destination);
|
||||
}
|
||||
|
||||
final pipelinesRoute = tab(AppDestination.pipelines);
|
||||
final runsRoute = tab(AppDestination.runs);
|
||||
final chatRoute = tab(AppDestination.chat);
|
||||
@@ -615,6 +664,7 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
cupertino: _cupertino,
|
||||
destination: _destinationOf(route.kind),
|
||||
onDestinationSelected: _selectDestination,
|
||||
onClosePage: () => _delegate.goTo(AppRoute.pipelines),
|
||||
destinationBodies: {
|
||||
AppDestination.pipelines: (_) => PipelinesDestination(
|
||||
session: _session,
|
||||
|
||||
Reference in New Issue
Block a user