fix(app): Android Back and the back gesture go through the router: they step up a level, and ask before closing the app; an open pipeline is part of the route

This commit is contained in:
2026-10-24 01:15:21 +01:00
parent 6a9c41de33
commit f51ad9c7ed
6 changed files with 205 additions and 6 deletions
+31 -5
View File
@@ -34,6 +34,7 @@ class PipelinesScreen extends StatefulWidget {
this.syncToken = 0,
this.onRunStarted,
this.onViewPipelineRuns,
this.onSelectionChanged,
this.onOpenSchedules,
this.initialPipelineId,
this.initialVersion = 0,
@@ -57,6 +58,10 @@ class PipelinesScreen extends StatefulWidget {
final ValueChanged<int>? onRunStarted;
final ValueChanged<int>? onViewPipelineRuns;
/// Reports the open pipeline (null for the list) so the route, and with it
/// Back, follows what is shown.
final ValueChanged<int?>? onSelectionChanged;
/// Opens every schedule; shown in the bar while the list is visible.
final VoidCallback? onOpenSchedules;
@@ -105,6 +110,17 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
// The detail read owns its own failure state; the list read continues.
_controller.openPipeline(id, version: widget.initialVersion);
}
_reported = _controller.selectedId;
_controller.addListener(_reportSelection);
}
int? _reported;
void _reportSelection() {
final id = _controller.selectedId;
if (id == _reported) return;
_reported = id;
widget.onSelectionChanged?.call(id);
}
@override
@@ -113,10 +129,15 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
if (oldWidget.gateway != widget.gateway ||
oldWidget.endpoint != widget.endpoint) {
_controller.dispose();
_controller = PipelinesController(
PipelinesRepository(widget.gateway),
pendingRunStore: SharedPreferencesPendingRunStore(widget.endpoint),
)..load();
_controller =
PipelinesController(
PipelinesRepository(widget.gateway),
pendingRunStore: SharedPreferencesPendingRunStore(
widget.endpoint,
),
)
..load()
..addListener(_reportSelection);
} 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.
@@ -129,7 +150,12 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
final id = widget.initialPipelineId;
if (id == null) {
_controller.clearSelection();
} else if (!_isRoutePin(_controller.detail)) {
} else if (!(_controller.selectedId == id &&
// The route caught up with a pipeline opened from the list.
((oldWidget.initialPipelineId != id &&
widget.initialVersion <= 0) ||
_controller.selectedVersion == widget.initialVersion)) &&
!_isRoutePin(_controller.detail)) {
_controller.openPipeline(id, version: widget.initialVersion);
}
}