2026-10-14 14:08:56 +09:00
|
|
|
// Yukart display: the tablet app. Starts the link to the Orin and hands the screen to
|
|
|
|
|
// the shell (lib/shell.dart). Code layout: lib/README.md.
|
2026-10-11 04:01:05 +09:00
|
|
|
|
2026-09-05 13:50:51 +09:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
2026-10-14 14:08:56 +09:00
|
|
|
import 'link/boundary.dart';
|
|
|
|
|
import 'link/net.dart';
|
|
|
|
|
import 'pages/link_test.dart';
|
|
|
|
|
import 'shell.dart';
|
|
|
|
|
import 'shell_scope.dart';
|
2026-10-13 23:25:28 +09:00
|
|
|
import 'theme/palette.dart';
|
2026-10-09 20:23:00 +09:00
|
|
|
|
|
|
|
|
/// Override for development, e.g. `--dart-define=YUKART_GW=ws://halogen.local:7700/`.
|
2026-10-11 17:43:27 +09:00
|
|
|
const defaultUrl = String.fromEnvironment(
|
|
|
|
|
'YUKART_GW',
|
|
|
|
|
defaultValue: 'ws://192.168.55.1:7700/',
|
|
|
|
|
);
|
2026-10-09 20:23:00 +09:00
|
|
|
|
|
|
|
|
Future<void> main() async {
|
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
2026-10-14 14:08:56 +09:00
|
|
|
final themes = await Themes.load();
|
2026-10-09 20:23:00 +09:00
|
|
|
final usb = UsbLink();
|
|
|
|
|
await usb.bindFor(Uri.parse(defaultUrl));
|
|
|
|
|
final boundary = Boundary(defaultUrl)..start();
|
2026-10-11 15:55:52 +09:00
|
|
|
final linkTest = LinkTest(usb);
|
2026-10-11 16:33:55 +09:00
|
|
|
// Development hook: `am start ... --es linktest [dl:|bi:]<label>[@<host>]` runs the test
|
|
|
|
|
// (`dl:` the download series, `bi:` burst latency against idle gaps), on the gateway's host unless one is given.
|
2026-10-11 15:58:43 +09:00
|
|
|
Future<void> runLinkTest(String request) async {
|
2026-10-11 17:43:27 +09:00
|
|
|
final mode = request.startsWith('dl:') || request.startsWith('bi:')
|
|
|
|
|
? request.substring(0, 2)
|
|
|
|
|
: '';
|
2026-10-11 16:33:55 +09:00
|
|
|
if (mode.isNotEmpty) request = request.substring(3);
|
2026-10-11 15:58:43 +09:00
|
|
|
final at = request.indexOf('@');
|
|
|
|
|
final label = at < 0 ? request : request.substring(0, at);
|
2026-10-11 17:43:27 +09:00
|
|
|
final host = at < 0
|
|
|
|
|
? Uri.parse(boundary.url).host
|
|
|
|
|
: request.substring(at + 1);
|
2026-10-14 14:08:56 +09:00
|
|
|
shellView.value = ShellView.linkTest;
|
2026-10-11 16:33:55 +09:00
|
|
|
await switch (mode) {
|
|
|
|
|
'dl' => linkTest.runDownload(host, label),
|
|
|
|
|
'bi' => linkTest.runBurstIdle(host, label),
|
|
|
|
|
_ => linkTest.run(host, label),
|
|
|
|
|
};
|
2026-10-11 15:55:52 +09:00
|
|
|
await usb.bindFor(Uri.parse(boundary.url));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
usb.onLinkTest = runLinkTest;
|
2026-10-14 14:08:56 +09:00
|
|
|
runApp(
|
|
|
|
|
YukartApp(boundary: boundary, usb: usb, linkTest: linkTest, themes: themes),
|
|
|
|
|
);
|
2026-10-11 15:55:52 +09:00
|
|
|
final pending = await usb.takeLinkTest();
|
|
|
|
|
if (pending != null) {
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) => runLinkTest(pending));
|
|
|
|
|
}
|
2026-09-05 13:50:51 +09:00
|
|
|
}
|
|
|
|
|
|
2026-10-09 20:23:00 +09:00
|
|
|
class YukartApp extends StatelessWidget {
|
2026-10-11 17:43:27 +09:00
|
|
|
const YukartApp({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.boundary,
|
|
|
|
|
required this.usb,
|
|
|
|
|
required this.linkTest,
|
2026-10-14 14:08:56 +09:00
|
|
|
required this.themes,
|
2026-10-11 17:43:27 +09:00
|
|
|
});
|
2026-10-09 20:23:00 +09:00
|
|
|
final Boundary boundary;
|
|
|
|
|
final UsbLink usb;
|
2026-10-11 15:55:52 +09:00
|
|
|
final LinkTest linkTest;
|
2026-10-14 14:08:56 +09:00
|
|
|
final Themes themes;
|
2026-09-05 13:50:51 +09:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2026-10-13 23:25:28 +09:00
|
|
|
// Every page takes its colours from the palette; switching dark/bright rebuilds them all.
|
|
|
|
|
return ListenableBuilder(
|
|
|
|
|
listenable: themes,
|
|
|
|
|
builder: (context, _) => MaterialApp(
|
|
|
|
|
title: 'Yukart',
|
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
|
theme: themes.material(),
|
|
|
|
|
builder: (context, child) =>
|
|
|
|
|
AppTheme(palette: themes.current, child: child!),
|
2026-10-14 14:08:56 +09:00
|
|
|
home: AppShell(
|
|
|
|
|
boundary: boundary,
|
|
|
|
|
usb: usb,
|
|
|
|
|
linkTest: linkTest,
|
|
|
|
|
themes: themes,
|
2026-10-13 23:25:28 +09:00
|
|
|
),
|
2026-09-05 13:50:51 +09:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|