### Installation: Install Executable Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_testbed/linux/CMakeLists.txt Installs the main application executable to the specified destination within the bundle. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Installation: Install Bundled Plugin Libraries Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_testbed/linux/CMakeLists.txt Iterates through a list of bundled plugin libraries and installs each one to the library directory within the bundle. ```cmake foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Installation: Initialize Install Prefix Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_testbed/linux/CMakeLists.txt Sets the installation prefix to a bundle directory within the build directory by default, unless it's explicitly initialized to '/usr/local' or the user has set it. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR CMAKE_INSTALL_PREFIX STREQUAL "/usr/local") set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() ``` -------------------------------- ### Installation: Install Flutter Library Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_testbed/linux/CMakeLists.txt Installs the main Flutter library file to the library directory within the bundle. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Installation Configuration Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_example/linux/CMakeLists.txt Configures the installation prefix and defines directories for bundle data and libraries. It also ensures a clean build bundle directory on each installation. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR CMAKE_INSTALL_PREFIX STREQUAL "/usr/local") set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Installation: Define Bundle Data and Library Directories Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_testbed/linux/CMakeLists.txt Sets variables for the installation paths of data and library files within the application bundle. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Installation: Install Native Assets Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_testbed/linux/CMakeLists.txt Installs native assets provided by build.dart from all packages to the library directory within the bundle. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Application Target and Assets Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_example/linux/CMakeLists.txt Installs the main application executable, Flutter ICU data, Flutter library, and bundled plugin libraries to the specified installation directories. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Install WebKitGTK on Ubuntu Source: https://github.com/dizitart/papyrus/blob/main/packages/papyrus_linux/README.md Use this command to install the necessary WebKitGTK package on Ubuntu 22.04/24.04 LTS. ```sh sudo apt-get install libwebkit2gtk-4.1-0 ``` -------------------------------- ### Install Build Dependencies on Fedora Source: https://github.com/dizitart/papyrus/blob/main/packages/papyrus_linux/README.md Install required development tools and libraries for building on Fedora 39+. ```sh sudo dnf install cmake ninja-build gcc-c++ pkgconf-pkg-config gtk3-devel webkit2gtk4.1-devel ``` -------------------------------- ### Installation: Clean Build Bundle Directory Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_testbed/linux/CMakeLists.txt Installs a code block that removes the build bundle directory before installation to ensure a clean state. ```cmake install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) ``` -------------------------------- ### Install WebKitGTK on Arch Linux Source: https://github.com/dizitart/papyrus/blob/main/packages/papyrus_linux/README.md Install the WebKitGTK package on Arch Linux using pacman. ```sh sudo pacman -S webkit2gtk-4.1 ``` -------------------------------- ### Installation: Install ICU Data Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_testbed/linux/CMakeLists.txt Installs the ICU data file to the data directory within the bundle. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Runtime Library Path Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_testbed/linux/CMakeLists.txt Configures the installation runtime path to load bundled libraries from the 'lib/' directory relative to the binary. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Example Conformance Test Runs Source: https://github.com/dizitart/papyrus/blob/main/test/conformance/README.md Demonstrates various ways to run the Papyrus conformance tests with different device IDs and flags. Ensure you list available devices using `flutter devices` before running. ```bash dart run tool/run_platform_conformance.dart --device macos ``` ```bash dart run tool/run_platform_conformance.dart --device macos --native-macos-platform-view ``` ```bash dart run tool/run_platform_conformance.dart --device 4BC64162-0CFF-4C35-B60E-7B4A4EFF0770 --skip-checks ``` ```bash dart run tool/run_platform_conformance.dart --device emulator-5554 --skip-checks ``` ```bash dart run tool/run_platform_conformance.dart --device linux --skip-checks ``` ```bash dart run tool/run_platform_conformance.dart --device windows --skip-checks ``` -------------------------------- ### Configure Unit Tests Source: https://github.com/dizitart/papyrus/blob/main/packages/papyrus_linux/linux/CMakeLists.txt Sets up unit tests using Google Test, including fetching the library, configuring build settings, and linking necessary dependencies. Tests are enabled only when building the example. ```cmake if (${include_${PROJECT_NAME}_tests}) if(${CMAKE_VERSION} VERSION_LESS "3.11.0") message("Unit tests require CMake 3.11.0 or later") else() set(TEST_RUNNER "${PROJECT_NAME}_test") enable_testing() include(FetchContent) FetchContent_Declare( googletest URL https://github.com/google/googletest/archive/release-1.11.0.zip ) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) set(INSTALL_GTEST OFF CACHE BOOL "Disable installation of googletest" FORCE) FetchContent_MakeAvailable(googletest) add_executable(${TEST_RUNNER} test/papyrus_linux_plugin_test.cc ${PLUGIN_SOURCES} ) apply_standard_settings(${TEST_RUNNER}) target_include_directories(${TEST_RUNNER} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(${TEST_RUNNER} PRIVATE flutter) target_link_libraries(${TEST_RUNNER} PRIVATE PkgConfig::GTK) target_link_libraries(${TEST_RUNNER} PRIVATE PkgConfig::WEBKIT2GTK) target_link_libraries(${TEST_RUNNER} PRIVATE gtest_main gmock) include(GoogleTest) gtest_discover_tests(${TEST_RUNNER}) endif() # CMake version check endif() # include_${PROJECT_NAME}_tests ``` -------------------------------- ### Project and Build Configuration Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_example/linux/CMakeLists.txt Sets up the minimum CMake version, project name, executable name, and GTK application ID. It also enforces modern CMake behaviors and configures the installation path for bundled libraries. ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) set(BINARY_NAME "papyrus_example") set(APPLICATION_ID "com.example.papyrus_example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Build and Test Native Windows Implementation Source: https://github.com/dizitart/papyrus/blob/main/packages/papyrus_windows/README.md Commands to get dependencies, build the Windows project, and run native tests for the papyrus_windows plugin. ```powershell flutter pub get flutter build windows --debug cmake -S windows -B build/windows/x64 "-Dinclude_papyrus_windows_tests=ON" "-DCMAKE_POLICY_VERSION_MINIMUM=3.10" cmake --build build/windows/x64 --config Debug --target papyrus_windows_test ctest --test-dir build/windows/x64/plugins/papyrus_windows -C Debug --output-on-failure ``` -------------------------------- ### Install AOT Library Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_example/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the bundle's library directory, but only for non-Debug build types. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Customize Papyrus Configuration Profile Source: https://github.com/dizitart/papyrus/blob/main/README.md Start from a built-in profile and override specific policy groups using `copyWith`. This example customizes the display policy for a document viewer profile. ```dart final config = PapyrusProfiles.documentViewer().copyWith( display: const PapyrusDisplayPolicy(autoHeight: true, darkMode: PapyrusDarkMode.dark), ); ``` -------------------------------- ### Query Platform Capabilities in Dart Source: https://github.com/dizitart/papyrus/blob/main/README.md Check runtime capabilities of the current backend before using optional features. This example demonstrates checking for snapshot, print, and auto-height support. ```dart final caps = await controller.getCapabilities(); if (caps.supportsSnapshot) { final png = await controller.captureSnapshot(); } if (caps.supportsPrint) { await controller.printDocument(options: const PapyrusPrintOptions(jobName: 'Report')); } if (caps.supportsAutoHeight) { // PapyrusDisplayPolicy.autoHeight is effective on this backend } ``` -------------------------------- ### Installation: Clean and Copy Assets Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_testbed/linux/CMakeLists.txt Removes the existing Flutter assets directory and then copies the new assets from the build directory to the data directory within the bundle. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Native Assets and Flutter Assets Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_example/linux/CMakeLists.txt Installs native assets from packages and the Flutter assets directory. It ensures the Flutter assets directory is re-copied on each build to avoid stale files. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Fetch and Configure Google Test Source: https://github.com/dizitart/papyrus/blob/main/packages/papyrus_windows/windows/CMakeLists.txt Fetches the Google Test framework and configures it for use within the project. It prevents overriding parent project settings and disables installation of gtest. ```cmake include(FetchContent) if (NOT DEFINED CMAKE_POLICY_VERSION_MINIMUM) set(CMAKE_POLICY_VERSION_MINIMUM 3.10 CACHE STRING "Minimum policy version for bundled test dependencies" FORCE) endif() FetchContent_Declare( googletest URL https://github.com/google/googletest/archive/release-1.11.0.zip ) # Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Disable install commands for gtest so it doesn't end up in the bundle. set(INSTALL_GTEST OFF CACHE BOOL "Disable installation of googletest" FORCE) FetchContent_MakeAvailable(googletest) ``` -------------------------------- ### PapyrusController - Output & Export Source: https://github.com/dizitart/papyrus/blob/main/README.md Methods for capturing snapshots, printing, and getting content size. ```APIDOC ## PapyrusController.captureSnapshot({options}) ### Description Captures a PNG snapshot of the current WebView content. ### Method `captureSnapshot({Map? options})` ### Parameters #### Path Parameters - **options** (Map) - Optional - Options for capturing the snapshot. ### Returns A `Uint8List` containing the PNG image data. ``` ```APIDOC ## PapyrusController.printDocument({options}) ### Description Triggers the native print dialog for the current WebView content. ### Method `printDocument({Map? options})` ### Parameters #### Path Parameters - **options** (Map) - Optional - Options for printing. ``` ```APIDOC ## PapyrusController.getContentSize() ### Description Returns the scrollable content size of the WebView. ### Method `getContentSize()` ### Returns A `PapyrusContentSize` object containing the width and height of the content. ``` -------------------------------- ### Initialize PapyrusView in Flutter Source: https://github.com/dizitart/papyrus/blob/main/README.md Basic setup for displaying HTML content using PapyrusView in a Flutter widget. Ensure to use appropriate PapyrusProfiles based on content trust. ```dart import 'package:papyrus/papyrus.dart'; import 'package:flutter/material.dart'; class MyPage extends StatefulWidget { const MyPage({super.key}); @override State createState() => _MyPageState(); } class _MyPageState extends State { final _controller = PapyrusController.create(); @override Widget build(BuildContext context) { return PapyrusView( controller: _controller, configuration: PapyrusProfiles.documentViewer(), initialRequest: const PapyrusHtmlRequest( html: '

