### Install Application Target Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Installs the main application binary to the root of the installation prefix. This makes the executable available in the bundle. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Initializes CMake version and defines the project name and languages. This is a standard starting point for any CMake project. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) ``` -------------------------------- ### Installation Configuration Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/CMakeLists.txt Configures installation paths and ensures the 'install' step is part of the default build for Visual Studio projects. ```cmake set(BUILD_BUNDLE_DIR "$") 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 Bundled Libraries Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Iterates through a list of bundled libraries and installs each one to the 'lib' subdirectory of the installation prefix. This ensures all necessary dynamic libraries are included in the bundle. ```cmake foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Configure Installation Prefix Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Sets the installation prefix to a 'bundle' directory within the project's binary directory. This ensures that the 'install' command creates a relocatable bundle in the build directory by default. ```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 Application and Support Files Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/CMakeLists.txt Installs the main executable, ICU data, Flutter library, and bundled plugin libraries to the specified runtime destinations. ```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) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Flutter Library Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Installs the main Flutter library file to the 'lib' subdirectory of the installation prefix. This makes the core library accessible. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Assets and AOT Library Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/CMakeLists.txt Installs the Flutter assets directory and the AOT library (for Profile/Release builds) to the application's data directory. ```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(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Flutter Managed Directory Setup Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Sets the path for the Flutter managed directory. This is essential for including Flutter-specific build rules. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Install ICU Data File Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Installs the ICU data file to the 'data' subdirectory of the installation prefix. This is necessary for internationalization support. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Ensures the Flutter assets directory is completely re-copied on each build to prevent stale files. This is done by removing the existing directory and then installing the new one. ```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) ``` -------------------------------- ### Clean Build Bundle Directory Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Removes the build bundle directory before installation to ensure a clean state. This is executed as part of the installation process. ```cmake install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) ``` -------------------------------- ### Install AOT Library Conditionally Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Installs the AOT (Ahead-of-Time) library only for non-Debug build types. This ensures that performance-critical libraries are included in release builds. ```cmake # Install the AOT library on non-Debug builds only. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Set Flutter Library and Headers Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/flutter/CMakeLists.txt Defines the Flutter library path and headers, making them available in the parent scope for installation. It also sets the project build directory and AOT library path. ```cmake set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") # Configuration provided via flutter tool. include(${EPHEMERAL_DIR}/generated_config.cmake) # TODO: Move the rest of this into files in ephemeral. See # https://github.com/flutter/flutter/issues/57146. set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") # === Flutter Library === 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) ``` -------------------------------- ### Initialize SDK Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/README.md Initialize the SDK with your user ID and token. This is a required step before using other SDK features. ```dart WKIM.shared.setup(Options.newDefault('uid', 'token')); ``` -------------------------------- ### Connect to Server Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/README.md Establish a connection to the WuKongIM server. This must be called after SDK initialization. ```dart WKIM.shared.connectionManager.connect(); ``` -------------------------------- ### Link Libraries and Include Directories Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/runner/CMakeLists.txt Links the necessary Flutter libraries and the dwmapi.lib for Windows desktop integration. 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}") ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/runner/CMakeLists.txt Applies a standard set of build settings to the application target. This can be removed if custom build settings are required. ```cmake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### System Dependencies with PkgConfig Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Checks for GTK+ 3.0 using PkgConfig. This ensures the necessary GTK libraries are available for the application. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### Project and Build Configuration Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/CMakeLists.txt Sets the minimum CMake version, project name, executable name, and configures build types for multi-config generators or single-config builds. ```cmake cmake_minimum_required(VERSION 3.14) project(example LANGUAGES CXX) set(BINARY_NAME "example") cmake_policy(SET CMP0063 NEW) 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() ``` -------------------------------- ### Plugin Integration Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/CMakeLists.txt Includes generated CMake scripts for building and integrating plugins into the application. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### System-Level Dependencies Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/flutter/CMakeLists.txt Checks for required system libraries (GTK, GLIB, GIO) using PkgConfig for the Flutter Linux GTK build. ```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) ``` -------------------------------- ### Configure Server Address Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/README.md Set up a mechanism to dynamically fetch and provide the server address. This is useful for load balancing or when the IP address changes. ```dart WKIM.shared.options.getAddr = (Function(String address) complete) async { // 可通过接口获取后返回 String ip = await HttpUtils.getIP(); complete(ip); }; ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Applies standard C++ compilation features and options to a target. Use this to enforce C++14 and set compiler warnings and optimization levels. ```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() ``` -------------------------------- ### Add SDK Dependency Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/README.md Add the wukongimfluttersdk to your project's dependencies in pubspec.yaml. Check the latest version number from the pub.dev badge. ```yaml dependencies: wukongimfluttersdk: ^version // 版本号看上面 ``` -------------------------------- ### Import SDK Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/README.md Import the main SDK library into your Dart file to access its functionalities. ```dart import 'package:wukongimfluttersdk/wkim.dart'; ``` -------------------------------- ### Profile Build Mode Settings Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/CMakeLists.txt Defines linker and compiler flags for the 'Profile' build mode, typically by copying settings from the 'Release' mode. ```cmake set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") ``` -------------------------------- ### Enabling Modern CMake Behaviors Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Explicitly opts into modern CMake behaviors to avoid warnings with recent CMake versions. This ensures compatibility and leverages newer CMake features. ```cmake cmake_policy(SET CMP0063 NEW) ``` -------------------------------- ### Load Flutter Entrypoint with Service Worker Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/web/index.html This JavaScript code initializes the Flutter engine and runs the application. It's designed to be used with Flutter web builds that employ a service worker for asset loading and caching. ```javascript var serviceWorkerVersion = null; window.addEventListener('load', function(ev) { // Download main.dart.js _flutter.loader.loadEntrypoint({ serviceWorker: { serviceWorkerVersion: serviceWorkerVersion, }, onEntrypointLoaded: function(engineInitializer) { engineInitializer.initializeEngine().then(function(appRunner) { appRunner.runApp(); }); } }); }); ``` -------------------------------- ### Set Runtime Output Directory Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Configures the runtime output directory for the target binary to a specific subdirectory within the build directory. This is done to prevent users from running an unbundled copy of the application. ```cmake set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Configuring Runtime Library Path Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Sets the runtime search path for bundled libraries relative to the binary. This is important for ensuring that dynamically linked libraries can be found at runtime. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Link Application Dependencies Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Links the application target with necessary libraries, including the Flutter library and GTK. Add any other application-specific dependencies here. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### Define Application Executable Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Defines the main executable target for the application. Ensure source files are listed here, including generated Flutter plugin registration files. ```cmake add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) ``` -------------------------------- ### Setting Executable and Application IDs Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Defines the on-disk name of the application executable and its unique GTK application identifier. These are essential for application packaging and system integration. ```cmake set(BINARY_NAME "example") set(APPLICATION_ID "com.example.example") ``` -------------------------------- ### Flutter Tool Backend Custom Command Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/flutter/CMakeLists.txt A custom CMake command to execute the Flutter tool backend script, generating necessary build artifacts like the Flutter library and headers. ```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 ) ``` -------------------------------- ### Unicode and Standard Compilation Settings Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/CMakeLists.txt Enables Unicode support and defines a function to apply standard compilation features, options, and definitions to targets. ```cmake add_definitions(-DUNICODE -D_UNICODE) 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() ``` -------------------------------- ### Flutter and Application Subdirectories Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/CMakeLists.txt Includes the Flutter managed directory and the application's runner subdirectory, integrating them into the build. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) add_subdirectory("runner") ``` -------------------------------- ### Cross-Compilation Sysroot Configuration Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Configures the sysroot and find root paths for cross-compiling. This is critical when building for a different architecture or operating system than the build environment. ```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() ``` -------------------------------- ### Define Flutter Wrapper App Library Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/flutter/CMakeLists.txt Compiles C++ wrapper sources for the application runner into a static library. It links against the Flutter library and includes necessary directories. ```cmake # Wrapper sources needed for the runner. 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) ``` -------------------------------- ### Define Executable Target Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/runner/CMakeLists.txt Defines the main executable for the Windows runner. Ensure BINARY_NAME is consistent with the top-level CMakeLists.txt for `flutter run` to function correctly. Add any new source files to this list. ```cmake add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) ``` -------------------------------- ### Configure Flutter Library Interface Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/flutter/CMakeLists.txt Adds Flutter library headers and links the Flutter library to the 'flutter' interface target. It also ensures the 'flutter_assemble' dependency is met. ```cmake 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}/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Add Flutter Version Preprocessor Definitions Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/runner/CMakeLists.txt Adds preprocessor definitions for the Flutter build version, allowing access to version components within the C++ code. ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") ``` -------------------------------- ### Define Flutter Wrapper Plugin Library Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/flutter/CMakeLists.txt Compiles C++ wrapper sources for plugins into a static library. It applies standard build settings, sets position-independent code, and links against the Flutter library. ```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}/") # Wrapper sources needed for a plugin. 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) ``` -------------------------------- ### Listen for Connection Status Changes Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/README.md Add a listener to monitor the connection status with the server. This callback provides information about the connection state, reason, and connected node. ```dart WKIM.shared.connectionManager.addOnConnectionStatus('home', (status, reason,connectInfo) { if (status == WKConnectStatus.connecting) { // 连接中 } else if (status == WKConnectStatus.success) { var nodeId = connectInfo?.nodeId; // 节点id // 成功 } else if (status == WKConnectStatus.noNetwork) { // 网络异常 } else if (status == WKConnectStatus.syncMsg) { //同步消息中 } else if (status == WKConnectStatus.syncCompleted) { //同步完成 } }); ``` -------------------------------- ### Listen for Command Messages Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/README.md Register a listener to handle command (cmd) messages. These messages are used for specific control or signaling purposes within the application. ```dart WKIM.shared.cmdManager.addOnCmdListener('chat', (cmdMsg) { // todo 按需处理cmd消息 }); ``` -------------------------------- ### List Prepend Function Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/flutter/CMakeLists.txt A custom CMake function to prepend a prefix to each element in a list, as 'list(TRANSFORM ... PREPEND ...)' is not available in CMake 3.10. ```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() ``` -------------------------------- ### Listen for Message Insertion Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/README.md Register a listener to be notified when a message is successfully inserted into the local database. This is useful for updating the UI after a message is saved. ```dart WKIM.shared.messageManager.addOnMsgInsertedListener((wkMsg) { // todo 展示在UI上 }); ``` -------------------------------- ### Listen for New Messages Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/README.md Add a listener to receive new incoming messages. The callback receives a list of messages that need to be displayed in the UI. ```dart WKIM.shared.messageManager.addOnNewMsgListener('chat', (msgs) { // todo 展示在UI上 }); ``` -------------------------------- ### Add Flutter Tool Build Dependency Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/runner/CMakeLists.txt Ensures that the Flutter tool's assembly process is completed before the application target is built. This dependency is crucial and must not be removed. ```cmake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Listen for Message Refresh Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/README.md Set up a listener to refresh a specific message. This is typically used when a message's status or content needs to be updated in the UI. ```dart WKIM.shared.messageManager.addOnRefreshMsgListener('chat', (wkMsg) { // todo 刷新消息 }); ``` -------------------------------- ### Setting Default Build Type Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/CMakeLists.txt Sets the default build type to 'Debug' if not already specified. This ensures a consistent build configuration when not explicitly set by the user or environment. ```cmake 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() ``` -------------------------------- ### Flutter Assemble Custom Target Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/flutter/CMakeLists.txt A custom CMake target that depends on the output of the Flutter tool backend, ensuring build artifacts are available. ```cmake add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### Flutter Library Interface Target Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/linux/flutter/CMakeLists.txt Defines an INTERFACE library target for Flutter, including its include directories and linked libraries. ```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) ``` -------------------------------- ### Disconnect from Server Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/README.md Disconnect from the WuKongIM server. You can choose to either log out and prevent reconnection or disconnect while maintaining the possibility of automatic reconnection. ```dart // isLogout true:退出并不再重连 false:退出保持重连 WKIM.shared.connectionManager.disconnect(isLogout) ``` -------------------------------- ### Remove Event Listener Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/README.md Listeners with a 'key' can be removed using the same key. This is important for preventing duplicate callbacks and managing resources when a page is destroyed or the user logs out. ```dart // 包含`key`的事件监听均有移除监听的方法,为了避免重复收到事件回掉,在退出或销毁页面时通过传入的`key`移除事件 ``` -------------------------------- ### Disable Conflicting Windows Macros Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/example/windows/runner/CMakeLists.txt Disables Windows-specific macros like NOMINMAX that can conflict with C++ standard library functions. ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") ``` -------------------------------- ### Send Text Message Source: https://github.com/wukongim/wukongimfluttersdk/blob/master/README.md Send a text message to a specified channel. Ensure you have the correct channel ID and type. ```dart WKIM.shared.messageManager.sendMessage(WKTextContent('我是文本消息'), WKChannel(channelID, channelType)); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.