feat(app): phone onboarding (server, then password) kept across launches; a known server opens straight into the app; a refused session asks for the password
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../core/session/server_session.dart';
|
||||
import '../features/onboarding/onboarding_flow.dart';
|
||||
import '../features/settings/settings_store.dart';
|
||||
import '../ui/theme/app_theme.dart';
|
||||
import 'pipelines_app.dart';
|
||||
import 'server_endpoint.dart';
|
||||
|
||||
/// The phone app's root: onboarding until a server and its password are
|
||||
/// known, then the app. A saved session the server later refuses brings the
|
||||
/// password step back; an unreachable server just reconnects in the app.
|
||||
class PipelinesRoot extends StatefulWidget {
|
||||
const PipelinesRoot({
|
||||
super.key,
|
||||
required this.server,
|
||||
this.buildDefault = '',
|
||||
this.signedIn = false,
|
||||
this.check = ServerSession.check,
|
||||
this.settingsStore = const SharedPreferencesSettingsStore(),
|
||||
});
|
||||
|
||||
final ServerEndpoint server;
|
||||
|
||||
/// The server this build was made for; it pre-fills onboarding.
|
||||
final String buildDefault;
|
||||
|
||||
/// A session is kept on this device.
|
||||
final bool signedIn;
|
||||
final ServerCheck check;
|
||||
final SettingsStore settingsStore;
|
||||
|
||||
@override
|
||||
State<PipelinesRoot> createState() => _PipelinesRootState();
|
||||
}
|
||||
|
||||
class _PipelinesRootState extends State<PipelinesRoot> {
|
||||
late ServerEndpoint _server = widget.server;
|
||||
late bool _onboarding = widget.server.uri == null || !widget.signedIn;
|
||||
bool _refused = false;
|
||||
int _generation = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (!_onboarding) _verify(widget.server.uri!);
|
||||
}
|
||||
|
||||
/// A kept session the server now refuses asks for the password again.
|
||||
Future<void> _verify(Uri endpoint) async {
|
||||
final state = await widget.check(endpoint);
|
||||
if (!mounted || state != SessionState.signedOut) return;
|
||||
setState(() {
|
||||
_refused = true;
|
||||
_onboarding = true;
|
||||
});
|
||||
}
|
||||
|
||||
void _done(Uri endpoint) {
|
||||
setState(() {
|
||||
_server = ServerEndpoint.resolve(
|
||||
base: Uri.base,
|
||||
web: false,
|
||||
configured: endpoint.toString(),
|
||||
);
|
||||
_onboarding = false;
|
||||
_refused = false;
|
||||
_generation++;
|
||||
});
|
||||
}
|
||||
|
||||
bool get _cupertino =>
|
||||
defaultTargetPlatform == TargetPlatform.iOS ||
|
||||
defaultTargetPlatform == TargetPlatform.macOS;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!_onboarding) {
|
||||
return PipelinesApp(
|
||||
key: ValueKey(_generation),
|
||||
server: _server,
|
||||
knownServer: true,
|
||||
);
|
||||
}
|
||||
final flow = OnboardingFlow(
|
||||
initialServer: _server.uri?.toString() ?? widget.buildDefault,
|
||||
startAtPassword: _refused,
|
||||
saveServer: widget.settingsStore.saveServerUrl,
|
||||
onDone: _done,
|
||||
);
|
||||
return _cupertino
|
||||
? CupertinoApp(
|
||||
title: 'Pipelines',
|
||||
theme: appCupertinoTheme,
|
||||
debugShowCheckedModeBanner: false,
|
||||
home: flow,
|
||||
)
|
||||
: MaterialApp(
|
||||
title: 'Pipelines',
|
||||
theme: appLightTheme(),
|
||||
darkTheme: appDarkTheme(),
|
||||
debugShowCheckedModeBanner: false,
|
||||
home: flow,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user