Hello Papyrus

Controlled HTML content.

', ), onPageFinished: (event) => debugPrint('Loaded: ${event.uri}'), ); } } ``` -------------------------------- ### Project and Dependency Configuration Source: https://github.com/dizitart/papyrus/blob/main/packages/papyrus_linux/linux/CMakeLists.txt Sets the project name and finds necessary packages like PkgConfig, GTK, and WebKitGTK. It includes a fallback for WebKitGTK versions. ```cmake set(PROJECT_NAME "papyrus_linux") project(${PROJECT_NAME} LANGUAGES CXX) find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(WEBKIT2GTK webkit2gtk-4.1 IMPORTED_TARGET) if (NOT WEBKIT2GTK_FOUND) pkg_check_modules(WEBKIT2GTK webkit2gtk-4.0 IMPORTED_TARGET) endif() if (NOT WEBKIT2GTK_FOUND) message(FATAL_ERROR "Papyrus Linux requires WebKitGTK. Install webkit2gtk-4.1 or webkit2gtk-4.0 development packages.") endif() ``` -------------------------------- ### Run Papyrus Testbed Locally Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_testbed/README.md Commands to set up and run the Papyrus testbed locally using Flutter. ```bash flutter pub get flutter run ``` -------------------------------- ### Set Flutter Library and Headers Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_example/windows/flutter/CMakeLists.txt Defines the Flutter library and its associated header files. These are published to the parent scope for use in the installation step. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "flutter_export.h" "flutter_windows.h" "flutter_messenger.h" "flutter_plugin_registrar.h" "flutter_texture_registrar.h" ) list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") ``` -------------------------------- ### Interact with Selection Tools in Papyrus Source: https://github.com/dizitart/papyrus/blob/main/SKILL.md Utilize controller methods to get selected text, create a quote of the selection, and copy the selection to the clipboard. ```dart final selected = await controller.selectedText(); final quote = await controller.quoteSelection(); await controller.copySelection(); ``` -------------------------------- ### Initialize and Configure PapyrusView Source: https://github.com/dizitart/papyrus/blob/main/docs/quick_start.md Create a Papyrus controller and initialize the PapyrusView with a specific profile and initial HTML content. Use PapyrusProfiles.lockedDown() for untrusted static HTML. ```dart final controller = PapyrusController.create(); PapyrusView( controller: controller, configuration: PapyrusProfiles.documentViewer(), initialRequest: const PapyrusHtmlRequest( html: '

