8138cdc3d9
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>
139 lines
4.9 KiB
Dart
139 lines
4.9 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/gestures.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:webview_flutter/webview_flutter.dart';
|
|
|
|
import '../domain/artifact_html_links.dart';
|
|
import '../domain/artifact_html_theme.dart';
|
|
import 'artifact_external_open.dart';
|
|
|
|
/// The mobile web views pinch-zoom natively (Android's built-in zoom, which
|
|
/// the plugin turns on with its display controls hidden; WKWebView's own), so
|
|
/// the full-screen view needs no zoom buttons.
|
|
const bool inertHtmlZoomButtons = false;
|
|
|
|
/// The webview plugin has Android, iOS and macOS implementations only; the
|
|
/// Linux and Windows apps say so instead of failing to create a web view.
|
|
bool inertHtmlViewSupported([TargetPlatform? platform]) => switch (platform ??
|
|
defaultTargetPlatform) {
|
|
TargetPlatform.android || TargetPlatform.iOS || TargetPlatform.macOS => true,
|
|
_ => false,
|
|
};
|
|
|
|
const String inertHtmlUnsupportedMessage =
|
|
'This app cannot preview HTML on this platform: it has no web view. '
|
|
'Download the file to open it in a browser.';
|
|
|
|
/// A web view with JavaScript disabled that refuses every navigation after the
|
|
/// recorded document itself loads.
|
|
///
|
|
/// A platform view only receives the pointers of gestures that its
|
|
/// [WebViewWidget.gestureRecognizers] win in Flutter's gesture arena. With
|
|
/// none it got a drag only after every other recognizer gave up, which the
|
|
/// viewer's page swipe never does before the finger lifts: the document never
|
|
/// scrolled or pinched. Inline it claims vertical drags (scrolling the
|
|
/// document) and leaves horizontal ones to the page swipe; [interactive] (the
|
|
/// full-screen view) claims every pointer at once, so scroll, pan and pinch
|
|
/// all reach the document.
|
|
class InertHtmlView extends StatefulWidget {
|
|
const InertHtmlView({
|
|
super.key,
|
|
required this.html,
|
|
this.interactive = false,
|
|
this.zoom,
|
|
this.openExternal = openArtifactExternally,
|
|
this.dark = false,
|
|
});
|
|
|
|
final String html;
|
|
|
|
/// Whether the app is in its dark theme: a document that supports dark mode
|
|
/// is loaded in it ([artifactHtmlForScheme]).
|
|
final bool dark;
|
|
|
|
/// Opens a link's http(s)/mailto address outside the artifact.
|
|
final ArtifactExternalOpen openExternal;
|
|
final bool interactive;
|
|
|
|
/// Unused: the mobile web views pinch instead ([inertHtmlZoomButtons]).
|
|
final ValueListenable<double>? zoom;
|
|
|
|
@override
|
|
State<InertHtmlView> createState() => _InertHtmlViewState();
|
|
}
|
|
|
|
final _inlineGestures = <Factory<OneSequenceGestureRecognizer>>{
|
|
Factory<VerticalDragGestureRecognizer>(VerticalDragGestureRecognizer.new),
|
|
};
|
|
|
|
final _allGestures = <Factory<OneSequenceGestureRecognizer>>{
|
|
Factory<EagerGestureRecognizer>(EagerGestureRecognizer.new),
|
|
};
|
|
|
|
class _InertHtmlViewState extends State<InertHtmlView> {
|
|
/// Until the recorded document finishes loading, the view may load it (an
|
|
/// `about:` or `data:` document); afterwards only links are followed.
|
|
bool _loaded = false;
|
|
|
|
late final WebViewController _controller = WebViewController()
|
|
..setJavaScriptMode(JavaScriptMode.disabled)
|
|
..enableZoom(true)
|
|
..setNavigationDelegate(
|
|
NavigationDelegate(
|
|
onPageFinished: (_) => _loaded = true,
|
|
onNavigationRequest: _decide,
|
|
),
|
|
)
|
|
..loadHtmlString(_document);
|
|
|
|
String get _document => artifactHtmlForScheme(widget.html, dark: widget.dark);
|
|
|
|
/// Links: a place in the document scrolls there; an http(s)/mailto address
|
|
/// opens in the system's handler, never inside this view; anything else
|
|
/// (scripts, files, other schemes, relative paths) stays inert.
|
|
NavigationDecision _decide(NavigationRequest request) {
|
|
if (!_loaded &&
|
|
(request.url.startsWith('about:') || request.url.startsWith('data:'))) {
|
|
return NavigationDecision.navigate;
|
|
}
|
|
switch (artifactHtmlLinkAction(request.url)) {
|
|
case ArtifactHtmlLinkAction.inDocument:
|
|
return NavigationDecision.navigate;
|
|
case ArtifactHtmlLinkAction.external:
|
|
final uri = Uri.tryParse(request.url.trim());
|
|
if (uri != null) widget.openExternal(uri);
|
|
return NavigationDecision.prevent;
|
|
case ArtifactHtmlLinkAction.blocked:
|
|
return NavigationDecision.prevent;
|
|
}
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant InertHtmlView oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (!inertHtmlViewSupported()) return;
|
|
if (oldWidget.html != widget.html || oldWidget.dark != widget.dark) {
|
|
_loaded = false;
|
|
_controller.loadHtmlString(_document);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => inertHtmlViewSupported()
|
|
? WebViewWidget(
|
|
controller: _controller,
|
|
gestureRecognizers: widget.interactive
|
|
? _allGestures
|
|
: _inlineGestures,
|
|
)
|
|
: const Center(
|
|
child: Padding(
|
|
padding: EdgeInsets.all(16),
|
|
child: Text(
|
|
inertHtmlUnsupportedMessage,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
);
|
|
}
|