Files
pipelines/app/tool/fixture_host/fixture_steps.dart
T
alan 8138cdc3d9 Linux desktop: optimized release build, installer, Linux gaps
Build: split Dart debug info out of libapp.so (13.96 -> 11.27 MB, symbols
kept in the cache) and fix icon tree shaking, which Flutter 3.44's Linux
CMake backend silently disables by quoting the define; the build image
patches its SDK copy (MaterialIcons 1.6 MB -> 25 KB). Impeller cannot be
enabled in a Linux release build and was slower in a profile-build bench.

Install: `./install --linux --install` installs the bundle into
<prefix>/lib/app-linux with com.pipelines.app.desktop (the GTK/Wayland
app id), its icon and a ~/.local/bin/pipelines-app link, through
scripts/install-linux-app.sh.

Linux gaps: notifications through the freedesktop daemon; HTML artifacts
explain the missing web view instead of throwing; no Share for files;
a GTK clipboard reader for pasting files and screenshots (Ctrl+V and
Omarchy's Super+V); GTK header bar only on GNOME; window icon.

Bench: native fixture frame log, wheel/mark steps and
tool/perf/linux_desktop_bench.py (private Xvfb); results in
app/notes/linux-desktop-optimized.md.

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

189 lines
6.2 KiB
Dart

import 'dart:async';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
/// A tiny in-app driver for simulator captures, where `simctl` cannot tap.
///
/// [script] is `;`-separated steps run after the first frame, 700 ms apart:
/// `wait:<ms>`, `tap:<label>` (a Text, Tooltip, Semantics label or field
/// hint; `tap:<label>#<n>` picks the n-th match), `tapxy:<x>,<y>`,
/// `drag:<x>,<y>,<dx>,<dy>`, `wheel:<x>,<y>,<dy>,<count>` (mouse-wheel
/// notches 16 ms apart, as the web interaction bench sends), `mark:<name>`
/// (prints `FIXTURE_MARK <name>`, so a bench can tell its phases apart),
/// `type:<text>` (into the focused field; `\n`
/// is a newline), `orient:landscape|portrait` and `labels` (prints the
/// visible labels with their centres to the device log).
void runFixtureSteps(String script) {
final steps = [
for (final step in script.split(';'))
if (step.trim().isNotEmpty) step.trim(),
];
if (steps.isEmpty) return;
WidgetsBinding.instance.waitUntilFirstFrameRasterized.then((_) async {
await Future<void>.delayed(const Duration(milliseconds: 1500));
for (final step in steps) {
final colon = step.indexOf(':');
final verb = colon < 0 ? step : step.substring(0, colon);
final value = colon < 0 ? '' : step.substring(colon + 1);
try {
await _run(verb, value);
} catch (error) {
// ignore: avoid_print
print('FIXTURE_STEP_FAILED $step: $error');
}
await Future<void>.delayed(const Duration(milliseconds: 700));
}
// ignore: avoid_print
print('FIXTURE_STEPS_DONE');
});
}
Future<void> _run(String verb, String value) async {
switch (verb) {
case 'wait':
await Future<void>.delayed(Duration(milliseconds: int.parse(value)));
case 'tap':
final hash = value.lastIndexOf('#');
final index = hash < 0 ? 0 : int.parse(value.substring(hash + 1));
final label = hash < 0 ? value : value.substring(0, hash);
final hits = _find(label);
if (hits.length <= index) throw StateError('no "$label"');
await _tap(hits[index].center);
case 'tapxy':
final parts = value.split(',').map(double.parse).toList();
await _tap(Offset(parts[0], parts[1]));
case 'drag':
final p = value.split(',').map(double.parse).toList();
await _drag(Offset(p[0], p[1]), Offset(p[2], p[3]));
case 'mark':
// ignore: avoid_print
print('FIXTURE_MARK $value');
case 'wheel':
final p = value.split(',').map(double.parse).toList();
await _wheel(Offset(p[0], p[1]), p[2], p[3].toInt());
case 'type':
_type(value.replaceAll(r'\n', '\n'));
case 'orient':
await SystemChrome.setPreferredOrientations(
value == 'landscape'
? [DeviceOrientation.landscapeLeft]
: [DeviceOrientation.portraitUp],
);
case 'labels':
for (final hit in _find(null)) {
// ignore: avoid_print
print('FIXTURE_LABEL ${hit.label} @ ${hit.center}');
}
default:
throw StateError('unknown step');
}
}
class _Hit {
_Hit(this.label, this.center);
final String label;
final Offset center;
}
String? _labelOf(Widget widget) => switch (widget) {
Text(:final data?) => data,
Text(:final textSpan?) => textSpan.toPlainText(),
Tooltip(:final message?) => message,
Semantics(:final properties) => properties.label,
Icon(:final semanticLabel?) => semanticLabel,
InputDecorator(:final decoration) =>
decoration.hintText ?? decoration.labelText,
_ => null,
};
/// Visible widgets labelled [label] (every labelled one when null).
List<_Hit> _find(String? label) {
final hits = <_Hit>[];
final size = WidgetsBinding.instance.renderViews.first.size;
void visit(Element element) {
final text = _labelOf(element.widget);
if (text != null && (label == null || text == label)) {
final box = element.findRenderObject();
if (box is RenderBox && box.attached && box.hasSize) {
final center = box.localToGlobal(box.size.center(Offset.zero));
if ((Offset.zero & size).contains(center)) hits.add(_Hit(text, center));
}
}
element.visitChildren(visit);
}
WidgetsBinding.instance.rootElement?.visitChildren(visit);
return hits;
}
var _pointer = 900;
Future<void> _tap(Offset at) async {
final pointer = ++_pointer;
final binding = GestureBinding.instance;
binding.handlePointerEvent(PointerDownEvent(pointer: pointer, position: at));
await Future<void>.delayed(const Duration(milliseconds: 60));
binding.handlePointerEvent(PointerUpEvent(pointer: pointer, position: at));
}
Future<void> _drag(Offset from, Offset by) async {
final pointer = ++_pointer;
final binding = GestureBinding.instance;
binding.handlePointerEvent(
PointerDownEvent(pointer: pointer, position: from),
);
const moves = 16;
for (var i = 1; i <= moves; i++) {
await Future<void>.delayed(const Duration(milliseconds: 16));
binding.handlePointerEvent(
PointerMoveEvent(
pointer: pointer,
position: from + by * (i / moves),
delta: by / moves.toDouble(),
),
);
}
binding.handlePointerEvent(
PointerUpEvent(pointer: pointer, position: from + by),
);
}
Future<void> _wheel(Offset at, double dy, int count) async {
final binding = GestureBinding.instance;
for (var i = 0; i < count; i++) {
binding.handlePointerEvent(
PointerScrollEvent(
kind: PointerDeviceKind.mouse,
position: at,
scrollDelta: Offset(0, dy),
),
);
await Future<void>.delayed(const Duration(milliseconds: 16));
}
}
void _type(String text) {
EditableTextState? focused;
void visit(Element element) {
if (element is StatefulElement &&
element.state is EditableTextState &&
(element.widget as EditableText).focusNode.hasFocus) {
focused = element.state as EditableTextState;
}
element.visitChildren(visit);
}
WidgetsBinding.instance.rootElement?.visitChildren(visit);
final state = focused;
if (state == null) throw StateError('no focused field');
state.userUpdateTextEditingValue(
TextEditingValue(
text: text,
selection: TextSelection.collapsed(offset: text.length),
),
SelectionChangedCause.keyboard,
);
}