Terms

Controlled HTML content.

', ), ); ``` -------------------------------- ### Set Include Directories and Link Libraries Source: https://github.com/dizitart/papyrus/blob/main/packages/papyrus_windows/windows/CMakeLists.txt Specifies include directories for the plugin and links against Flutter and WebView2 libraries. Add any plugin-specific dependencies here. ```cmake target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/dizitart/papyrus/blob/main/packages/papyrus_windows/windows/CMakeLists.txt Applies common build settings from the application-level CMakeLists.txt. This can be removed if the plugin requires full control over build settings. ```cmake apply_standard_settings(${PLUGIN_NAME}) ``` -------------------------------- ### Link WebView2 Libraries Source: https://github.com/dizitart/papyrus/blob/main/packages/papyrus_windows/windows/CMakeLists.txt Adds the WebView2 include directory and links the appropriate WebView2LoaderStatic.lib based on the determined architecture. ```cmake target_include_directories(${PLUGIN_NAME} PRIVATE "${WEBVIEW2_ROOT}/build/native/include") target_link_libraries(${PLUGIN_NAME} PRIVATE "${WEBVIEW2_ROOT}/build/native/${WEBVIEW2_ARCH}/WebView2LoaderStatic.lib") ``` -------------------------------- ### Run Repository Contract Checks Source: https://github.com/dizitart/papyrus/blob/main/SKILL.md Execute the repository contract checks script from the root directory of the repository. ```bash ./tool/check.sh ``` -------------------------------- ### Configure Download and Permission Callbacks Source: https://github.com/dizitart/papyrus/blob/main/README.md Handle download requests with onDownloadRequest and permission requests with onPermissionRequest. Define decisions like PapyrusDownloadDecision.handToHostApp or PapyrusPermissionDecision.deny. ```dart PapyrusView( controller: _controller, onDownloadRequest: (request) async { // request.uri, request.suggestedFilename, request.mimeType, request.contentLength return PapyrusDownloadDecision.handToHostApp; }, onPermissionRequest: (request) async { // request.uri, request.permissions (Set) if (request.permissions.contains(PapyrusPermissionType.camera)) { return PapyrusPermissionDecision.deny; } return PapyrusPermissionDecision.promptHostApp; }, ); ``` -------------------------------- ### Add Papyrus Dependency to Flutter Project Source: https://github.com/dizitart/papyrus/blob/main/SKILL.md Add the papyrus package to your Flutter project's dependencies in pubspec.yaml. Ensure you run 'flutter pub get' afterwards. Minimum environment requirements are Flutter >=3.41.0 and Dart ^3.11.0. ```yaml dependencies: papyrus: ^0.1.0 ``` -------------------------------- ### Create PapyrusController and Embed PapyrusView Source: https://context7.com/dizitart/papyrus/llms.txt Demonstrates creating a PapyrusController and using it with PapyrusView to display HTML content. Ensure the controller is disposed of to release native resources. ```dart import 'package:papyrus/papyrus.dart'; import 'package:flutter/material.dart'; class DocumentPage extends StatefulWidget { const DocumentPage({super.key}); @override State createState() => _DocumentPageState(); } class _DocumentPageState extends State { // Create controller once; share it with PapyrusView. final _controller = PapyrusController.create(); @override Widget build(BuildContext context) { return Scaffold( body: PapyrusView( controller: _controller, configuration: PapyrusProfiles.documentViewer(), initialRequest: const PapyrusHtmlRequest( html: '

