Offer platform-specific updates at startup and foreground return
This commit is contained in:
@@ -96,6 +96,9 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
/// Whether a dialog, popup, or other route is covering the shell page.
|
||||
bool get hasTransientRoute => _navigatorKey.currentState?.canPop() ?? false;
|
||||
|
||||
/// Context for app-level native dialogs owned by the mounted navigator.
|
||||
BuildContext? get navigatorContext => _navigatorKey.currentContext;
|
||||
|
||||
bool get searchOpen => _route.kind == AppRouteKind.search;
|
||||
|
||||
bool get templatesOpen => _route.kind == AppRouteKind.templates;
|
||||
|
||||
@@ -24,6 +24,10 @@ import '../features/runs/ui/run_search_selection.dart';
|
||||
import '../features/search/domain/search_target.dart';
|
||||
import '../features/settings/settings_screen.dart';
|
||||
import '../features/settings/settings_store.dart';
|
||||
import '../features/updates/app_updates.dart';
|
||||
import '../features/updates/launch_update.dart';
|
||||
import '../features/updates/launch_update_dialog.dart';
|
||||
import '../features/updates/web_release.dart';
|
||||
import '../features/settings/server_connections.dart';
|
||||
import 'app.dart';
|
||||
import 'app_route.dart';
|
||||
@@ -63,6 +67,15 @@ class PipelinesApp extends StatefulWidget {
|
||||
this.servers,
|
||||
this.resetRoute = false,
|
||||
this.legacyPendingEndpoints = const [],
|
||||
this.webPlatform = kIsWeb,
|
||||
this.webBuildId = compiledWebBuildId,
|
||||
this.webPageUri,
|
||||
this.androidSupported,
|
||||
this.webReleaseReader = fetchLatestWebBuild,
|
||||
this.installedVersionReader = installedVersionCode,
|
||||
this.androidFeedReader = fetchLatestUpdate,
|
||||
this.androidInstaller = downloadAndInstall,
|
||||
this.webRefresher = refreshWebPage,
|
||||
});
|
||||
|
||||
final ServerEndpoint server;
|
||||
@@ -79,6 +92,15 @@ class PipelinesApp extends StatefulWidget {
|
||||
final ServerConnections? servers;
|
||||
final bool resetRoute;
|
||||
final List<String> legacyPendingEndpoints;
|
||||
final bool webPlatform;
|
||||
final String webBuildId;
|
||||
final Uri? webPageUri;
|
||||
final bool? androidSupported;
|
||||
final Future<String?> Function(Uri) webReleaseReader;
|
||||
final Future<int?> Function() installedVersionReader;
|
||||
final Future<AppUpdate> Function(Uri) androidFeedReader;
|
||||
final UpdateInstaller androidInstaller;
|
||||
final Future<void> Function() webRefresher;
|
||||
|
||||
@override
|
||||
State<PipelinesApp> createState() => _PipelinesAppState();
|
||||
@@ -105,6 +127,9 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
/// Prevents duplicate resumed notifications from refreshing twice before
|
||||
/// the next background transition starts another foreground visit.
|
||||
bool _foregroundVisitHandled = false;
|
||||
final _launchUpdates = LaunchUpdateChecker();
|
||||
bool _launchUpdateBusy = false;
|
||||
Uri? _launchUpdateEndpoint;
|
||||
|
||||
/// One run detail request from Search, delivered through the shell so the
|
||||
/// mounted run detail can resolve it once the named run's steps have loaded.
|
||||
@@ -212,6 +237,7 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
.where((frame) => frame['type'] == 'run_event')
|
||||
.listen(_attention.observeFrame);
|
||||
_session.addListener(_attentionSessionChanged);
|
||||
_session.addListener(_updateEndpointChanged);
|
||||
_attention.addListener(_attentionChanged);
|
||||
_delegate = AppRouterDelegate(
|
||||
initial: initial,
|
||||
@@ -245,6 +271,75 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
backButtonDispatcher: RootBackButtonDispatcher(),
|
||||
);
|
||||
unawaited(_session.start());
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
unawaited(_checkLaunchUpdate());
|
||||
});
|
||||
}
|
||||
|
||||
void _updateEndpointChanged() {
|
||||
if (_launchUpdateEndpoint == _session.endpoint) return;
|
||||
_launchUpdateEndpoint = _session.endpoint;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
unawaited(_checkLaunchUpdate());
|
||||
});
|
||||
WidgetsBinding.instance.ensureVisualUpdate();
|
||||
}
|
||||
|
||||
Future<void> _checkLaunchUpdate() async {
|
||||
if (!mounted || _launchUpdateBusy) return;
|
||||
final dialogContext = _delegate.navigatorContext;
|
||||
if (dialogContext == null || !dialogContext.mounted) return;
|
||||
_launchUpdateBusy = true;
|
||||
final endpoint = _session.endpoint;
|
||||
try {
|
||||
final update = await _launchUpdates.check(
|
||||
web: widget.webPlatform,
|
||||
android: widget.androidSupported ?? appUpdatesSupported,
|
||||
webBuildId: widget.webBuildId,
|
||||
page: widget.webPageUri ?? Uri.base,
|
||||
endpoint: endpoint,
|
||||
readWeb: widget.webReleaseReader,
|
||||
installedVersion: widget.installedVersionReader,
|
||||
readAndroid: widget.androidFeedReader,
|
||||
);
|
||||
if (!mounted || update == null || !dialogContext.mounted) return;
|
||||
if (!widget.webPlatform && endpoint != _session.endpoint) return;
|
||||
_launchUpdates.markOffered(update);
|
||||
final accepted = await showLaunchUpdateDialog(
|
||||
dialogContext,
|
||||
web: update is WebLaunchUpdate,
|
||||
cupertino: _cupertino,
|
||||
);
|
||||
if (accepted != true || !mounted || !dialogContext.mounted) return;
|
||||
if (!widget.webPlatform && endpoint != _session.endpoint) return;
|
||||
try {
|
||||
if (update is WebLaunchUpdate) {
|
||||
await widget.webRefresher();
|
||||
} else {
|
||||
await installLaunchUpdate(
|
||||
dialogContext,
|
||||
(update as AndroidLaunchUpdate).update,
|
||||
installer: widget.androidInstaller,
|
||||
cupertino: _cupertino,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
if (mounted && dialogContext.mounted) {
|
||||
await showLaunchUpdateFailure(
|
||||
dialogContext,
|
||||
error,
|
||||
cupertino: _cupertino,
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (_) {
|
||||
// An offline or signed-out update feed never interrupts opening the app.
|
||||
} finally {
|
||||
_launchUpdateBusy = false;
|
||||
if (mounted && endpoint != _session.endpoint) {
|
||||
unawaited(_checkLaunchUpdate());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -252,6 +347,7 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_deliveryHandoff?.dispose();
|
||||
_session.removeListener(_attentionSessionChanged);
|
||||
_session.removeListener(_updateEndpointChanged);
|
||||
unawaited(_attentionFrames?.cancel());
|
||||
_attention.removeListener(_attentionChanged);
|
||||
_attention.dispose();
|
||||
@@ -285,6 +381,8 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
}
|
||||
if (_foregroundVisitHandled) return;
|
||||
_foregroundVisitHandled = true;
|
||||
_launchUpdates.beginVisit();
|
||||
unawaited(_checkLaunchUpdate());
|
||||
final connection = _session.connection.kind;
|
||||
if (shouldReconnectOnForeground(connection)) {
|
||||
unawaited(_session.retry());
|
||||
|
||||
Reference in New Issue
Block a user