feat(app): load saved endpoint during native startup

This commit is contained in:
2026-10-22 23:09:26 +01:00
parent ff0447fae8
commit f58d8d3572
2 changed files with 123 additions and 5 deletions
+37 -5
View File
@@ -4,17 +4,49 @@ import 'package:flutter/widgets.dart';
import 'app_url_strategy.dart';
import 'pipelines_app.dart';
import 'server_endpoint.dart';
import '../features/settings/settings_store.dart';
/// Native builds must supply their server explicitly; there is no baked host.
const configuredServerUrl = String.fromEnvironment('PIPELINES_SERVER_URL');
/// Resolves the endpoint for this launch and starts the normal composition.
void runPipelinesApp({Uri? base, String configured = configuredServerUrl}) {
useAppUrlStrategy();
final server = ServerEndpoint.resolve(
/// Resolves the launch endpoint, loading the last saved native endpoint only
/// when no build-time endpoint was supplied.
Future<ServerEndpoint> resolveLaunchServer({
Uri? base,
String configured = configuredServerUrl,
bool web = kIsWeb,
SettingsStore? settingsStore,
}) async {
WidgetsFlutterBinding.ensureInitialized();
var endpoint = configured;
if (!web && endpoint.trim().isEmpty) {
try {
endpoint =
(await (settingsStore ?? const SharedPreferencesSettingsStore())
.load())
.serverUrl;
} catch (_) {
endpoint = '';
}
}
return ServerEndpoint.resolve(
base: base ?? Uri.base,
web: kIsWeb,
web: web,
configured: endpoint,
);
}
/// Resolves the endpoint for this launch and starts the normal composition.
Future<void> runPipelinesApp({
Uri? base,
String configured = configuredServerUrl,
SettingsStore? settingsStore,
}) async {
useAppUrlStrategy();
final server = await resolveLaunchServer(
base: base,
configured: configured,
settingsStore: settingsStore,
);
runApp(PipelinesApp(server: server));
}