Hello Papyrus

Controlled HTML content.

', ), onCreated: (ctrl) => debugPrint('WebView ready'), ), ); } @override void dispose() { _controller.dispose(); // release native resources super.dispose(); } } ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_testbed/windows/runner/CMakeLists.txt Applies a predefined set of build settings to the executable target. This can be customized for applications requiring different configurations. ```cmake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Application and Plugin Build Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_example/linux/CMakeLists.txt Adds the runner subdirectory for the application build and includes generated plugin build rules. ```cmake add_subdirectory("runner") include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_example/linux/runner/CMakeLists.txt Applies a predefined set of build settings to the target. This can be customized or removed if the application requires specific build configurations. ```cmake # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Find GTK, GLIB, and GIO Packages Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_example/linux/flutter/CMakeLists.txt Uses PkgConfig to find and check for required GTK, GLIB, and GIO libraries. These are essential for Flutter's Linux integration. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) ``` -------------------------------- ### WebView2 Dependency Management Source: https://github.com/dizitart/papyrus/blob/main/packages/papyrus_windows/windows/CMakeLists.txt Manages the download and extraction of the WebView2 SDK. It first attempts to use nuget.exe, and if unavailable, downloads and extracts the .nupkg manually. ```cmake set(WEBVIEW2_VERSION "1.0.3124.44") set(WEBVIEW2_ROOT "${CMAKE_CURRENT_BINARY_DIR}/nuget/Microsoft.Web.WebView2") if (NOT EXISTS "${WEBVIEW2_ROOT}/build/native/include/WebView2.h") find_program(NUGET_EXE nuget) if (NUGET_EXE) execute_process( COMMAND "${NUGET_EXE}" install Microsoft.Web.WebView2 -Version ${WEBVIEW2_VERSION} -OutputDirectory "${CMAKE_CURRENT_BINARY_DIR}/nuget" -ExcludeVersion RESULT_VARIABLE WEBVIEW2_NUGET_RESULT ) if (NOT WEBVIEW2_NUGET_RESULT EQUAL 0) message(FATAL_ERROR "Failed to restore Microsoft.Web.WebView2 ${WEBVIEW2_VERSION}.") endif() else() file(MAKE_DIRECTORY "${WEBVIEW2_ROOT}") set(WEBVIEW2_NUPKG "${CMAKE_CURRENT_BINARY_DIR}/nuget/Microsoft.Web.WebView2.${WEBVIEW2_VERSION}.nupkg") file(DOWNLOAD "https://api.nuget.org/v3-flatcontainer/microsoft.web.webview2/${WEBVIEW2_VERSION}/microsoft.web.webview2.${WEBVIEW2_VERSION}.nupkg" "${WEBVIEW2_NUPKG}" STATUS WEBVIEW2_DOWNLOAD_STATUS TLS_VERIFY ON ) list(GET WEBVIEW2_DOWNLOAD_STATUS 0 WEBVIEW2_DOWNLOAD_CODE) if (NOT WEBVIEW2_DOWNLOAD_CODE EQUAL 0) message(FATAL_ERROR "Failed to download Microsoft.Web.WebView2 ${WEBVIEW2_VERSION}. Install nuget.exe or pre-populate ${WEBVIEW2_ROOT}.") endif() execute_process( COMMAND ${CMAKE_COMMAND} -E tar xvf "${WEBVIEW2_NUPKG}" WORKING_DIRECTORY "${WEBVIEW2_ROOT}" RESULT_VARIABLE WEBVIEW2_EXTRACT_RESULT ) if (NOT WEBVIEW2_EXTRACT_RESULT EQUAL 0) message(FATAL_ERROR "Failed to extract ${WEBVIEW2_NUPKG}.") endif() endif() endif() ``` -------------------------------- ### Run Platform Conformance Tests Source: https://github.com/dizitart/papyrus/blob/main/SKILL.md Execute platform conformance tests using `dart run tool/run_platform_conformance.dart`. Specify the target device and optional flags like `--native-macos-platform-view` or `--skip-checks`. ```bash dart run tool/run_platform_conformance.dart --device macos ``` ```bash dart run tool/run_platform_conformance.dart --device macos --native-macos-platform-view ``` ```bash dart run tool/run_platform_conformance.dart --device emulator-5554 --skip-checks ``` ```bash dart run tool/run_platform_conformance.dart --device linux --skip-checks ``` ```bash dart run tool/run_platform_conformance.dart --device windows --skip-checks ``` -------------------------------- ### Link Libraries and Include Directories Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_testbed/windows/runner/CMakeLists.txt Links necessary libraries (flutter, flutter_wrapper_app, dwmapi.lib) and adds the source directory to include paths. Add any other application-specific dependencies here. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) ``` ```cmake target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") ``` ```cmake target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### PapyrusConfiguration Initialization Source: https://github.com/dizitart/papyrus/blob/main/README.md Initialize PapyrusConfiguration with various policy objects to control WebView behavior. Defaults are conservative, requiring explicit enablement for most features. ```dart const config = PapyrusConfiguration( security: PapyrusSecurityPolicy(...), navigation: PapyrusNavigationPolicy(...), resources: PapyrusResourcePolicy(...), javascript: PapyrusJavaScriptPolicy(...), storage: PapyrusStoragePolicy(...), media: PapyrusMediaPolicy(...), display: PapyrusDisplayPolicy(...), accessibility: PapyrusAccessibilityPolicy(...), interaction: PapyrusInteractionPolicy(...), platform: PapyrusPlatformOptions(...), ); ``` -------------------------------- ### Run Static Checks and Unit Tests Source: https://github.com/dizitart/papyrus/blob/main/README.md Execute the bash script to perform static code analysis and run unit tests. ```bash bash tool/check.sh ``` -------------------------------- ### PapyrusController.getCapabilities Source: https://context7.com/dizitart/papyrus/llms.txt Queries the platform for supported features. Returns a `PapyrusPlatformCapabilities` object that describes which optional features are available on the current platform backend. Always check capabilities before calling optional methods. ```APIDOC ## PapyrusController.getCapabilities — Query platform feature support ### Description Returns a `PapyrusPlatformCapabilities` object describing which optional features are available on the current platform backend. Always check capabilities before calling optional methods. ### Method Signature `Future getCapabilities()` ### Returns - **PapyrusPlatformCapabilities** - An object detailing supported platform features. ``` -------------------------------- ### Project and Policy Configuration Source: https://github.com/dizitart/papyrus/blob/main/packages/papyrus_windows/windows/CMakeLists.txt Sets the project name and opts into modern CMake behaviors to avoid warnings. The project name must not be changed. ```cmake set(PROJECT_NAME "papyrus_windows") project(${PROJECT_NAME} LANGUAGES CXX) cmake_policy(VERSION 3.14...3.25) ``` -------------------------------- ### PapyrusProfiles Built-in Configuration Presets Source: https://context7.com/dizitart/papyrus/llms.txt Offers five pre-configured `PapyrusConfiguration` instances for common scenarios like locked-down environments, document viewers, trusted content, browser-like behavior, and email HTML viewing. Profiles can be customized using `copyWith` to adjust specific policies. ```dart // 1. Maximally locked down — no JS, no remote resources, all navigation blocked. final locked = PapyrusProfiles.lockedDown(); // 2. Document viewer — remote resources ask the host, external links open externally. final docs = PapyrusProfiles.documentViewer(); // 3. Trusted first-party content — restricted JS, per-host resources, cookies + storage. final trusted = PapyrusProfiles.trustedAppContent(); // 4. Browser-like — full JS, all navigation, cookies, localStorage. final browser = PapyrusProfiles.browserLike(); // 5. Email HTML viewer — no JS, no remote resources, ephemeral session, auto-height. final email = PapyrusProfiles.emailHtmlViewer(); // Customise a profile with copyWith. final customEmail = PapyrusProfiles.emailHtmlViewer().copyWith( display: const PapyrusDisplayPolicy( autoHeight: true, darkMode: PapyrusDarkMode.system, textZoom: 1.1, ), resources: PapyrusResourcePolicy( remoteResources: PapyrusRemoteResourceMode.block, virtualResourceOrigin: Uri.parse('papyrus-resource://email.local/'), ), ); ``` -------------------------------- ### Run Platform Conformance Tests Source: https://github.com/dizitart/papyrus/blob/main/test/conformance/README.md Execute the cross-host runner for Papyrus conformance tests. Specify the target Flutter device ID. Use flags like `--skip-checks` to rerun only live device-backed suites. ```bash dart run tool/run_platform_conformance.dart --device ``` -------------------------------- ### PapyrusController.create Source: https://context7.com/dizitart/papyrus/llms.txt Creates a new PapyrusController, which is essential for driving all WebView operations and must be provided to PapyrusView. ```APIDOC ## PapyrusController.create — Create a WebView controller ### Description Creates a new `PapyrusController` bound to the active platform implementation. The controller is the single handle for all WebView operations and must be provided to `PapyrusView`. ### Method Signature ```dart PapyrusController.create() ``` ### Usage Example ```dart import 'package:papyrus/papyrus.dart'; import 'package:flutter/material.dart'; class DocumentPage extends StatefulWidget { const DocumentPage({super.key}); @override State createState() => _DocumentPageState(); } class _DocumentPageState extends State { // Create controller once; share it with PapyrusView. final _controller = PapyrusController.create(); @override Widget build(BuildContext context) { return Scaffold( body: PapyrusView( controller: _controller, configuration: PapyrusProfiles.documentViewer(), initialRequest: const PapyrusHtmlRequest( html: '

