Files
pipelines/app/lib/application/bootstrap.dart
T
alan ca2f7eee32 App: add a selectable app design with a Terminal look
AppDesign builds each design's light and dark ThemeData with an
AppDesignTokens extension (corner radius, flat surfaces, frame colour,
ANSI accents, prompt glyph). Settings gains a Design picker stored per
device; the theme hosts rebuild live. Terminal is monospace (bundled
RobotoMono), near-black or paper, flat 1px frames with 3px corners, and
draws the chat transcript as prompt lines, tool dot/result lines and
bracketed follow-up lines. Default keeps its exact themes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 16:43:59 +00:00

100 lines
3.4 KiB
Dart

import '../features/terminal/terminal_layout.dart';
import '../core/session/server_session.dart';
import '../ui/scale/ui_scale.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'app_url_strategy.dart';
import 'detached/detached_platform.dart';
import 'pipelines_binding.dart';
import 'pipelines_root.dart';
import 'server_endpoint.dart';
import '../features/settings/settings_store.dart';
import '../ui/theme/app_design_controller.dart';
import '../ui/theme/app_font_controller.dart';
import '../ui/theme/app_font_licenses.dart';
import '../ui/motion/animation_speed.dart';
import '../ui/motion/quick_switch_animation.dart';
/// Native builds must supply their server explicitly; there is no baked host.
const configuredServerUrl = String.fromEnvironment('PIPELINES_SERVER_URL');
/// Resolves the launch endpoint: on a phone the server saved at onboarding,
/// else the build's default (which only pre-fills onboarding until saved).
Future<ServerEndpoint> resolveLaunchServer({
Uri? base,
String configured = configuredServerUrl,
bool web = kIsWeb,
SettingsStore? settingsStore,
}) async {
WidgetsFlutterBinding.ensureInitialized();
var endpoint = configured;
if (!web) {
try {
final saved =
(await (settingsStore ?? const SharedPreferencesSettingsStore())
.load())
.serverUrl;
if (saved.trim().isNotEmpty) endpoint = saved;
} catch (_) {
// Keep the build's default.
}
}
return ServerEndpoint.resolve(
base: base ?? Uri.base,
web: web,
configured: endpoint,
);
}
/// How long the first frame waits for a stored font before drawing in the
/// system font.
const appFontStartupWait = Duration(milliseconds: 1500);
/// Resolves the endpoint for this launch and starts the normal composition,
/// or a detached window's when the launch names one ([args] on a desktop,
/// the location on the web; see `detachedLaunchRoute`).
Future<void> runPipelinesApp({
Uri? base,
String configured = configuredServerUrl,
SettingsStore? settingsStore,
List<String> args = const [],
}) async {
useAppUrlStrategy();
final detached = detachedLaunchRoute(args);
// A detached window reads the device's terminal layout, never writes it.
if (detached != null) TerminalLayout.instance.persist = false;
PipelinesBinding.ensureInitialized();
registerAppFontLicenses();
// The device's chosen font loads beside the session; a slow download does
// not hold the first frame, and applies when it lands.
final animationSpeed = AnimationSpeedController.instance.restore();
final uiScale = UiScaleController.instance.restore();
final terminalLayout = TerminalLayout.instance.restore();
final quickSwitchAnimation = QuickSwitchAnimationController.instance
.restore();
final font = AppFontController.instance.restore(wait: appFontStartupWait);
final design = AppDesignController.instance.restore();
// A phone behind the web login reconnects with its kept session.
await ServerSession.load();
await font;
await design;
await animationSpeed;
await uiScale;
await terminalLayout;
await quickSwitchAnimation;
final server = await resolveLaunchServer(
base: base,
configured: configured,
settingsStore: settingsStore,
);
runApp(
PipelinesRoot(
server: server,
buildDefault: configured,
signedIn: kIsWeb || ServerSession.cookie != null,
detached: detached,
),
);
}