### Project and Dependency Setup Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/linux/CMakeLists.txt Initializes the CMake project, sets binary and application IDs, configures installation paths, and finds necessary packages like PkgConfig and GTK. This sets up the foundational build environment. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) set(BINARY_NAME "tray_manager_example") set(APPLICATION_ID "com.example.tray_manager") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 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() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() 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) add_definitions(-DAPPLICATION_ID=\"${APPLICATION_ID}\") ``` -------------------------------- ### Configure Installation Rules for Runtime Components Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/windows/CMakeLists.txt Defines installation rules for the main executable, ICU data, Flutter library, bundled plugin libraries, and assets. It ensures these components are placed correctly next to the executable for in-place execution. ```cmake # === Installation === # Support files are copied into place next to the executable, so that it can # run in place. This is done instead of making a separate bundle (as on Linux) # so that building and running from within Visual Studio will work. set(BUILD_BUNDLE_DIR "$") # Make the "install" step default, as it's required to run. set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") 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) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. 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 the AOT library on non-Debug builds only. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Install Linux AppIndicator Development Libraries Source: https://github.com/leanflutter/tray_manager/blob/main/README.md Install the necessary development libraries for AppIndicator on Linux systems. Use either ayatana-appindicator3-0.1 or appindicator3-0.1. ```bash sudo apt-get install libayatana-appindicator3-dev ``` ```bash sudo apt-get install appindicator3-0.1 libappindicator3-dev ``` -------------------------------- ### Install Application Bundle Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/linux/CMakeLists.txt Installs the application executable, Flutter ICU data, Flutter library, bundled plugin libraries, and assets into a relocatable bundle. AOT library is installed for non-Debug builds. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 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") 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) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() 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) if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Find System Dependencies with PkgConfig Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/linux/flutter/CMakeLists.txt This section finds required system libraries (GTK, GLIB, GIO) using PkgConfig. Ensure PkgConfig is installed and the development files for these libraries are available on your system. These are essential for the Flutter Linux embedding. ```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) ``` -------------------------------- ### CMake Project Configuration Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/windows/runner/CMakeLists.txt Configures the CMake build system for the project. Specifies the minimum required version, project name, and languages. This is typically the starting point for any CMake project. ```cmake cmake_minimum_required(VERSION 3.15) project(runner LANGUAGES CXX) ``` -------------------------------- ### Set Minimum CMake Version and Project Name Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/windows/CMakeLists.txt Specifies the minimum required CMake version and names the project. This is a standard starting point for CMake projects. ```cmake cmake_minimum_required(VERSION 3.15) project(tray_manager_example LANGUAGES CXX) ``` -------------------------------- ### Application Build Configuration Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/linux/CMakeLists.txt Configures the main executable, applies standard settings, links Flutter and GTK libraries, and sets runtime output directory. Ensure Flutter plugins are correctly registered. ```cmake add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) apply_standard_settings(${BINARY_NAME}) target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) add_dependencies(${BINARY_NAME} flutter_assemble) set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### TrayManager Methods Source: https://github.com/leanflutter/tray_manager/blob/main/README.md This section details the methods available for the TrayManager class, which allows for the management of system tray icons. ```APIDOC ## TrayManager ### destroy #### Description Destroys the tray icon immediately. #### Method `destroy()` ### setIcon #### Description Sets the image associated with this tray icon. #### Method `setIcon(iconPath: string)` ### setIconPosition #### Description Sets the icon position of the tray icon. #### Method `setIconPosition(position: 'left' | 'right' | 'center')` ### setToolTip #### Description Sets the hover text for this tray icon. #### Method `setToolTip(toolTip: string)` ### setContextMenu #### Description Sets the context menu for this icon. #### Method `setContextMenu(menu: Menu)` ### popUpContextMenu #### Description Pops up the context menu of the tray icon. #### Method `popUpContextMenu()` ### getBounds #### Description Returns `Rect` The bounds of this tray icon. #### Method `getBounds(): Rect` ``` -------------------------------- ### Create Flutter Wrapper Application Library Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/windows/flutter/CMakeLists.txt Builds a static library for the Flutter wrapper application, including core and application-specific sources. Configures include directories and links against the Flutter library. ```cmake add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### Set Tray Icon and Context Menu Source: https://github.com/leanflutter/tray_manager/blob/main/README.md Configure the tray icon using platform-specific paths and define a context menu with selectable items. This code should be called after initializing the tray manager. ```dart await trayManager.setIcon( Platform.isWindows ? 'images/tray_icon.ico' : 'images/tray_icon.png', ); Menu menu = Menu( items: [ MenuItem( key: 'show_window', label: 'Show Window', ), MenuItem.separator(), MenuItem( key: 'exit_app', label: 'Exit App', ), ], ); await trayManager.setContextMenu(menu); ``` -------------------------------- ### Create Flutter Wrapper Plugin Library Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/windows/flutter/CMakeLists.txt Builds a static library for the Flutter wrapper plugin, including core and plugin-specific sources. Configures visibility and links against the Flutter library. ```cmake add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) ``` -------------------------------- ### Define C++ Wrapper Sources Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/windows/flutter/CMakeLists.txt Lists and prepends paths to C++ wrapper source files for core, plugin, and application components. ```cmake list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### CMake Build Configuration for Tray Manager Plugin Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/linux/CMakeLists.txt This CMakeLists.txt file configures the build for the tray_manager Flutter plugin. It sets up project details, finds necessary packages like PkgConfig and GTK, and links against the Flutter and GTK libraries. It also includes conditional logic to check for AppIndicator dependencies (Ayatana or standard libappindicator3). ```cmake cmake_minimum_required(VERSION 3.10) set(PROJECT_NAME "tray_manager") project(${PROJECT_NAME} LANGUAGES CXX) # This value is used when generating builds using this plugin, so it must # not be changed set(PLUGIN_NAME "tray_manager_plugin") find_package(PkgConfig REQUIRED) add_library(${PLUGIN_NAME} SHARED "tray_manager_plugin.cc" ) apply_standard_settings(${PLUGIN_NAME}) set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter) target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK) pkg_check_modules(APPINDICATOR IMPORTED_TARGET ayatana-appindicator3-0.1) if(APPINDICATOR_FOUND) target_compile_definitions(${PLUGIN_NAME} PRIVATE HAVE_AYATANA) else() pkg_check_modules(APPINDICATOR IMPORTED_TARGET appindicator3-0.1) endif() if(APPINDICATOR_FOUND) target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::APPINDICATOR) else() message( FATAL_ERROR "\n" "The `tray_manager` package requires ayatana-appindicator3-0.1 or appindicator3-0.1. See https://github.com/leanflutter/tray_manager#linux-requirements" ) endif() # List of absolute paths to libraries that should be bundled with the plugin set(tray_manager_bundled_libraries "" PARENT_SCOPE ) ``` -------------------------------- ### Configure Build Options for Multi-Config Generators Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/windows/CMakeLists.txt Sets the available build configurations (Debug, Profile, Release) for multi-configuration generators like Visual Studio. For single-configuration generators, it ensures a default build type is set if none is specified. ```cmake get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() ``` -------------------------------- ### Configure Tray Manager Plugin Build Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/windows/CMakeLists.txt Defines the build settings for the tray_manager plugin using CMake. It sets the project name, adds the shared library, applies standard settings, and configures visibility and include directories. ```cmake cmake_minimum_required(VERSION 3.15) set(PROJECT_NAME "tray_manager") project(${PROJECT_NAME} LANGUAGES CXX) # This value is used when generating builds using this plugin, so it must # not be changed set(PLUGIN_NAME "tray_manager_plugin") add_library(${PLUGIN_NAME} SHARED "tray_manager_plugin.cpp" ) apply_standard_settings(${PLUGIN_NAME}) set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) target_compile_definitions(${PLUGIN_NAME} PRIVATE _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING) target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) # List of absolute paths to libraries that should be bundled with the plugin set(tray_manager_bundled_libraries "" PARENT_SCOPE ) ``` -------------------------------- ### Add tray_manager Dependency (Pubspec) Source: https://github.com/leanflutter/tray_manager/blob/main/README.md Include the tray_manager package in your project's pubspec.yaml file using a version constraint. ```yaml dependencies: tray_manager: ^0.5.2 ``` -------------------------------- ### Add tray_manager Dependency (Git) Source: https://github.com/leanflutter/tray_manager/blob/main/README.md Alternatively, add the tray_manager package directly from its Git repository, specifying a URL, branch, and path. ```yaml dependencies: tray_manager: git: url: https://github.com/leanflutter/tray_manager.git ref: main path: packages/tray_manager ``` -------------------------------- ### Apply Standard Compilation Settings Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/linux/CMakeLists.txt Applies C++14 standard, warning flags, optimization, and NDEBUG definition for non-Debug builds. Use this function for most targets. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") endfunction() ``` -------------------------------- ### Integrate Flutter Build Rules Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/windows/CMakeLists.txt Includes the Flutter build rules and generated plugin build rules. This is essential for building Flutter applications with CMake. ```cmake # Flutter library and tool build rules. add_subdirectory(${FLUTTER_MANAGED_DIR}) # Application build add_subdirectory("runner") # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Set Flutter Library and Headers Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/windows/flutter/CMakeLists.txt Configures the Flutter library and its associated header files. Ensures these are available for linking and inclusion. ```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}/") ``` -------------------------------- ### Listen for Tray Events Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/README.md Implement the TrayListener interface to handle user interactions with the tray icon, such as mouse clicks and menu item selections. Remember to add and remove the listener in the widget's lifecycle methods. ```dart import 'package:flutter/material.dart'; import 'package:tray_manager/tray_manager.dart'; class HomePage extends StatefulWidget { @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State with TrayListener { @override void initState() { trayManager.addListener(this); super.initState(); _init(); } @override void dispose() { trayManager.removeListener(this); super.dispose(); } void _init() { // ... } @override Widget build(BuildContext context) { // ... } @override void onTrayIconMouseDown() { // do something, for example pop up the menu trayManager.popUpContextMenu(); } @override void onTrayIconRightMouseDown() { // do something } @override void onTrayIconRightMouseUp() { // do something } @override void onTrayMenuItemClick(MenuItem menuItem) { if (menuItem.key == 'show_window') { // do something } else if (menuItem.key == 'exit_app') { // do something } } } ``` -------------------------------- ### Configure Flutter Tool Backend Custom Command Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/windows/flutter/CMakeLists.txt Defines a custom command to execute the Flutter tool backend script. This command generates necessary Flutter artifacts and is forced to run every time using a phony output file. ```cmake set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) ``` -------------------------------- ### Define Flutter Library Headers Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/linux/flutter/CMakeLists.txt This section defines a list of Flutter library header files. The `list_prepend` function is used to add the correct include path prefix to each header. These headers are necessary for compiling code that interacts with the Flutter engine. ```cmake list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") ``` -------------------------------- ### Add Flutter Interface Library Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/windows/flutter/CMakeLists.txt Creates an interface library target for Flutter, specifying include directories and linking against the Flutter library. ```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) ``` -------------------------------- ### Apply Standard Compilation Settings Function Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/windows/CMakeLists.txt A reusable CMake function to apply common compilation features, options, and definitions to a target. It enforces C++17, sets warning levels, and manages exception handling and debug definitions. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") endfunction() ``` -------------------------------- ### Update app_links Dependency Source: https://github.com/leanflutter/tray_manager/blob/main/README.md Ensure your app_links package version is at least 6.3.3 to avoid conflicts with tray_manager. This is crucial for proper event propagation. ```yaml dependencies: app_links: ^6.3.3 ``` -------------------------------- ### Configure Flutter Library and Headers Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/linux/flutter/CMakeLists.txt This configures the Flutter library path and header include directories. It also sets up variables for the ICU data file, project build directory, and AOT library. These variables are published to the parent scope for use in other CMake files or build steps. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # 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/lib/libapp.so" PARENT_SCOPE) ``` -------------------------------- ### Create Flutter Interface Library Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/linux/flutter/CMakeLists.txt This creates an INTERFACE library target named 'flutter'. It specifies include directories and links against the Flutter library and system dependencies found earlier. This target simplifies linking against Flutter in other parts of the build. ```cmake add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Add Executable Target in CMake Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/windows/runner/CMakeLists.txt Defines the main executable target for the project, listing all source files, resource files, and manifest files. It also applies standard build settings and links necessary libraries. ```cmake add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "run_loop.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) apply_standard_settings(${BINARY_NAME}) target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Listen for Tray Events in Flutter Source: https://github.com/leanflutter/tray_manager/blob/main/README.md Implement the TrayListener mixin in a StatefulWidget to handle tray icon interactions such as mouse clicks and context menu item selections. Ensure the listener is added in initState and removed in dispose. ```dart import 'package:flutter/material.dart'; import 'package:tray_manager/tray_manager.dart'; class HomePage extends StatefulWidget { @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State with TrayListener { @override void initState() { trayManager.addListener(this); super.initState(); _init(); } @override void dispose() { trayManager.removeListener(this); super.dispose(); } void _init() { // ... } @override Widget build(BuildContext context) { // ... } @override void onTrayIconMouseDown() { // do something, for example pop up the menu trayManager.popUpContextMenu(); } @override void onTrayIconRightMouseDown() { // do something } @override void onTrayIconRightMouseUp() { // do something } @override void onTrayMenuItemClick(MenuItem menuItem) { if (menuItem.key == 'show_window') { // do something } else if (menuItem.key == 'exit_app') { // do something } } ``` -------------------------------- ### Define list_prepend CMake Function Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/linux/flutter/CMakeLists.txt This custom CMake function prepends a prefix to each element in a list. It is used as a workaround for older CMake versions that do not support `list(TRANSFORM ... PREPEND ...)`. Ensure the list variable is correctly defined before calling this function. ```cmake function(list_prepend LIST_NAME PREFIX) set(NEW_LIST "") foreach(element ${${LIST_NAME}}) list(APPEND NEW_LIST "${PREFIX}${element}") endforeach(element) set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) endfunction() ``` -------------------------------- ### Add Flutter Assemble Custom Target Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/windows/flutter/CMakeLists.txt Creates a custom target 'flutter_assemble' that depends on the output of the Flutter tool backend command, ensuring all generated Flutter artifacts are available. ```cmake add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### Define Flutter Assemble Custom Target Source: https://github.com/leanflutter/tray_manager/blob/main/packages/tray_manager/example/linux/flutter/CMakeLists.txt This defines a custom target `flutter_assemble` that depends on the Flutter library and its headers. This target ensures that the Flutter assets are built before they are needed by other targets. The `add_custom_command` is used to execute the Flutter tool backend script. ```cmake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/_phony_ COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.