Hello Papyrus

Controlled HTML content.

', ), onCreated: (ctrl) => debugPrint('WebView ready'), ), ); } @override void dispose() { _controller.dispose(); // release native resources super.dispose(); } } ``` ``` -------------------------------- ### Configure Flutter Interface Library Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_example/windows/flutter/CMakeLists.txt Creates an interface library for Flutter, setting include directories and linking against the Flutter library. It also adds a dependency on the flutter_assemble target. ```cmake add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### PapyrusController Load Methods for Different Content Types Source: https://context7.com/dizitart/papyrus/llms.txt Demonstrates various methods of the PapyrusController for loading content, including HTML strings with base URIs and virtual resources, remote URLs with custom headers, local files, and raw data with specified MIME types and encodings. ```dart // Load an HTML string with a base URI, metadata, and inline virtual resources. await _controller.load( PapyrusHtmlRequest( html: sanitizedEmailHtml, baseUri: Uri.parse('papyrus-resource://email.local/msg-42/'), metadata: const PapyrusContentMetadata( contentType: 'text/html', source: 'email', identifier: 'msg-42', ), virtualResources: [ PapyrusVirtualResource( uri: Uri.parse('papyrus-resource://email.local/msg-42/logo.png'), bytes: logoPngBytes, mimeType: 'image/png', ), ], ), ); // Load a remote URL with custom headers. await _controller.loadUri( Uri.parse('https://docs.example.com/guide'), headers: {'Authorization': 'Bearer $token'}, ); // Load a local file (requires allowFileAccess: true in security policy). await _controller.loadFile('/data/user/0/com.example/cache/report.html'); // Load raw bytes with a MIME type. await _controller.loadData( pdfBytes, 'application/pdf', encoding: 'base64', baseUri: Uri.parse('https://example.com/'), ); ``` -------------------------------- ### Include Generated Plugins Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_testbed/linux/CMakeLists.txt Includes the CMake script that manages the building and integration of generated plugins into the application. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Find GTK+ 3.0 Package Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_testbed/linux/CMakeLists.txt Finds the PkgConfig tool and checks for the GTK+ 3.0 library, making its imported target available. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### Flutter and System Dependencies Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_example/linux/CMakeLists.txt Includes the Flutter managed directory and checks for GTK+ 3.0 system dependencies using PkgConfig. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### Handle Downloads and Permissions Source: https://context7.com/dizitart/papyrus/llms.txt Intercept file download requests and device permission prompts. Return decisions to grant or deny permissions, or hand off downloads to the host app. ```dart PapyrusView( controller: _controller, configuration: PapyrusProfiles.browserLike(), onDownloadRequest: (request) async { // request.uri, suggestedFilename, mimeType, contentLength debugPrint('Download: ${request.suggestedFilename} (${request.mimeType})'); // Hand the URL to your own downloader. _myDownloadManager.enqueue(request.uri, request.suggestedFilename); return PapyrusDownloadDecision.handToHostApp; }, onPermissionRequest: (request) async { // request.uri, request.permissions (Set) if (request.permissions.contains(PapyrusPermissionType.camera) || request.permissions.contains(PapyrusPermissionType.microphone)) { // Show your own permission dialog, then grant or deny. final allowed = await _showPermissionDialog(request.permissions); return allowed ? PapyrusPermissionDecision.grant : PapyrusPermissionDecision.deny; } return PapyrusPermissionDecision.deny; }, ); ``` -------------------------------- ### Project and Minimum CMake Version Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_testbed/linux/CMakeLists.txt Sets the minimum required CMake version and the project name with supported languages. ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) ``` -------------------------------- ### Run Full Platform Conformance Tests Source: https://github.com/dizitart/papyrus/blob/main/README.md Execute the Dart script to run full platform conformance tests on a specified Flutter device. Use `flutter devices` to find device IDs. ```dart dart run tool/run_platform_conformance.dart --device ``` ```dart dart run tool/run_platform_conformance.dart --device macos ``` ```dart dart run tool/run_platform_conformance.dart --device 4BC64162-0CFF-4C35-B60E-7B4A4EFF0770 --skip-checks ``` ```dart dart run tool/run_platform_conformance.dart --device emulator-5554 --skip-checks ``` ```dart dart run tool/run_platform_conformance.dart --device linux --skip-checks ``` ```dart dart run tool/run_platform_conformance.dart --device windows --skip-checks ``` -------------------------------- ### Create PapyrusFileRequest Source: https://github.com/dizitart/papyrus/blob/main/README.md Instantiate PapyrusFileRequest with the absolute path to a local file. ```dart PapyrusFileRequest(absolutePath: '/data/user/0/com.example/files/doc.html'); ``` -------------------------------- ### Define Bundled Libraries Source: https://github.com/dizitart/papyrus/blob/main/packages/papyrus_windows/windows/CMakeLists.txt Placeholder for listing libraries to be bundled with the plugin. Currently set to an empty string. ```cmake set(papyrus_windows_bundled_libraries "" PARENT_SCOPE ) ``` -------------------------------- ### Cross-Building Configuration Source: https://github.com/dizitart/papyrus/blob/main/examples/papyrus_example/linux/CMakeLists.txt Configures sysroot and search paths for cross-building environments when FLUTTER_TARGET_PLATFORM_SYSROOT is defined. ```cmake if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() ```