feat(app): register native Settings on the shared live session
This commit is contained in:
@@ -18,13 +18,14 @@ enum RunSubscriptionState { pending, live, refused }
|
||||
/// `subscribe` on every connected transition because a new socket has no
|
||||
/// watch, and drops it deliberately with `unsubscribe` when the app stops.
|
||||
class AppSession extends ChangeNotifier {
|
||||
AppSession({required this.endpoint, PipelinesClient? client})
|
||||
: _client = client ?? PipelinesClient() {
|
||||
AppSession({required Uri? endpoint, PipelinesClient? client})
|
||||
: _initialEndpoint = endpoint,
|
||||
_client = client ?? PipelinesClient() {
|
||||
_states = _client.states.listen(_onState);
|
||||
_frames = _client.frames.listen(_onFrame);
|
||||
}
|
||||
|
||||
final Uri? endpoint;
|
||||
final Uri? _initialEndpoint;
|
||||
final PipelinesClient _client;
|
||||
late final StreamSubscription<ConnectionState> _states;
|
||||
late final StreamSubscription<JsonMap> _frames;
|
||||
@@ -36,6 +37,10 @@ class AppSession extends ChangeNotifier {
|
||||
String? _subscribeRequest;
|
||||
|
||||
ApiGateway get gateway => _client;
|
||||
|
||||
/// Settings controls the same transport; it must never create another socket.
|
||||
PipelinesClient get client => _client;
|
||||
Uri? get endpoint => _client.endpoint ?? _initialEndpoint;
|
||||
ConnectionState get connection => _connection;
|
||||
bool get connected => _connection.kind == ConnectionKind.connected;
|
||||
|
||||
@@ -62,7 +67,7 @@ class AppSession extends ChangeNotifier {
|
||||
/// Retries now: reopens a disconnected socket, or repeats a refused watch on
|
||||
/// a healthy one.
|
||||
Future<void> retry() async {
|
||||
if (connected) {
|
||||
if (_client.state.kind == ConnectionKind.connected) {
|
||||
resubscribe();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ 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';
|
||||
@@ -106,6 +107,11 @@ class _PipelinesAppState extends State<PipelinesApp> {
|
||||
onRunSelected: (id) => _delegate.goTo(AppRoute.run(id)),
|
||||
onBack: () => _delegate.goTo(AppRoute.runs),
|
||||
),
|
||||
AppDestination.settings: (_) => SettingsScreen(
|
||||
client: _session.client,
|
||||
initialEndpoint: _session.endpoint,
|
||||
embedded: true,
|
||||
),
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -34,7 +34,8 @@ class RunsDestination extends StatelessWidget {
|
||||
animation: session,
|
||||
builder: (context, _) {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
if (server.requiresConfiguration || server.error != null) {
|
||||
if ((server.requiresConfiguration || server.error != null) &&
|
||||
session.endpoint == null) {
|
||||
return _ConnectionScreen(
|
||||
session: session,
|
||||
server: server,
|
||||
|
||||
Reference in New Issue
Block a user