diff --git a/app/docker/Dockerfile b/app/docker/Dockerfile index 8b3cf479..44b1f602 100644 --- a/app/docker/Dockerfile +++ b/app/docker/Dockerfile @@ -24,10 +24,18 @@ COPY --chmod=0755 build.sh /usr/local/bin/pipelines-app-build WORKDIR /tmp FROM web AS linux +# Flutter's CMake backend passes `-dTreeShakeIcons="true"` with the quotes +# kept (no shell parses them), so `flutter build linux` never tree-shakes the +# icon fonts and ships the full 1.6 MB MaterialIcons font. Pass the plain value +# in this image's copy; the grep fails the build if the line ever changes. RUN apt-get update \ && apt-get install -y --no-install-recommends clang cmake ninja-build pkg-config libgtk-3-dev libstdc++-12-dev liblzma-dev \ && rm -rf /var/lib/apt/lists/* \ && flutter precache --linux \ + && backend=/opt/flutter/packages/flutter_tools/bin/tool_backend.dart \ + && grep -q "'-dTreeShakeIcons=\"\$treeShakeIcons\"'," "$backend" \ + && sed -i "s/'-dTreeShakeIcons=\"\$treeShakeIcons\"',/'-dTreeShakeIcons=\$treeShakeIcons',/" "$backend" \ + && grep -q "'-dTreeShakeIcons=\$treeShakeIcons'," "$backend" \ && chmod -R a+rwX /opt/flutter /home/builder FROM web AS android diff --git a/app/docker/build.sh b/app/docker/build.sh index 8f30af2d..11e2b78f 100755 --- a/app/docker/build.sh +++ b/app/docker/build.sh @@ -42,8 +42,12 @@ PROPERTIES /tmp/apk-certificates.txt > /out/signing-certificate-sha256.txt ;; linux) - flutter build linux --release "$@" + # Dart symbols go beside the bundle, not into libapp.so (about 18% + # smaller); `flutter symbolize -i -d .debug-info/app.linux-x64.symbols` + # reads a release stack trace. Icon fonts are tree-shaken (see Dockerfile). + flutter build linux --release --split-debug-info=/tmp/debug-info "$@" cp -a build/linux/x64/release/bundle/. /out/ + cp -a /tmp/debug-info /out/.debug-info ;; *) echo "unknown build: $kind" >&2 diff --git a/app/lib/features/artifacts/actions/artifact_transfer_io.dart b/app/lib/features/artifacts/actions/artifact_transfer_io.dart index 5fb3ccb9..52b57b13 100644 --- a/app/lib/features/artifacts/actions/artifact_transfer_io.dart +++ b/app/lib/features/artifacts/actions/artifact_transfer_io.dart @@ -1,18 +1,25 @@ import 'package:file_picker/file_picker.dart'; +import 'package:flutter/foundation.dart'; import 'package:share_plus/share_plus.dart'; import 'artifact_file.dart'; import 'artifact_transfer.dart'; /// Phones and desktops: Download asks where to save the exact bytes (the -/// system "Save as"), Share hands the named file to the share sheet. +/// system "Save as"; on Linux the desktop portal's file chooser), Share hands +/// the named file to the share sheet. Linux has no share sheet for files +/// (share_plus throws), so Share is not offered there. bool get artifactDownloadSupported => true; -bool get artifactShareSupported => true; +bool get artifactShareSupported => + defaultTargetPlatform != TargetPlatform.linux; String get artifactDownloadUnsupportedMessage => ''; -String get artifactShareUnsupportedMessage => ''; +String get artifactShareUnsupportedMessage => + defaultTargetPlatform == TargetPlatform.linux + ? 'Sharing files is not available on Linux; use Download.' + : ''; Future saveArtifactFile(ArtifactFile file) async { try { diff --git a/app/lib/features/artifacts/ui/artifact_html_view_native.dart b/app/lib/features/artifacts/ui/artifact_html_view_native.dart index fd61d5fe..cdf62172 100644 --- a/app/lib/features/artifacts/ui/artifact_html_view_native.dart +++ b/app/lib/features/artifacts/ui/artifact_html_view_native.dart @@ -12,6 +12,18 @@ import 'artifact_external_open.dart'; /// 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. /// @@ -99,6 +111,7 @@ class _InertHtmlViewState extends State { @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); @@ -106,8 +119,20 @@ class _InertHtmlViewState extends State { } @override - Widget build(BuildContext context) => WebViewWidget( - controller: _controller, - gestureRecognizers: widget.interactive ? _allGestures : _inlineGestures, - ); + 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, + ), + ), + ); } diff --git a/app/lib/features/attention/notify/notification_bridge_io.dart b/app/lib/features/attention/notify/notification_bridge_io.dart index 696df157..6c35f865 100644 --- a/app/lib/features/attention/notify/notification_bridge_io.dart +++ b/app/lib/features/attention/notify/notification_bridge_io.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:flutter/foundation.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'notification_bridge.dart'; @@ -7,8 +8,10 @@ import 'notification_models.dart'; /// System notifications from the native app: Android's notification shade (when /// its background notification service is off), iOS's and macOS's -/// notification centre. [close] removes a delivered one by its tag. The permission is cached so [environment] stays synchronous; it -/// is refreshed when the bridge starts and after every request. +/// notification centre, and the Linux desktop's notification daemon (the +/// freedesktop D-Bus service: mako, dunst, GNOME Shell, Plasma). [close] +/// removes a delivered one by its tag. The permission is cached so +/// [environment] stays synchronous; it is refreshed when the bridge starts and after every request. class NativeNotificationBridge implements NotificationBridge { NativeNotificationBridge() { _ready = _start(); @@ -40,13 +43,27 @@ class NativeNotificationBridge implements NotificationBridge { requestSoundPermission: false, ); + /// The bundle's icon (installed by the Linux runner's CMake beside + /// `flutter_assets`), so a portable, uninstalled bundle has one too. + static final _linuxSettings = LinuxInitializationSettings( + defaultActionName: 'Open', + defaultIcon: FilePathLinuxIcon( + '${File(Platform.resolvedExecutable).parent.path}/data/app_icon.png', + ), + ); + + /// The Linux app, by its target platform rather than the host's, so a test + /// on a Linux machine still sees the (Android) test platform. + static bool get _linux => defaultTargetPlatform == TargetPlatform.linux; + Future _start() async { try { await _plugin.initialize( - settings: const InitializationSettings( + settings: InitializationSettings( android: AndroidInitializationSettings('@mipmap/ic_launcher'), iOS: _darwin, macOS: _darwin, + linux: _linuxSettings, ), onDidReceiveNotificationResponse: (response) { final id = response.id; @@ -63,7 +80,10 @@ class NativeNotificationBridge implements NotificationBridge { } Future _refresh() async { - if (Platform.isAndroid) { + if (_linux) { + // A notification daemon asks no permission. + _permission = 'granted'; + } else if (Platform.isAndroid) { final enabled = await _plugin .resolvePlatformSpecificImplementation< AndroidFlutterLocalNotificationsPlugin @@ -82,7 +102,8 @@ class NativeNotificationBridge implements NotificationBridge { @override NotificationEnvironment environment() => NotificationEnvironment( - supported: Platform.isAndroid || Platform.isIOS || Platform.isMacOS, + supported: + Platform.isAndroid || Platform.isIOS || Platform.isMacOS || _linux, // A native app needs no secure origin. secureContext: true, permission: _permission, diff --git a/app/lib/features/chat/domain/chat_clipboard_paste_native.dart b/app/lib/features/chat/domain/chat_clipboard_paste_native.dart index 786469a1..ac93aa3d 100644 --- a/app/lib/features/chat/domain/chat_clipboard_paste_native.dart +++ b/app/lib/features/chat/domain/chat_clipboard_paste_native.dart @@ -7,7 +7,9 @@ import 'package:flutter/widgets.dart'; import 'chat_attachment_picker.dart'; import 'chat_clipboard_paste.dart'; -/// The macOS Runner's pasteboard reader (macos/Runner/MainFlutterWindow.swift). +/// The desktop Runners' clipboard reader: macOS's +/// (macos/Runner/MainFlutterWindow.swift) and Linux's +/// (linux/runner/clipboard_files.cc). const MethodChannel chatClipboardFilesChannel = MethodChannel( 'pipelines/clipboard_files', ); @@ -17,7 +19,7 @@ const MethodChannel chatClipboardFilesChannel = MethodChannel( /// /// Flutter's own [Clipboard] carries text only, so a native host reads the /// pasteboard through the Runner. Each subscription watches for the platform -/// paste shortcut (Cmd+V). When its composer may take the paste it consumes +/// paste shortcut (Cmd+V on macOS, Ctrl+V on Linux). When its composer may take the paste it consumes /// the key, asks the Runner for the pasteboard's files (Finder file URLs, else /// a copied or screenshot image) and hands them over; a pasteboard without /// files pastes its text into the composer instead, so the consumed key never @@ -46,13 +48,14 @@ ChatClipboardPaste nativeChatClipboardPaste({ ); /// Whether the held modifiers make V the host's paste shortcut: Cmd alone on -/// macOS. -bool chatIsNativePasteShortcut() { +/// macOS; Ctrl on Linux, also with Super held (Omarchy's universal Super+V +/// sends Ctrl+V while Super is down). +bool chatIsNativePasteShortcut([TargetPlatform? platform]) { final keys = HardwareKeyboard.instance; - return keys.isMetaPressed && - !keys.isControlPressed && - !keys.isAltPressed && - !keys.isShiftPressed; + if (keys.isAltPressed || keys.isShiftPressed) return false; + return (platform ?? defaultTargetPlatform) == TargetPlatform.linux + ? keys.isControlPressed + : keys.isMetaPressed && !keys.isControlPressed; } Future _readPasteboard( @@ -121,4 +124,5 @@ String chatNothingToPasteMessage(List types) => types.isEmpty /// Whether [platform] has a Runner that answers [chatClipboardFilesChannel]. bool chatHostReadsClipboardFiles(TargetPlatform platform) => - !kIsWeb && platform == TargetPlatform.macOS; + !kIsWeb && + (platform == TargetPlatform.macOS || platform == TargetPlatform.linux); diff --git a/app/lib/features/chat/domain/chat_clipboard_paste_stub.dart b/app/lib/features/chat/domain/chat_clipboard_paste_stub.dart index e93ec3ec..d62fe93a 100644 --- a/app/lib/features/chat/domain/chat_clipboard_paste_stub.dart +++ b/app/lib/features/chat/domain/chat_clipboard_paste_stub.dart @@ -5,7 +5,7 @@ import 'chat_clipboard_paste_native.dart'; /// Native clipboard-file paste. /// -/// macOS reads the pasteboard through its Runner +/// macOS and Linux read the clipboard through their Runners /// ([nativeChatClipboardPaste]). Other native hosts have no pasteboard reader /// yet: they report that missing capability rather than pretending no paste /// happened, and the composer keeps the host field's own text paste. diff --git a/app/linux/CMakeLists.txt b/app/linux/CMakeLists.txt index ae9c0a53..daefc140 100644 --- a/app/linux/CMakeLists.txt +++ b/app/linux/CMakeLists.txt @@ -97,6 +97,11 @@ install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) +# The window icon (runner/my_application.cc); the installer also puts it in +# the icon theme for the desktop entry. +install(FILES "runner/resources/app_icon.png" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) diff --git a/app/linux/runner/CMakeLists.txt b/app/linux/runner/CMakeLists.txt index e97dabc7..d3a40c79 100644 --- a/app/linux/runner/CMakeLists.txt +++ b/app/linux/runner/CMakeLists.txt @@ -9,6 +9,7 @@ project(runner LANGUAGES CXX) add_executable(${BINARY_NAME} "main.cc" "my_application.cc" + "clipboard_files.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) diff --git a/app/linux/runner/clipboard_files.cc b/app/linux/runner/clipboard_files.cc new file mode 100644 index 00000000..289a60d7 --- /dev/null +++ b/app/linux/runner/clipboard_files.cc @@ -0,0 +1,135 @@ +#include "clipboard_files.h" + +#include +#include + +namespace { + +FlMethodChannel* channel = nullptr; + +// The MIME type of [path] from its name and contents, or "". +gchar* mime_of(const gchar* path, const guchar* data, gsize length) { + gboolean uncertain = FALSE; + g_autofree gchar* type = + g_content_type_guess(path, data, MIN(length, (gsize)4096), &uncertain); + gchar* mime = type == nullptr ? nullptr : g_content_type_get_mime_type(type); + return mime == nullptr ? g_strdup("") : mime; +} + +FlValue* file_entry(const gchar* name, const gchar* mime, const guchar* data, + gsize length) { + FlValue* entry = fl_value_new_map(); + fl_value_set_string_take(entry, "name", fl_value_new_string(name)); + fl_value_set_string_take(entry, "mime", fl_value_new_string(mime)); + fl_value_set_string_take(entry, "bytes", + fl_value_new_uint8_list(data, length)); + return entry; +} + +// Adds each copied local file; folders and unreadable files become errors. +gboolean add_uris(GtkClipboard* clipboard, FlValue* files, FlValue* errors) { + g_auto(GStrv) uris = gtk_clipboard_wait_for_uris(clipboard); + if (uris == nullptr || uris[0] == nullptr) return FALSE; + gboolean any = FALSE; + for (gchar** uri = uris; *uri != nullptr; uri++) { + g_autofree gchar* path = g_filename_from_uri(*uri, nullptr, nullptr); + if (path == nullptr) continue; + any = TRUE; + g_autofree gchar* name = g_path_get_basename(path); + if (g_file_test(path, G_FILE_TEST_IS_DIR)) { + g_autofree gchar* message = + g_strdup_printf("%s is a folder; paste its files instead.", name); + fl_value_append_take(errors, fl_value_new_string(message)); + continue; + } + g_autofree gchar* contents = nullptr; + gsize length = 0; + g_autoptr(GError) error = nullptr; + if (!g_file_get_contents(path, &contents, &length, &error)) { + g_autofree gchar* message = + g_strdup_printf("Could not read %s: %s", name, error->message); + fl_value_append_take(errors, fl_value_new_string(message)); + continue; + } + g_autofree gchar* mime = + mime_of(path, reinterpret_cast(contents), length); + fl_value_append_take( + files, file_entry(name, mime, + reinterpret_cast(contents), length)); + } + return any; +} + +// The clipboard's own PNG (a screenshot tool's), else any image GTK can read +// converted to PNG. +void add_image(GtkClipboard* clipboard, FlValue* files) { + g_autoptr(GtkSelectionData) png = gtk_clipboard_wait_for_contents( + clipboard, gdk_atom_intern_static_string("image/png")); + if (png != nullptr && gtk_selection_data_get_length(png) > 0) { + fl_value_append_take( + files, file_entry("", "image/png", gtk_selection_data_get_data(png), + gtk_selection_data_get_length(png))); + return; + } + g_autoptr(GdkPixbuf) image = gtk_clipboard_wait_for_image(clipboard); + if (image == nullptr) return; + g_autofree gchar* buffer = nullptr; + gsize length = 0; + if (gdk_pixbuf_save_to_buffer(image, &buffer, &length, "png", nullptr, + nullptr)) { + fl_value_append_take( + files, file_entry("", "image/png", + reinterpret_cast(buffer), length)); + } +} + +FlValue* read_clipboard() { + GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); + FlValue* files = fl_value_new_list(); + FlValue* errors = fl_value_new_list(); + FlValue* types = fl_value_new_list(); + GdkAtom* targets = nullptr; + gint count = 0; + if (gtk_clipboard_wait_for_targets(clipboard, &targets, &count)) { + for (gint i = 0; i < count; i++) { + g_autofree gchar* name = gdk_atom_name(targets[i]); + fl_value_append_take(types, fl_value_new_string(name)); + } + g_free(targets); + } + if (!add_uris(clipboard, files, errors)) add_image(clipboard, files); + FlValue* reply = fl_value_new_map(); + fl_value_set_string_take(reply, "files", files); + fl_value_set_string_take(reply, "errors", errors); + fl_value_set_string_take(reply, "types", types); + return reply; +} + +void method_call_cb(FlMethodChannel* channel, FlMethodCall* call, + gpointer user_data) { + g_autoptr(FlMethodResponse) response = nullptr; + if (g_strcmp0(fl_method_call_get_name(call), "read") == 0) { + g_autoptr(FlValue) reply = read_clipboard(); + response = FL_METHOD_RESPONSE(fl_method_success_response_new(reply)); + } else { + response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new()); + } + g_autoptr(GError) error = nullptr; + if (!fl_method_call_respond(call, response, &error)) { + g_warning("Failed to answer a clipboard read: %s", error->message); + } +} + +} // namespace + +void clipboard_files_register(FlPluginRegistry* registry) { + g_autoptr(FlPluginRegistrar) registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "ClipboardFiles"); + g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new(); + g_clear_object(&channel); + channel = fl_method_channel_new(fl_plugin_registrar_get_messenger(registrar), + "pipelines/clipboard_files", + FL_METHOD_CODEC(codec)); + fl_method_channel_set_method_call_handler(channel, method_call_cb, nullptr, + nullptr); +} diff --git a/app/linux/runner/clipboard_files.h b/app/linux/runner/clipboard_files.h new file mode 100644 index 00000000..13a21081 --- /dev/null +++ b/app/linux/runner/clipboard_files.h @@ -0,0 +1,12 @@ +#ifndef RUNNER_CLIPBOARD_FILES_H_ +#define RUNNER_CLIPBOARD_FILES_H_ + +#include + +// Answers `read` on the `pipelines/clipboard_files` channel with the +// clipboard's files (a file manager's copied URIs), else its image as PNG, +// plus the clipboard's target names; the same reply shape as the macOS +// Runner (lib/features/chat/domain/chat_clipboard_paste_native.dart). +void clipboard_files_register(FlPluginRegistry* registry); + +#endif // RUNNER_CLIPBOARD_FILES_H_ diff --git a/app/linux/runner/my_application.cc b/app/linux/runner/my_application.cc index cb898c4e..08465cb6 100644 --- a/app/linux/runner/my_application.cc +++ b/app/linux/runner/my_application.cc @@ -6,6 +6,7 @@ #include #endif +#include "clipboard_files.h" #include "flutter/generated_plugin_registrant.h" struct _MyApplication { @@ -15,6 +16,18 @@ struct _MyApplication { G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) +// The bundle's icon (data/app_icon.png beside the executable) for X11 window +// managers and task bars. Wayland compositors take the icon from the desktop +// entry named by the application id instead. +static void set_window_icon(GtkWindow* window) { + g_autofree gchar* executable = g_file_read_link("/proc/self/exe", nullptr); + if (executable == nullptr) return; + g_autofree gchar* directory = g_path_get_dirname(executable); + g_autofree gchar* icon = + g_build_filename(directory, "data", "app_icon.png", nullptr); + gtk_window_set_icon_from_file(window, icon, nullptr); +} + // Called when first Flutter frame received. static void first_frame_cb(MyApplication* self, FlView* view) { gtk_widget_show(gtk_widget_get_toplevel(GTK_WIDGET(view))); @@ -33,21 +46,18 @@ static void my_application_activate(GApplication* application) { ? detached_title : "Pipelines"; - // Use a header bar when running in GNOME as this is the common style used - // by applications and is the setup most users will be using (e.g. Ubuntu - // desktop). - // If running on X and not using GNOME then just use a traditional title bar - // in case the window manager does more exotic layout, e.g. tiling. - // If running on Wayland assume the header bar will work (may need changing - // if future cases occur). - gboolean use_header_bar = TRUE; + // A GTK header bar only on GNOME, whose shell expects client-side title + // bars. Elsewhere (Hyprland, Sway, KDE, any X11 window manager) the window + // takes the compositor's own decorations, or none on a tiling compositor, + // instead of drawing a second title bar inside the tile. + const gchar* desktop = g_getenv("XDG_CURRENT_DESKTOP"); + gboolean use_header_bar = + desktop != nullptr && g_strrstr(desktop, "GNOME") != nullptr; #ifdef GDK_WINDOWING_X11 GdkScreen* screen = gtk_window_get_screen(window); if (GDK_IS_X11_SCREEN(screen)) { const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); - if (g_strcmp0(wm_name, "GNOME Shell") != 0) { - use_header_bar = FALSE; - } + use_header_bar = g_strcmp0(wm_name, "GNOME Shell") == 0; } #endif if (use_header_bar) { @@ -59,6 +69,7 @@ static void my_application_activate(GApplication* application) { } else { gtk_window_set_title(window, title); } + set_window_icon(window); gint width = 1280, height = 720; const gchar* detached_size = g_getenv("PIPELINES_WINDOW_SIZE"); @@ -91,6 +102,7 @@ static void my_application_activate(GApplication* application) { gtk_widget_realize(GTK_WIDGET(view)); fl_register_plugins(FL_PLUGIN_REGISTRY(view)); + clipboard_files_register(FL_PLUGIN_REGISTRY(view)); gtk_widget_grab_focus(GTK_WIDGET(view)); } diff --git a/app/linux/runner/resources/app_icon.png b/app/linux/runner/resources/app_icon.png new file mode 100644 index 00000000..8df1f55e Binary files /dev/null and b/app/linux/runner/resources/app_icon.png differ diff --git a/app/notes/linux-desktop-optimized.md b/app/notes/linux-desktop-optimized.md new file mode 100644 index 00000000..27c8041c --- /dev/null +++ b/app/notes/linux-desktop-optimized.md @@ -0,0 +1,69 @@ +# Linux desktop: optimized build, Linux gaps, bench + +Flutter 3.44.6, Docker build image (`app/docker`), tank (Ryzen, RTX 2080 Ti, +Omarchy/Hyprland). Measured 2026-12-03. + +## Build flags + +- `flutter build linux --release --split-debug-info` (symbols kept in the + build cache as `.debug-info/`, not archived): libapp.so 13.96 MB -> 11.27 MB. +- Icon tree shaking was silently off: Flutter's CMake backend + (`tool_backend.dart`) passes `-dTreeShakeIcons="true"` with literal quotes. + The Linux build image patches its own SDK copy (grep-guarded). + MaterialIcons-Regular.otf 1,645,184 -> 24,952 bytes. +- Bundle 37.1 MiB -> 33.1 MiB; archive 16.1 MB -> 14.3 MB. +- Not used: `--obfuscate` (no speed gain, breaks symbol names in errors); + Impeller (below). + +## Impeller + +The Linux release engine ignores engine switches (`FLUTTER_ENGINE_SWITCHES` +is read only in debug/profile builds) and `FlDartProject` has no Impeller +setter, so a release Linux build cannot opt in. Measured in a profile build +on Xvfb/llvmpipe (`tool/perf/linux_desktop_bench.py`, 3 runs, medians): + +| renderer | startup | scroll frames | raster sum | raster median | worst frame | +|---|---|---|---|---|---| +| Skia (default) | 1553 ms | 31 | 1141 ms | 29.4 ms | 168 ms | +| Impeller GL | 1919 ms | 14 | 1600 ms | 103.5 ms | 302 ms | + +Impeller was slower and dropped frames on the CPU rasteriser; no GPU numbers +(see below). Skia stays. + +## Linux vs web (same fixture, same 30-notch wheel scroll of a rich chat) + +| build | startup / first frame | frames | build sum | build max | raster sum | raster max | +|---|---|---|---|---|---|---| +| Linux release, Xvfb + llvmpipe (CPU), 1280x720 | 1241 ms (process launch) | 43 | 59 ms | 11.0 ms | 1031 ms | 105 ms | +| Web wasm, headless Chromium, no GPU, 1280x800 | 896 ms (navigation) | 57 | 126 ms | 18.3 ms | 2485 ms | 130 ms | +| Web wasm, headless Chromium, GPU, 1280x800 | 278 ms (navigation) | 69 | 128 ms | 10.6 ms | 174 ms | 8.9 ms | + +Medians of 5 runs. Build (UI thread) time is GPU-independent: native +~1.4 ms/frame vs web ~1.9-2.2 ms/frame. Raster on the CPU: native 21 ms median +vs web ~44 ms mean. Native startup counts process launch, GTK, engine and +llvmpipe shader setup; the web figure starts at navigation in a running +browser, so the two are not like for like. +No Linux GPU raster or Wayland numbers: nothing here runs a GPU-backed +headless Wayland or X server (no cage/weston; Xvfb is software only), and the +operator's Hyprland session was not used. + +## Linux gaps fixed + +- Notifications: the bridge reported Linux unsupported; now uses + flutter_local_notifications' D-Bus implementation with the bundle icon. +- HTML artifacts: `WebViewController()` throws on Linux (no webview + implementation); the view now explains and points at Download. +- Share: share_plus throws for files on Linux; Share is no longer offered. +- Clipboard paste of files/screenshots: new GTK reader + (`linux/runner/clipboard_files.cc`) answers `pipelines/clipboard_files`; + Ctrl+V (also Omarchy's Super+V) in the composer. Compiled and contract- + tested in Dart; not exercised against a real clipboard here. +- Window: GTK header bar only on GNOME (no second title bar in a Hyprland + tile); window icon on X11; installer desktop entry `com.pipelines.app.desktop` + = GTK application id = Wayland app id. + +Unchanged and already native: url_launcher (xdg-open plugin), file_picker +(xdg-desktop-portal FileChooser), keyboard shortcuts (Ctrl on non-Apple), +terminal (Dart xterm). The session cookie is stored by shared_preferences +(`~/.local/share/com.pipelines.app/shared_preferences.json`) as on the other +native platforms; there is no keyring-backed storage in the app. diff --git a/app/test/features/artifacts/ui/artifact_linux_capabilities_test.dart b/app/test/features/artifacts/ui/artifact_linux_capabilities_test.dart new file mode 100644 index 00000000..249ffaa2 --- /dev/null +++ b/app/test/features/artifacts/ui/artifact_linux_capabilities_test.dart @@ -0,0 +1,53 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/artifacts/actions/artifact_transfer_io.dart' + as transfer; +import 'package:pipelines_app/features/artifacts/ui/artifact_html_view_native.dart'; + +final _linux = TargetPlatformVariant.only(TargetPlatform.linux); + +/// The Linux app has no web view and no file share sheet: it says so rather +/// than failing to create the web view or throwing from Share. +void main() { + test('only Android, iOS and macOS have the HTML web view', () { + for (final platform in TargetPlatform.values) { + expect( + inertHtmlViewSupported(platform), + platform == TargetPlatform.android || + platform == TargetPlatform.iOS || + platform == TargetPlatform.macOS, + reason: '$platform', + ); + } + }); + + testWidgets('an HTML artifact on Linux explains why it is not previewed', ( + tester, + ) async { + await tester.pumpWidget( + const MaterialApp( + home: Scaffold(body: InertHtmlView(html: '

