57 lines
1.6 KiB
Dart
57 lines
1.6 KiB
Dart
import '../core/session/server_session.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
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 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: 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();
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
// A phone behind the web login reconnects with its kept session.
|
|
await ServerSession.load();
|
|
final server = await resolveLaunchServer(
|
|
base: base,
|
|
configured: configured,
|
|
settingsStore: settingsStore,
|
|
);
|
|
runApp(PipelinesApp(server: server));
|
|
}
|