report

')), + ), + ); + expect(find.text(inertHtmlUnsupportedMessage), findsOneWidget); + expect(tester.takeException(), isNull); + // A new document does not reach for a web view either. + await tester.pumpWidget( + const MaterialApp( + home: Scaffold(body: InertHtmlView(html: '

next

')), + ), + ); + expect(tester.takeException(), isNull); + }, variant: _linux); + + testWidgets('Linux offers Download but not Share', (tester) async { + expect(transfer.artifactDownloadSupported, isTrue); + expect(transfer.artifactShareSupported, isFalse); + expect(transfer.artifactShareUnsupportedMessage, contains('Download')); + }, variant: _linux); + + test('other native platforms keep Share', () { + expect(transfer.artifactShareSupported, isTrue); + expect(transfer.artifactShareUnsupportedMessage, isEmpty); + }); +} diff --git a/app/test/features/chat/conversation/chat_composer_injected_paste_test.dart b/app/test/features/chat/conversation/chat_composer_injected_paste_test.dart index 7bdf1abd..76290206 100644 --- a/app/test/features/chat/conversation/chat_composer_injected_paste_test.dart +++ b/app/test/features/chat/conversation/chat_composer_injected_paste_test.dart @@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart'; import 'package:pipelines_app/features/chat/conversation/chat_composer_controller.dart'; import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart'; +import 'package:pipelines_app/features/chat/domain/chat_clipboard_paste_native.dart'; import '../../../core/keyboard/browser_keys.dart'; import 'chat_composer_bar_fixtures.dart'; @@ -32,6 +33,12 @@ void main() { if (call.method == 'Clipboard.hasStrings') return {'value': true}; return null; }); + // The Linux Runner's clipboard reader: no files, so the text is pasted. + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler( + chatClipboardFilesChannel, + (call) async => {'files': const [], 'errors': const []}, + ); }); tearDown(() { @@ -39,6 +46,8 @@ void main() { gateway.close(); TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler(SystemChannels.platform, null); + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(chatClipboardFilesChannel, null); }); for (final merged in [false, true]) { diff --git a/app/test/features/chat/domain/chat_clipboard_paste_native_test.dart b/app/test/features/chat/domain/chat_clipboard_paste_native_test.dart index 497813eb..baee7524 100644 --- a/app/test/features/chat/domain/chat_clipboard_paste_native_test.dart +++ b/app/test/features/chat/domain/chat_clipboard_paste_native_test.dart @@ -10,6 +10,7 @@ import 'package:pipelines_app/features/chat/domain/chat_clipboard_paste_native.d import '../conversation/chat_composer_bar_fixtures.dart'; final _macOS = TargetPlatformVariant.only(TargetPlatform.macOS); +final _linux = TargetPlatformVariant.only(TargetPlatform.linux); Finder get _field => find.byKey(const Key('chat-composer-field')); @@ -77,10 +78,10 @@ void main() { Future done(WidgetTester tester) => tester.pumpWidget(const SizedBox()); - test('only the macOS host reads clipboard files natively', () { + test('the macOS and Linux hosts read clipboard files natively', () { expect(chatHostReadsClipboardFiles(TargetPlatform.macOS), isTrue); + expect(chatHostReadsClipboardFiles(TargetPlatform.linux), isTrue); for (final platform in [ - TargetPlatform.linux, TargetPlatform.windows, TargetPlatform.android, TargetPlatform.iOS, @@ -228,4 +229,47 @@ void main() { expect(composer.draft, isEmpty); await done(tester); }, variant: _macOS); + + testWidgets('Ctrl+V attaches a copied screenshot on Linux', (tester) async { + pasteboard = { + 'files': [ + { + 'name': '', + 'mime': 'image/png', + 'bytes': Uint8List.fromList([3]), + }, + ], + 'errors': const [], + }; + expect(hostChatClipboardPaste.isSupported, isTrue); + await mount(tester); + await tester.showKeyboard(_field); + await tester.pump(); + await paste(tester, modifier: LogicalKeyboardKey.controlLeft); + + expect(fileReads, 1); + expect(find.text('pasted-1.png'), findsOneWidget); + expect(textReads, 0); + await done(tester); + }, variant: _linux); + + testWidgets('Ctrl+V of plain text on Linux pastes it once', (tester) async { + await mount(tester); + await tester.showKeyboard(_field); + await paste(tester, modifier: LogicalKeyboardKey.controlLeft); + + expect(fileReads, 1); + expect(composer.draft, 'copied text'); + await done(tester); + }, variant: _linux); + + testWidgets('the Super key is not the Linux paste shortcut', (tester) async { + await mount(tester); + FocusManager.instance.primaryFocus?.unfocus(); + await tester.pump(); + await paste(tester); + + expect(fileReads, 0); + await done(tester); + }, variant: _linux); } diff --git a/app/tool/fixture_host/fixture_host_native.dart b/app/tool/fixture_host/fixture_host_native.dart index 5fa945ea..d1f0039f 100644 --- a/app/tool/fixture_host/fixture_host_native.dart +++ b/app/tool/fixture_host/fixture_host_native.dart @@ -4,6 +4,7 @@ import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:pipelines_app/application/server_endpoint.dart'; +import '../perf/frame_log_native.dart'; import 'fixture_steps.dart'; import 'narrow_view.dart'; @@ -31,8 +32,10 @@ Map fixtureParams() { return raw.isEmpty ? const {} : Uri.splitQueryString(raw); } -/// The DevTools probes are browser-only. -void installHostProbes(Map params) {} +/// The DevTools probes are browser-only; `perf=1` prints frame timings to +/// stdout (tool/perf/frame_log_native.dart). +void installHostProbes(Map params) => + installNativeFrameLog(params); /// The route goes through [fixtureRouteProvider] instead. void openFixtureRoute(String route) {} diff --git a/app/tool/fixture_host/fixture_steps.dart b/app/tool/fixture_host/fixture_steps.dart index e3603649..02099676 100644 --- a/app/tool/fixture_host/fixture_steps.dart +++ b/app/tool/fixture_host/fixture_steps.dart @@ -9,7 +9,10 @@ import 'package:flutter/services.dart'; /// [script] is `;`-separated steps run after the first frame, 700 ms apart: /// `wait:`, `tap: