diff --git a/.idea/flutter_openim_sdk.iml b/.idea/flutter_openim_sdk.iml
index 841b64d..f66f4f5 100644
--- a/.idea/flutter_openim_sdk.iml
+++ b/.idea/flutter_openim_sdk.iml
@@ -30,6 +30,99 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml
index db4f9a0..2925ee6 100644
--- a/.idea/libraries/Dart_SDK.xml
+++ b/.idea/libraries/Dart_SDK.xml
@@ -1,27 +1,29 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 9cbc368..80a1400 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -3,4 +3,7 @@
+
+
+
\ No newline at end of file
diff --git a/android/src/main/kotlin/io/openim/flutter_openim_sdk/FlutterOpenimSdkPlugin.kt b/android/src/main/kotlin/io/openim/flutter_openim_sdk/FlutterOpenimSdkPlugin.kt
new file mode 100644
index 0000000..308391d
--- /dev/null
+++ b/android/src/main/kotlin/io/openim/flutter_openim_sdk/FlutterOpenimSdkPlugin.kt
@@ -0,0 +1,35 @@
+package io.openim.flutter_openim_sdk
+
+import androidx.annotation.NonNull
+
+import io.flutter.embedding.engine.plugins.FlutterPlugin
+import io.flutter.plugin.common.MethodCall
+import io.flutter.plugin.common.MethodChannel
+import io.flutter.plugin.common.MethodChannel.MethodCallHandler
+import io.flutter.plugin.common.MethodChannel.Result
+
+/** FlutterOpenimSdkPlugin */
+class FlutterOpenimSdkPlugin: FlutterPlugin, MethodCallHandler {
+ /// The MethodChannel that will the communication between Flutter and native Android
+ ///
+ /// This local reference serves to register the plugin with the Flutter Engine and unregister it
+ /// when the Flutter Engine is detached from the Activity
+ private lateinit var channel : MethodChannel
+
+ override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
+ channel = MethodChannel(flutterPluginBinding.binaryMessenger, "flutter_openim_sdk")
+ channel.setMethodCallHandler(this)
+ }
+
+ override fun onMethodCall(call: MethodCall, result: Result) {
+ if (call.method == "getPlatformVersion") {
+ result.success("Android ${android.os.Build.VERSION.RELEASE}")
+ } else {
+ result.notImplemented()
+ }
+ }
+
+ override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
+ channel.setMethodCallHandler(null)
+ }
+}
diff --git a/android/src/test/kotlin/io/openim/flutter_openim_sdk/FlutterOpenimSdkPluginTest.kt b/android/src/test/kotlin/io/openim/flutter_openim_sdk/FlutterOpenimSdkPluginTest.kt
new file mode 100644
index 0000000..22e697e
--- /dev/null
+++ b/android/src/test/kotlin/io/openim/flutter_openim_sdk/FlutterOpenimSdkPluginTest.kt
@@ -0,0 +1,27 @@
+package io.openim.flutter_openim_sdk
+
+import io.flutter.plugin.common.MethodCall
+import io.flutter.plugin.common.MethodChannel
+import kotlin.test.Test
+import org.mockito.Mockito
+
+/*
+ * This demonstrates a simple unit test of the Kotlin portion of this plugin's implementation.
+ *
+ * Once you have built the plugin's example app, you can run these tests from the command
+ * line by running `./gradlew testDebugUnitTest` in the `example/android/` directory, or
+ * you can run them directly from IDEs that support JUnit such as Android Studio.
+ */
+
+internal class FlutterOpenimSdkPluginTest {
+ @Test
+ fun onMethodCall_getPlatformVersion_returnsExpectedValue() {
+ val plugin = FlutterOpenimSdkPlugin()
+
+ val call = MethodCall("getPlatformVersion", null)
+ val mockResult: MethodChannel.Result = Mockito.mock(MethodChannel.Result::class.java)
+ plugin.onMethodCall(call, mockResult)
+
+ Mockito.verify(mockResult).success("Android " + android.os.Build.VERSION.RELEASE)
+ }
+}
diff --git a/example/OpenIM_v3_3e8b8fb2ecd8414db50838d9f7bcb19d.db b/example/OpenIM_v3_3e8b8fb2ecd8414db50838d9f7bcb19d.db
new file mode 100644
index 0000000..929664c
Binary files /dev/null and b/example/OpenIM_v3_3e8b8fb2ecd8414db50838d9f7bcb19d.db differ
diff --git a/example/android/app/src/main/kotlin/io/openim/flutter_openim_sdk_example/MainActivity.kt b/example/android/app/src/main/kotlin/io/openim/flutter_openim_sdk_example/MainActivity.kt
new file mode 100644
index 0000000..378d53d
--- /dev/null
+++ b/example/android/app/src/main/kotlin/io/openim/flutter_openim_sdk_example/MainActivity.kt
@@ -0,0 +1,5 @@
+package io.openim.flutter_openim_sdk_example
+
+import io.flutter.embedding.android.FlutterActivity
+
+class MainActivity: FlutterActivity()
diff --git a/example/integration_test/plugin_integration_test.dart b/example/integration_test/plugin_integration_test.dart
new file mode 100644
index 0000000..3d9044c
--- /dev/null
+++ b/example/integration_test/plugin_integration_test.dart
@@ -0,0 +1,25 @@
+// This is a basic Flutter integration test.
+//
+// Since integration tests run in a full Flutter application, they can interact
+// with the host side of a plugin implementation, unlike Dart unit tests.
+//
+// For more information about Flutter integration tests, please see
+// https://flutter.dev/to/integration-testing
+
+
+import 'package:flutter_test/flutter_test.dart';
+import 'package:integration_test/integration_test.dart';
+
+import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
+
+void main() {
+ IntegrationTestWidgetsFlutterBinding.ensureInitialized();
+
+ testWidgets('getPlatformVersion test', (WidgetTester tester) async {
+ final FlutterOpenimSdk plugin = FlutterOpenimSdk();
+ final String? version = await plugin.getPlatformVersion();
+ // The version string depends on the host platform running the test, so
+ // just assert that some non-empty string is returned.
+ expect(version?.isNotEmpty, true);
+ });
+}
diff --git a/example/lib/main.dart b/example/lib/main.dart
index 554deef..05da347 100644
--- a/example/lib/main.dart
+++ b/example/lib/main.dart
@@ -2,7 +2,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
void main() {
- runApp(MyApp());
+ try {
+ runApp(MyApp());
+ } catch (e, stackTrace) {
+ print('Error during app startup: $e');
+ print('Stack trace: $stackTrace');
+ }
}
class MyApp extends StatefulWidget {
@@ -14,12 +19,26 @@ class _MyAppState extends State {
@override
void initState() {
super.initState();
- OpenIM.iMManager.initSDK(
- platformID: 1,
- apiAddr: '',
- wsAddr: '',
- dataDir: '/',
- listener: OnConnectListener());
+ OpenIM.iMManager
+ .initSDK(
+ platformID: 1,
+ apiAddr: 'http://192.168.77.135:10002',
+ wsAddr: 'ws://192.168.77.135:10001',
+ dataDir: './',
+ listener: OnConnectListener())
+ .then((value) {
+ print('SDK initialized successfully');
+ OpenIM.iMManager
+ .login(
+ userID: "3e8b8fb2ecd8414db50838d9f7bcb19d",
+ token:
+ "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySUQiOiIzZThiOGZiMmVjZDg0MTRkYjUwODM4ZDlmN2JjYjE5ZCIsIlBsYXRmb3JtSUQiOjIsImV4cCI6MTc1Mzc1MTYyNywiaWF0IjoxNzQ1OTc1NjIyfQ.S-CxfETXYyLFe2VqStwbrVCRcB5j2T2qi-52y1L-3OI")
+ .then((value) {
+ print('Login successful');
+ }).catchError((error) {
+ print('Login failed: $error');
+ });
+ });
}
@override
diff --git a/example/pubspec.lock b/example/pubspec.lock
index 56cbd94..c110d01 100644
--- a/example/pubspec.lock
+++ b/example/pubspec.lock
@@ -5,42 +5,42 @@ packages:
dependency: transitive
description:
name: async
- sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
+ sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63
url: "https://pub.dev"
source: hosted
- version: "2.11.0"
+ version: "2.12.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
- sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
+ sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea"
url: "https://pub.dev"
source: hosted
- version: "2.1.1"
+ version: "2.1.2"
characters:
dependency: transitive
description:
name: characters
- sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
+ sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
url: "https://pub.dev"
source: hosted
- version: "1.3.0"
+ version: "1.4.0"
clock:
dependency: transitive
description:
name: clock
- sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
+ sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b
url: "https://pub.dev"
source: hosted
- version: "1.1.1"
+ version: "1.1.2"
collection:
dependency: transitive
description:
name: collection
- sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
+ sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
url: "https://pub.dev"
source: hosted
- version: "1.18.0"
+ version: "1.19.1"
cupertino_icons:
dependency: "direct main"
description:
@@ -53,10 +53,10 @@ packages:
dependency: transitive
description:
name: fake_async
- sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
+ sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc"
url: "https://pub.dev"
source: hosted
- version: "1.3.1"
+ version: "1.3.2"
flutter:
dependency: "direct main"
description: flutter
@@ -86,18 +86,18 @@ packages:
dependency: transitive
description:
name: leak_tracker
- sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
+ sha256: c35baad643ba394b40aac41080300150a4f08fd0fd6a10378f8f7c6bc161acec
url: "https://pub.dev"
source: hosted
- version: "10.0.5"
+ version: "10.0.8"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
- sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
+ sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573
url: "https://pub.dev"
source: hosted
- version: "3.0.5"
+ version: "3.0.9"
leak_tracker_testing:
dependency: transitive
description:
@@ -118,10 +118,10 @@ packages:
dependency: transitive
description:
name: matcher
- sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
+ sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
url: "https://pub.dev"
source: hosted
- version: "0.12.16+1"
+ version: "0.12.17"
material_color_utilities:
dependency: transitive
description:
@@ -134,71 +134,71 @@ packages:
dependency: transitive
description:
name: meta
- sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
+ sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
url: "https://pub.dev"
source: hosted
- version: "1.15.0"
+ version: "1.16.0"
path:
dependency: transitive
description:
name: path
- sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
+ sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
url: "https://pub.dev"
source: hosted
- version: "1.9.0"
+ version: "1.9.1"
sky_engine:
dependency: transitive
description: flutter
source: sdk
- version: "0.0.99"
+ version: "0.0.0"
source_span:
dependency: transitive
description:
name: source_span
- sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
+ sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c"
url: "https://pub.dev"
source: hosted
- version: "1.10.0"
+ version: "1.10.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
- sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
+ sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1"
url: "https://pub.dev"
source: hosted
- version: "1.11.1"
+ version: "1.12.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
- sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
+ sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d"
url: "https://pub.dev"
source: hosted
- version: "2.1.2"
+ version: "2.1.4"
string_scanner:
dependency: transitive
description:
name: string_scanner
- sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
+ sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43"
url: "https://pub.dev"
source: hosted
- version: "1.2.0"
+ version: "1.4.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
- sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
+ sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e"
url: "https://pub.dev"
source: hosted
- version: "1.2.1"
+ version: "1.2.2"
test_api:
dependency: transitive
description:
name: test_api
- sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
+ sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd
url: "https://pub.dev"
source: hosted
- version: "0.7.2"
+ version: "0.7.4"
vector_math:
dependency: transitive
description:
@@ -211,10 +211,10 @@ packages:
dependency: transitive
description:
name: vm_service
- sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
+ sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14"
url: "https://pub.dev"
source: hosted
- version: "14.2.5"
+ version: "14.3.1"
sdks:
- dart: ">=3.4.4 <4.0.0"
+ dart: ">=3.7.0-0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
diff --git a/example/windows/.gitignore b/example/windows/.gitignore
new file mode 100644
index 0000000..d492d0d
--- /dev/null
+++ b/example/windows/.gitignore
@@ -0,0 +1,17 @@
+flutter/ephemeral/
+
+# Visual Studio user-specific files.
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# Visual Studio build-related files.
+x64/
+x86/
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!*.[Cc]ache/
diff --git a/example/windows/CMakeLists.txt b/example/windows/CMakeLists.txt
new file mode 100644
index 0000000..7bc7571
--- /dev/null
+++ b/example/windows/CMakeLists.txt
@@ -0,0 +1,110 @@
+# Project-level configuration.
+cmake_minimum_required(VERSION 3.14)
+project(flutter_openim_sdk_example LANGUAGES CXX)
+
+# The name of the executable created for the application. Change this to change
+# the on-disk name of your application.
+set(BINARY_NAME "flutter_openim_sdk_example")
+
+# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
+# versions of CMake.
+cmake_policy(VERSION 3.14...3.25)
+
+# Define build configuration option.
+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()
+# Define settings for the Profile build mode.
+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}")
+
+# Use Unicode for all projects.
+add_definitions(-DUNICODE -D_UNICODE)
+
+# Compilation settings that should be applied to most targets.
+#
+# Be cautious about adding new options here, as plugins use this function by
+# default. In most cases, you should add new options to specific targets instead
+# of modifying this function.
+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 library and tool build rules.
+set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
+add_subdirectory(${FLUTTER_MANAGED_DIR})
+
+# Application build; see runner/CMakeLists.txt.
+add_subdirectory("runner")
+
+# Enable the test target.
+set(include_flutter_openim_sdk_tests TRUE)
+
+# Generated plugin build rules, which manage building the plugins and adding
+# them to the application.
+include(flutter/generated_plugins.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()
+
+# Copy the native assets provided by the build.dart from all packages.
+set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/")
+install(DIRECTORY "${NATIVE_ASSETS_DIR}"
+ DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
+ COMPONENT Runtime)
+
+# 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)
diff --git a/example/windows/flutter/CMakeLists.txt b/example/windows/flutter/CMakeLists.txt
new file mode 100644
index 0000000..903f489
--- /dev/null
+++ b/example/windows/flutter/CMakeLists.txt
@@ -0,0 +1,109 @@
+# This file controls Flutter-level build steps. It should not be edited.
+cmake_minimum_required(VERSION 3.14)
+
+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")
+
+# Set fallback configurations for older versions of the flutter tool.
+if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
+ set(FLUTTER_TARGET_PLATFORM "windows-x64")
+endif()
+
+# === 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)
+
+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)
+
+# === Wrapper ===
+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)
+
+# 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)
+
+# === Flutter tool backend ===
+# _phony_ is a non-existent file to force this command to run every time,
+# since currently there's no way to get a full input/output list from the
+# flutter tool.
+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
+)
+add_custom_target(flutter_assemble DEPENDS
+ "${FLUTTER_LIBRARY}"
+ ${FLUTTER_LIBRARY_HEADERS}
+ ${CPP_WRAPPER_SOURCES_CORE}
+ ${CPP_WRAPPER_SOURCES_PLUGIN}
+ ${CPP_WRAPPER_SOURCES_APP}
+)
diff --git a/example/windows/flutter/generated_plugin_registrant.cc b/example/windows/flutter/generated_plugin_registrant.cc
new file mode 100644
index 0000000..4193c00
--- /dev/null
+++ b/example/windows/flutter/generated_plugin_registrant.cc
@@ -0,0 +1,14 @@
+//
+// Generated file. Do not edit.
+//
+
+// clang-format off
+
+#include "generated_plugin_registrant.h"
+
+#include
+
+void RegisterPlugins(flutter::PluginRegistry* registry) {
+ FlutterOpenimSdkPluginRegisterWithRegistrar(
+ registry->GetRegistrarForPlugin("FlutterOpenimSdkPlugin"));
+}
diff --git a/example/windows/flutter/generated_plugin_registrant.h b/example/windows/flutter/generated_plugin_registrant.h
new file mode 100644
index 0000000..dc139d8
--- /dev/null
+++ b/example/windows/flutter/generated_plugin_registrant.h
@@ -0,0 +1,15 @@
+//
+// Generated file. Do not edit.
+//
+
+// clang-format off
+
+#ifndef GENERATED_PLUGIN_REGISTRANT_
+#define GENERATED_PLUGIN_REGISTRANT_
+
+#include
+
+// Registers Flutter plugins.
+void RegisterPlugins(flutter::PluginRegistry* registry);
+
+#endif // GENERATED_PLUGIN_REGISTRANT_
diff --git a/example/windows/flutter/generated_plugins.cmake b/example/windows/flutter/generated_plugins.cmake
new file mode 100644
index 0000000..89b03b8
--- /dev/null
+++ b/example/windows/flutter/generated_plugins.cmake
@@ -0,0 +1,24 @@
+#
+# Generated file, do not edit.
+#
+
+list(APPEND FLUTTER_PLUGIN_LIST
+ flutter_openim_sdk
+)
+
+list(APPEND FLUTTER_FFI_PLUGIN_LIST
+)
+
+set(PLUGIN_BUNDLED_LIBRARIES)
+
+foreach(plugin ${FLUTTER_PLUGIN_LIST})
+ add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin})
+ target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
+ list(APPEND PLUGIN_BUNDLED_LIBRARIES $)
+ list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
+endforeach(plugin)
+
+foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
+ add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
+ list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
+endforeach(ffi_plugin)
diff --git a/example/windows/runner/CMakeLists.txt b/example/windows/runner/CMakeLists.txt
new file mode 100644
index 0000000..394917c
--- /dev/null
+++ b/example/windows/runner/CMakeLists.txt
@@ -0,0 +1,40 @@
+cmake_minimum_required(VERSION 3.14)
+project(runner LANGUAGES CXX)
+
+# Define the application target. To change its name, change BINARY_NAME in the
+# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer
+# work.
+#
+# Any new source files that you add to the application should be added here.
+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"
+)
+
+# Apply the standard set of build settings. This can be removed for applications
+# that need different build settings.
+apply_standard_settings(${BINARY_NAME})
+
+# Add preprocessor definitions for the build version.
+target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"")
+target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}")
+target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}")
+target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}")
+target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}")
+
+# Disable Windows macros that collide with C++ standard library functions.
+target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
+
+# Add dependency libraries and include directories. Add any application-specific
+# dependencies here.
+target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
+target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib")
+target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
+
+# Run the Flutter tool portions of the build. This must not be removed.
+add_dependencies(${BINARY_NAME} flutter_assemble)
diff --git a/example/windows/runner/Runner.rc b/example/windows/runner/Runner.rc
new file mode 100644
index 0000000..db1cd2d
--- /dev/null
+++ b/example/windows/runner/Runner.rc
@@ -0,0 +1,121 @@
+// Microsoft Visual C++ generated resource script.
+//
+#pragma code_page(65001)
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "winres.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// English (United States) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE
+BEGIN
+ "#include ""winres.h""\r\n"
+ "\0"
+END
+
+3 TEXTINCLUDE
+BEGIN
+ "\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Icon
+//
+
+// Icon with lowest ID value placed first to ensure application icon
+// remains consistent on all systems.
+IDI_APP_ICON ICON "resources\\app_icon.ico"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD)
+#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD
+#else
+#define VERSION_AS_NUMBER 1,0,0,0
+#endif
+
+#if defined(FLUTTER_VERSION)
+#define VERSION_AS_STRING FLUTTER_VERSION
+#else
+#define VERSION_AS_STRING "1.0.0"
+#endif
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION VERSION_AS_NUMBER
+ PRODUCTVERSION VERSION_AS_NUMBER
+ FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
+#ifdef _DEBUG
+ FILEFLAGS VS_FF_DEBUG
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS VOS__WINDOWS32
+ FILETYPE VFT_APP
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904e4"
+ BEGIN
+ VALUE "CompanyName", "io.openim" "\0"
+ VALUE "FileDescription", "flutter_openim_sdk_example" "\0"
+ VALUE "FileVersion", VERSION_AS_STRING "\0"
+ VALUE "InternalName", "flutter_openim_sdk_example" "\0"
+ VALUE "LegalCopyright", "Copyright (C) 2025 io.openim. All rights reserved." "\0"
+ VALUE "OriginalFilename", "flutter_openim_sdk_example.exe" "\0"
+ VALUE "ProductName", "flutter_openim_sdk_example" "\0"
+ VALUE "ProductVersion", VERSION_AS_STRING "\0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1252
+ END
+END
+
+#endif // English (United States) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
diff --git a/example/windows/runner/flutter_window.cpp b/example/windows/runner/flutter_window.cpp
new file mode 100644
index 0000000..955ee30
--- /dev/null
+++ b/example/windows/runner/flutter_window.cpp
@@ -0,0 +1,71 @@
+#include "flutter_window.h"
+
+#include
+
+#include "flutter/generated_plugin_registrant.h"
+
+FlutterWindow::FlutterWindow(const flutter::DartProject& project)
+ : project_(project) {}
+
+FlutterWindow::~FlutterWindow() {}
+
+bool FlutterWindow::OnCreate() {
+ if (!Win32Window::OnCreate()) {
+ return false;
+ }
+
+ RECT frame = GetClientArea();
+
+ // The size here must match the window dimensions to avoid unnecessary surface
+ // creation / destruction in the startup path.
+ flutter_controller_ = std::make_unique(
+ frame.right - frame.left, frame.bottom - frame.top, project_);
+ // Ensure that basic setup of the controller was successful.
+ if (!flutter_controller_->engine() || !flutter_controller_->view()) {
+ return false;
+ }
+ RegisterPlugins(flutter_controller_->engine());
+ SetChildContent(flutter_controller_->view()->GetNativeWindow());
+
+ flutter_controller_->engine()->SetNextFrameCallback([&]() {
+ this->Show();
+ });
+
+ // Flutter can complete the first frame before the "show window" callback is
+ // registered. The following call ensures a frame is pending to ensure the
+ // window is shown. It is a no-op if the first frame hasn't completed yet.
+ flutter_controller_->ForceRedraw();
+
+ return true;
+}
+
+void FlutterWindow::OnDestroy() {
+ if (flutter_controller_) {
+ flutter_controller_ = nullptr;
+ }
+
+ Win32Window::OnDestroy();
+}
+
+LRESULT
+FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
+ WPARAM const wparam,
+ LPARAM const lparam) noexcept {
+ // Give Flutter, including plugins, an opportunity to handle window messages.
+ if (flutter_controller_) {
+ std::optional result =
+ flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
+ lparam);
+ if (result) {
+ return *result;
+ }
+ }
+
+ switch (message) {
+ case WM_FONTCHANGE:
+ flutter_controller_->engine()->ReloadSystemFonts();
+ break;
+ }
+
+ return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
+}
diff --git a/example/windows/runner/flutter_window.h b/example/windows/runner/flutter_window.h
new file mode 100644
index 0000000..6da0652
--- /dev/null
+++ b/example/windows/runner/flutter_window.h
@@ -0,0 +1,33 @@
+#ifndef RUNNER_FLUTTER_WINDOW_H_
+#define RUNNER_FLUTTER_WINDOW_H_
+
+#include
+#include
+
+#include
+
+#include "win32_window.h"
+
+// A window that does nothing but host a Flutter view.
+class FlutterWindow : public Win32Window {
+ public:
+ // Creates a new FlutterWindow hosting a Flutter view running |project|.
+ explicit FlutterWindow(const flutter::DartProject& project);
+ virtual ~FlutterWindow();
+
+ protected:
+ // Win32Window:
+ bool OnCreate() override;
+ void OnDestroy() override;
+ LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,
+ LPARAM const lparam) noexcept override;
+
+ private:
+ // The project to run.
+ flutter::DartProject project_;
+
+ // The Flutter instance hosted by this window.
+ std::unique_ptr flutter_controller_;
+};
+
+#endif // RUNNER_FLUTTER_WINDOW_H_
diff --git a/example/windows/runner/main.cpp b/example/windows/runner/main.cpp
new file mode 100644
index 0000000..787bc4b
--- /dev/null
+++ b/example/windows/runner/main.cpp
@@ -0,0 +1,43 @@
+#include
+#include
+#include
+
+#include "flutter_window.h"
+#include "utils.h"
+
+int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
+ _In_ wchar_t *command_line, _In_ int show_command) {
+ // Attach to console when present (e.g., 'flutter run') or create a
+ // new console when running with a debugger.
+ if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
+ CreateAndAttachConsole();
+ }
+
+ // Initialize COM, so that it is available for use in the library and/or
+ // plugins.
+ ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
+
+ flutter::DartProject project(L"data");
+
+ std::vector command_line_arguments =
+ GetCommandLineArguments();
+
+ project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
+
+ FlutterWindow window(project);
+ Win32Window::Point origin(10, 10);
+ Win32Window::Size size(1280, 720);
+ if (!window.Create(L"flutter_openim_sdk_example", origin, size)) {
+ return EXIT_FAILURE;
+ }
+ window.SetQuitOnClose(true);
+
+ ::MSG msg;
+ while (::GetMessage(&msg, nullptr, 0, 0)) {
+ ::TranslateMessage(&msg);
+ ::DispatchMessage(&msg);
+ }
+
+ ::CoUninitialize();
+ return EXIT_SUCCESS;
+}
diff --git a/example/windows/runner/resource.h b/example/windows/runner/resource.h
new file mode 100644
index 0000000..66a65d1
--- /dev/null
+++ b/example/windows/runner/resource.h
@@ -0,0 +1,16 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by Runner.rc
+//
+#define IDI_APP_ICON 101
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 102
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1001
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
diff --git a/example/windows/runner/resources/app_icon.ico b/example/windows/runner/resources/app_icon.ico
new file mode 100644
index 0000000..c04e20c
Binary files /dev/null and b/example/windows/runner/resources/app_icon.ico differ
diff --git a/example/windows/runner/runner.exe.manifest b/example/windows/runner/runner.exe.manifest
new file mode 100644
index 0000000..153653e
--- /dev/null
+++ b/example/windows/runner/runner.exe.manifest
@@ -0,0 +1,14 @@
+
+
+
+
+ PerMonitorV2
+
+
+
+
+
+
+
+
+
diff --git a/example/windows/runner/utils.cpp b/example/windows/runner/utils.cpp
new file mode 100644
index 0000000..3a0b465
--- /dev/null
+++ b/example/windows/runner/utils.cpp
@@ -0,0 +1,65 @@
+#include "utils.h"
+
+#include
+#include
+#include
+#include
+
+#include
+
+void CreateAndAttachConsole() {
+ if (::AllocConsole()) {
+ FILE *unused;
+ if (freopen_s(&unused, "CONOUT$", "w", stdout)) {
+ _dup2(_fileno(stdout), 1);
+ }
+ if (freopen_s(&unused, "CONOUT$", "w", stderr)) {
+ _dup2(_fileno(stdout), 2);
+ }
+ std::ios::sync_with_stdio();
+ FlutterDesktopResyncOutputStreams();
+ }
+}
+
+std::vector GetCommandLineArguments() {
+ // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use.
+ int argc;
+ wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
+ if (argv == nullptr) {
+ return std::vector();
+ }
+
+ std::vector command_line_arguments;
+
+ // Skip the first argument as it's the binary name.
+ for (int i = 1; i < argc; i++) {
+ command_line_arguments.push_back(Utf8FromUtf16(argv[i]));
+ }
+
+ ::LocalFree(argv);
+
+ return command_line_arguments;
+}
+
+std::string Utf8FromUtf16(const wchar_t* utf16_string) {
+ if (utf16_string == nullptr) {
+ return std::string();
+ }
+ unsigned int target_length = ::WideCharToMultiByte(
+ CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
+ -1, nullptr, 0, nullptr, nullptr)
+ -1; // remove the trailing null character
+ int input_length = (int)wcslen(utf16_string);
+ std::string utf8_string;
+ if (target_length == 0 || target_length > utf8_string.max_size()) {
+ return utf8_string;
+ }
+ utf8_string.resize(target_length);
+ int converted_length = ::WideCharToMultiByte(
+ CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
+ input_length, utf8_string.data(), target_length, nullptr, nullptr);
+ if (converted_length == 0) {
+ return std::string();
+ }
+ return utf8_string;
+}
diff --git a/example/windows/runner/utils.h b/example/windows/runner/utils.h
new file mode 100644
index 0000000..3879d54
--- /dev/null
+++ b/example/windows/runner/utils.h
@@ -0,0 +1,19 @@
+#ifndef RUNNER_UTILS_H_
+#define RUNNER_UTILS_H_
+
+#include
+#include
+
+// Creates a console for the process, and redirects stdout and stderr to
+// it for both the runner and the Flutter library.
+void CreateAndAttachConsole();
+
+// Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string
+// encoded in UTF-8. Returns an empty std::string on failure.
+std::string Utf8FromUtf16(const wchar_t* utf16_string);
+
+// Gets the command line arguments passed in as a std::vector,
+// encoded in UTF-8. Returns an empty std::vector on failure.
+std::vector GetCommandLineArguments();
+
+#endif // RUNNER_UTILS_H_
diff --git a/example/windows/runner/win32_window.cpp b/example/windows/runner/win32_window.cpp
new file mode 100644
index 0000000..60608d0
--- /dev/null
+++ b/example/windows/runner/win32_window.cpp
@@ -0,0 +1,288 @@
+#include "win32_window.h"
+
+#include
+#include
+
+#include "resource.h"
+
+namespace {
+
+/// Window attribute that enables dark mode window decorations.
+///
+/// Redefined in case the developer's machine has a Windows SDK older than
+/// version 10.0.22000.0.
+/// See: https://docs.microsoft.com/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
+#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
+#define DWMWA_USE_IMMERSIVE_DARK_MODE 20
+#endif
+
+constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW";
+
+/// Registry key for app theme preference.
+///
+/// A value of 0 indicates apps should use dark mode. A non-zero or missing
+/// value indicates apps should use light mode.
+constexpr const wchar_t kGetPreferredBrightnessRegKey[] =
+ L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
+constexpr const wchar_t kGetPreferredBrightnessRegValue[] = L"AppsUseLightTheme";
+
+// The number of Win32Window objects that currently exist.
+static int g_active_window_count = 0;
+
+using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd);
+
+// Scale helper to convert logical scaler values to physical using passed in
+// scale factor
+int Scale(int source, double scale_factor) {
+ return static_cast(source * scale_factor);
+}
+
+// Dynamically loads the |EnableNonClientDpiScaling| from the User32 module.
+// This API is only needed for PerMonitor V1 awareness mode.
+void EnableFullDpiSupportIfAvailable(HWND hwnd) {
+ HMODULE user32_module = LoadLibraryA("User32.dll");
+ if (!user32_module) {
+ return;
+ }
+ auto enable_non_client_dpi_scaling =
+ reinterpret_cast(
+ GetProcAddress(user32_module, "EnableNonClientDpiScaling"));
+ if (enable_non_client_dpi_scaling != nullptr) {
+ enable_non_client_dpi_scaling(hwnd);
+ }
+ FreeLibrary(user32_module);
+}
+
+} // namespace
+
+// Manages the Win32Window's window class registration.
+class WindowClassRegistrar {
+ public:
+ ~WindowClassRegistrar() = default;
+
+ // Returns the singleton registrar instance.
+ static WindowClassRegistrar* GetInstance() {
+ if (!instance_) {
+ instance_ = new WindowClassRegistrar();
+ }
+ return instance_;
+ }
+
+ // Returns the name of the window class, registering the class if it hasn't
+ // previously been registered.
+ const wchar_t* GetWindowClass();
+
+ // Unregisters the window class. Should only be called if there are no
+ // instances of the window.
+ void UnregisterWindowClass();
+
+ private:
+ WindowClassRegistrar() = default;
+
+ static WindowClassRegistrar* instance_;
+
+ bool class_registered_ = false;
+};
+
+WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr;
+
+const wchar_t* WindowClassRegistrar::GetWindowClass() {
+ if (!class_registered_) {
+ WNDCLASS window_class{};
+ window_class.hCursor = LoadCursor(nullptr, IDC_ARROW);
+ window_class.lpszClassName = kWindowClassName;
+ window_class.style = CS_HREDRAW | CS_VREDRAW;
+ window_class.cbClsExtra = 0;
+ window_class.cbWndExtra = 0;
+ window_class.hInstance = GetModuleHandle(nullptr);
+ window_class.hIcon =
+ LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON));
+ window_class.hbrBackground = 0;
+ window_class.lpszMenuName = nullptr;
+ window_class.lpfnWndProc = Win32Window::WndProc;
+ RegisterClass(&window_class);
+ class_registered_ = true;
+ }
+ return kWindowClassName;
+}
+
+void WindowClassRegistrar::UnregisterWindowClass() {
+ UnregisterClass(kWindowClassName, nullptr);
+ class_registered_ = false;
+}
+
+Win32Window::Win32Window() {
+ ++g_active_window_count;
+}
+
+Win32Window::~Win32Window() {
+ --g_active_window_count;
+ Destroy();
+}
+
+bool Win32Window::Create(const std::wstring& title,
+ const Point& origin,
+ const Size& size) {
+ Destroy();
+
+ const wchar_t* window_class =
+ WindowClassRegistrar::GetInstance()->GetWindowClass();
+
+ const POINT target_point = {static_cast(origin.x),
+ static_cast(origin.y)};
+ HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST);
+ UINT dpi = FlutterDesktopGetDpiForMonitor(monitor);
+ double scale_factor = dpi / 96.0;
+
+ HWND window = CreateWindow(
+ window_class, title.c_str(), WS_OVERLAPPEDWINDOW,
+ Scale(origin.x, scale_factor), Scale(origin.y, scale_factor),
+ Scale(size.width, scale_factor), Scale(size.height, scale_factor),
+ nullptr, nullptr, GetModuleHandle(nullptr), this);
+
+ if (!window) {
+ return false;
+ }
+
+ UpdateTheme(window);
+
+ return OnCreate();
+}
+
+bool Win32Window::Show() {
+ return ShowWindow(window_handle_, SW_SHOWNORMAL);
+}
+
+// static
+LRESULT CALLBACK Win32Window::WndProc(HWND const window,
+ UINT const message,
+ WPARAM const wparam,
+ LPARAM const lparam) noexcept {
+ if (message == WM_NCCREATE) {
+ auto window_struct = reinterpret_cast(lparam);
+ SetWindowLongPtr(window, GWLP_USERDATA,
+ reinterpret_cast(window_struct->lpCreateParams));
+
+ auto that = static_cast(window_struct->lpCreateParams);
+ EnableFullDpiSupportIfAvailable(window);
+ that->window_handle_ = window;
+ } else if (Win32Window* that = GetThisFromHandle(window)) {
+ return that->MessageHandler(window, message, wparam, lparam);
+ }
+
+ return DefWindowProc(window, message, wparam, lparam);
+}
+
+LRESULT
+Win32Window::MessageHandler(HWND hwnd,
+ UINT const message,
+ WPARAM const wparam,
+ LPARAM const lparam) noexcept {
+ switch (message) {
+ case WM_DESTROY:
+ window_handle_ = nullptr;
+ Destroy();
+ if (quit_on_close_) {
+ PostQuitMessage(0);
+ }
+ return 0;
+
+ case WM_DPICHANGED: {
+ auto newRectSize = reinterpret_cast(lparam);
+ LONG newWidth = newRectSize->right - newRectSize->left;
+ LONG newHeight = newRectSize->bottom - newRectSize->top;
+
+ SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth,
+ newHeight, SWP_NOZORDER | SWP_NOACTIVATE);
+
+ return 0;
+ }
+ case WM_SIZE: {
+ RECT rect = GetClientArea();
+ if (child_content_ != nullptr) {
+ // Size and position the child window.
+ MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left,
+ rect.bottom - rect.top, TRUE);
+ }
+ return 0;
+ }
+
+ case WM_ACTIVATE:
+ if (child_content_ != nullptr) {
+ SetFocus(child_content_);
+ }
+ return 0;
+
+ case WM_DWMCOLORIZATIONCOLORCHANGED:
+ UpdateTheme(hwnd);
+ return 0;
+ }
+
+ return DefWindowProc(window_handle_, message, wparam, lparam);
+}
+
+void Win32Window::Destroy() {
+ OnDestroy();
+
+ if (window_handle_) {
+ DestroyWindow(window_handle_);
+ window_handle_ = nullptr;
+ }
+ if (g_active_window_count == 0) {
+ WindowClassRegistrar::GetInstance()->UnregisterWindowClass();
+ }
+}
+
+Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept {
+ return reinterpret_cast(
+ GetWindowLongPtr(window, GWLP_USERDATA));
+}
+
+void Win32Window::SetChildContent(HWND content) {
+ child_content_ = content;
+ SetParent(content, window_handle_);
+ RECT frame = GetClientArea();
+
+ MoveWindow(content, frame.left, frame.top, frame.right - frame.left,
+ frame.bottom - frame.top, true);
+
+ SetFocus(child_content_);
+}
+
+RECT Win32Window::GetClientArea() {
+ RECT frame;
+ GetClientRect(window_handle_, &frame);
+ return frame;
+}
+
+HWND Win32Window::GetHandle() {
+ return window_handle_;
+}
+
+void Win32Window::SetQuitOnClose(bool quit_on_close) {
+ quit_on_close_ = quit_on_close;
+}
+
+bool Win32Window::OnCreate() {
+ // No-op; provided for subclasses.
+ return true;
+}
+
+void Win32Window::OnDestroy() {
+ // No-op; provided for subclasses.
+}
+
+void Win32Window::UpdateTheme(HWND const window) {
+ DWORD light_mode;
+ DWORD light_mode_size = sizeof(light_mode);
+ LSTATUS result = RegGetValue(HKEY_CURRENT_USER, kGetPreferredBrightnessRegKey,
+ kGetPreferredBrightnessRegValue,
+ RRF_RT_REG_DWORD, nullptr, &light_mode,
+ &light_mode_size);
+
+ if (result == ERROR_SUCCESS) {
+ BOOL enable_dark_mode = light_mode == 0;
+ DwmSetWindowAttribute(window, DWMWA_USE_IMMERSIVE_DARK_MODE,
+ &enable_dark_mode, sizeof(enable_dark_mode));
+ }
+}
diff --git a/example/windows/runner/win32_window.h b/example/windows/runner/win32_window.h
new file mode 100644
index 0000000..e901dde
--- /dev/null
+++ b/example/windows/runner/win32_window.h
@@ -0,0 +1,102 @@
+#ifndef RUNNER_WIN32_WINDOW_H_
+#define RUNNER_WIN32_WINDOW_H_
+
+#include
+
+#include
+#include
+#include
+
+// A class abstraction for a high DPI-aware Win32 Window. Intended to be
+// inherited from by classes that wish to specialize with custom
+// rendering and input handling
+class Win32Window {
+ public:
+ struct Point {
+ unsigned int x;
+ unsigned int y;
+ Point(unsigned int x, unsigned int y) : x(x), y(y) {}
+ };
+
+ struct Size {
+ unsigned int width;
+ unsigned int height;
+ Size(unsigned int width, unsigned int height)
+ : width(width), height(height) {}
+ };
+
+ Win32Window();
+ virtual ~Win32Window();
+
+ // Creates a win32 window with |title| that is positioned and sized using
+ // |origin| and |size|. New windows are created on the default monitor. Window
+ // sizes are specified to the OS in physical pixels, hence to ensure a
+ // consistent size this function will scale the inputted width and height as
+ // as appropriate for the default monitor. The window is invisible until
+ // |Show| is called. Returns true if the window was created successfully.
+ bool Create(const std::wstring& title, const Point& origin, const Size& size);
+
+ // Show the current window. Returns true if the window was successfully shown.
+ bool Show();
+
+ // Release OS resources associated with window.
+ void Destroy();
+
+ // Inserts |content| into the window tree.
+ void SetChildContent(HWND content);
+
+ // Returns the backing Window handle to enable clients to set icon and other
+ // window properties. Returns nullptr if the window has been destroyed.
+ HWND GetHandle();
+
+ // If true, closing this window will quit the application.
+ void SetQuitOnClose(bool quit_on_close);
+
+ // Return a RECT representing the bounds of the current client area.
+ RECT GetClientArea();
+
+ protected:
+ // Processes and route salient window messages for mouse handling,
+ // size change and DPI. Delegates handling of these to member overloads that
+ // inheriting classes can handle.
+ virtual LRESULT MessageHandler(HWND window,
+ UINT const message,
+ WPARAM const wparam,
+ LPARAM const lparam) noexcept;
+
+ // Called when CreateAndShow is called, allowing subclass window-related
+ // setup. Subclasses should return false if setup fails.
+ virtual bool OnCreate();
+
+ // Called when Destroy is called.
+ virtual void OnDestroy();
+
+ private:
+ friend class WindowClassRegistrar;
+
+ // OS callback called by message pump. Handles the WM_NCCREATE message which
+ // is passed when the non-client area is being created and enables automatic
+ // non-client DPI scaling so that the non-client area automatically
+ // responds to changes in DPI. All other messages are handled by
+ // MessageHandler.
+ static LRESULT CALLBACK WndProc(HWND const window,
+ UINT const message,
+ WPARAM const wparam,
+ LPARAM const lparam) noexcept;
+
+ // Retrieves a class instance pointer for |window|
+ static Win32Window* GetThisFromHandle(HWND const window) noexcept;
+
+ // Update the window frame's theme to match the system theme.
+ static void UpdateTheme(HWND const window);
+
+ bool quit_on_close_ = false;
+
+ // window handle for top level window.
+ HWND window_handle_ = nullptr;
+
+ // window handle for hosted content.
+ HWND child_content_ = nullptr;
+};
+
+#endif // RUNNER_WIN32_WINDOW_H_
diff --git a/ios/.gitignore b/ios/.gitignore
new file mode 100644
index 0000000..034771f
--- /dev/null
+++ b/ios/.gitignore
@@ -0,0 +1,38 @@
+.idea/
+.vagrant/
+.sconsign.dblite
+.svn/
+
+.DS_Store
+*.swp
+profile
+
+DerivedData/
+build/
+GeneratedPluginRegistrant.h
+GeneratedPluginRegistrant.m
+
+.generated/
+
+*.pbxuser
+*.mode1v3
+*.mode2v3
+*.perspectivev3
+
+!default.pbxuser
+!default.mode1v3
+!default.mode2v3
+!default.perspectivev3
+
+xcuserdata
+
+*.moved-aside
+
+*.pyc
+*sync/
+Icon?
+.tags*
+
+/Flutter/Generated.xcconfig
+/Flutter/ephemeral/
+/Flutter/flutter_export_environment.sh
diff --git a/pubspec.yaml b/pubspec.yaml
index 651869d..5a41d7d 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -32,7 +32,8 @@ flutter:
pluginClass: FlutterOpenimSdkPlugin
ios:
pluginClass: FlutterOpenimSdkPlugin
-
+ windows:
+ pluginClass: FlutterOpenimSdkPlugin
# To add assets to your plugin package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
diff --git a/windows/.gitignore b/windows/.gitignore
new file mode 100644
index 0000000..b3eb2be
--- /dev/null
+++ b/windows/.gitignore
@@ -0,0 +1,17 @@
+flutter/
+
+# Visual Studio user-specific files.
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# Visual Studio build-related files.
+x64/
+x86/
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!*.[Cc]ache/
diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt
new file mode 100644
index 0000000..8c84b3f
--- /dev/null
+++ b/windows/CMakeLists.txt
@@ -0,0 +1,105 @@
+# The Flutter tooling requires that developers have a version of Visual Studio
+# installed that includes CMake 3.14 or later. You should not increase this
+# version, as doing so will cause the plugin to fail to compile for some
+# customers of the plugin.
+cmake_minimum_required(VERSION 3.14)
+
+# Project-level configuration.
+set(PROJECT_NAME "flutter_openim_sdk")
+project(${PROJECT_NAME} LANGUAGES CXX)
+
+# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
+# versions of CMake.
+cmake_policy(VERSION 3.14...3.25)
+
+# This value is used when generating builds using this plugin, so it must
+# not be changed
+set(PLUGIN_NAME "flutter_openim_sdk_plugin")
+set(PCH_HEADER_FILE ${CMAKE_CURRENT_LIST_DIR}/src/common/stable.h)
+
+# third_party_libs
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third_party/alog/include")
+link_directories("${CMAKE_CURRENT_SOURCE_DIR}/third_party/alog/lib/x64/${CMAKE_BUILD_TYPE}")
+
+FILE(GLOB SELF_TEMP_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/*.cpp src/*.h)
+source_group(src FILES ${SELF_TEMP_SRC_FILES})
+list(APPEND NIM_CORE_SOURCES ${SELF_TEMP_SRC_FILES})
+
+FILE(GLOB SELF_TEMP_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/common/*.cpp src/common/*.h)
+source_group(src/common FILES ${SELF_TEMP_SRC_FILES})
+list(APPEND NIM_CORE_SOURCES ${SELF_TEMP_SRC_FILES})
+
+FILE(GLOB SELF_TEMP_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/common/services/*.cpp src/common/services/*.h)
+source_group(src/common/services FILES ${SELF_TEMP_SRC_FILES})
+list(APPEND NIM_CORE_SOURCES ${SELF_TEMP_SRC_FILES})
+
+FILE(GLOB SELF_TEMP_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/common/utils/*.cpp src/common/utils/*.h src/common/utils/*.hpp)
+source_group(src/common/utils FILES ${SELF_TEMP_SRC_FILES})
+list(APPEND NIM_CORE_SOURCES ${SELF_TEMP_SRC_FILES})
+
+FILE(GLOB SELF_TEMP_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/utils/*.cpp src/utils/*.h)
+source_group(src/utils FILES ${SELF_TEMP_SRC_FILES})
+list(APPEND NIM_CORE_SOURCES ${SELF_TEMP_SRC_FILES})
+
+FILE(GLOB SELF_TEMP_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/utils/dump/*.cpp src/utils/dump/*.h)
+source_group(src/utils/dump FILES ${SELF_TEMP_SRC_FILES})
+list(APPEND NIM_CORE_SOURCES ${SELF_TEMP_SRC_FILES})
+
+# Any new source files that you add to the plugin should be added here.
+list(APPEND PLUGIN_SOURCES
+ ${CMAKE_CURRENT_LIST_DIR}/flutter_openim_sdk_plugin.cpp
+)
+
+add_library(${PLUGIN_NAME} SHARED
+ ${PLUGIN_SOURCES}
+ ${NIM_CORE_SOURCES}
+)
+target_precompile_headers(${PLUGIN_NAME} PRIVATE ${PCH_HEADER_FILE})
+target_link_libraries(${PLUGIN_NAME} PRIVATE yx_alog)
+
+# Apply a standard set of build settings that are configured in the
+# application-level CMakeLists.txt. This can be removed for plugins that want
+# full control over build settings.
+apply_standard_settings(${PLUGIN_NAME})
+
+# Symbols are hidden by default to reduce the chance of accidental conflicts
+# between plugins. This should not be removed; any symbols that should be
+# exported should be explicitly exported with the FLUTTER_PLUGIN_EXPORT macro.
+set_target_properties(${PLUGIN_NAME} PROPERTIES
+ CXX_VISIBILITY_PRESET hidden)
+target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
+target_compile_options(${PLUGIN_NAME} PRIVATE /W4 /WX- /wd4100 /wd4267 /wd4189 /wd4244 /wd4996 /bigobj /utf-8)
+
+target_include_directories(${PLUGIN_NAME} PUBLIC
+ "${CMAKE_CURRENT_LIST_DIR}/include"
+ "${CMAKE_CURRENT_LIST_DIR}/"
+ "${CMAKE_CURRENT_LIST_DIR}/openlib/x64/include"
+)
+
+target_link_libraries(${PLUGIN_NAME} PRIVATE
+ flutter
+ flutter_wrapper_plugin
+ ${CMAKE_CURRENT_LIST_DIR}/openlib/x64/libopenimsdk.lib
+)
+
+
+
+file(GLOB flutter_openim_sdk_bundled_libraries
+ "${CMAKE_CURRENT_LIST_DIR}/openlib/x64/*.dll"
+)
+
+file(GLOB LIBRARY_FILES "${CMAKE_CURRENT_LIST_DIR}/openlib/x64/*")
+foreach(LIB_FILE ${LIBRARY_FILES})
+ if(LIB_FILE MATCHES "cacert\.pem")
+ # 添加库文件路径到变量
+ list(APPEND flutter_openim_sdk_bundled_libraries ${LIB_FILE})
+ endif()
+endforeach()
+
+set(flutter_openim_sdk_bundled_libraries ${flutter_openim_sdk_bundled_libraries} PARENT_SCOPE)
+
+
+
+#install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/openlib/libopenimsdk.dll
+# DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
+#)
diff --git a/windows/flutter_openim_sdk_plugin.cpp b/windows/flutter_openim_sdk_plugin.cpp
new file mode 100644
index 0000000..4794fb8
--- /dev/null
+++ b/windows/flutter_openim_sdk_plugin.cpp
@@ -0,0 +1,104 @@
+#include "include/flutter_openim_sdk/flutter_openim_sdk_plugin.h"
+
+// This must be included before many other Windows headers.
+#include
+
+// For getPlatformVersion; remove unless needed for your plugin implementation.
+#include
+
+#include
+#include
+#include
+
+#include
+#include
+#include "src/MethodCallHandlerImpl.h"
+#include "src/common/stable.h"
+
+
+class FlutterOpenimSdkPlugin : public flutter::Plugin {
+public:
+ static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
+
+ FlutterOpenimSdkPlugin();
+
+ virtual ~FlutterOpenimSdkPlugin();
+
+ // Disallow copy and assign.
+ FlutterOpenimSdkPlugin(const FlutterOpenimSdkPlugin &) = delete;
+
+ FlutterOpenimSdkPlugin &operator=(const FlutterOpenimSdkPlugin &) = delete;
+
+ // Called when a method is called on this plugin's channel from Dart.
+ void HandleMethodCall(
+ const flutter::MethodCall &method_call,
+ std::unique_ptr > result);
+
+public:
+ std::unique_ptr m_channel;
+};
+
+//std::string ws2s(const std::wstring& wstr) {
+// using convert_typeX = std::codecvt_utf8;
+// std::wstring_convert converterX;
+// return converterX.to_bytes(wstr);
+//}
+
+// static
+void FlutterOpenimSdkPlugin::RegisterWithRegistrar(
+ flutter::PluginRegistrarWindows *registrar) {
+
+ //std::string filePath = ws2s(_wgetenv(L"LOCALAPPDATA"));
+ std::string filePath = std::getenv("LOCALAPPDATA");
+ std::string filePathApp;
+ if (!filePath.empty()) {
+ filePath.append("/OpenIM/OpenimPlugin");
+ } else {
+ std::cout << "log filePath empty!" << std::endl;
+ }
+ filePathApp = filePath;
+ filePathApp.append("/app");
+ std::cout << "log filePath: " << filePathApp.c_str() << std::endl;
+ ALog::CreateInstance(filePathApp, "nim_core_plugin", Info);
+ ALog::GetInstance()->setShortFileName(true);
+ YXLOG(Info) << "===================start===================" << YXLOGEnd;
+ YXLOG_API(Info) << "RegisterWithRegistrar, logPath: " << filePathApp
+ << YXLOGEnd;
+ //InitDumpInfo("");
+
+ NimCore::getInstance()->setLogDir(filePath);
+
+ auto plugin = std::make_unique();
+ auto channel = plugin->m_channel->startListening(registrar);
+ channel->SetMethodCallHandler(
+ [plugin_pointer = plugin.get()](const auto &call, auto result) {
+ plugin_pointer->HandleMethodCall(call, std::move(result));
+ });
+
+
+ registrar->AddPlugin(std::move(plugin));
+}
+
+FlutterOpenimSdkPlugin::FlutterOpenimSdkPlugin() {
+ m_channel = std::make_unique();
+}
+
+FlutterOpenimSdkPlugin::~FlutterOpenimSdkPlugin() {
+ m_channel.reset(nullptr);
+}
+
+
+
+
+void FlutterOpenimSdkPlugin::HandleMethodCall(
+ const flutter::MethodCall &method_call,
+ std::unique_ptr > result) {
+ m_channel->onMethodCall(method_call, std::move(result));
+}
+
+
+void FlutterOpenimSdkPluginRegisterWithRegistrar(FlutterDesktopPluginRegistrarRef registrar) {
+ FlutterOpenimSdkPlugin::RegisterWithRegistrar(
+ flutter::PluginRegistrarManager::GetInstance()
+ ->GetRegistrar(registrar));
+}
diff --git a/windows/include/flutter_openim_sdk/flutter_openim_sdk_plugin.h b/windows/include/flutter_openim_sdk/flutter_openim_sdk_plugin.h
new file mode 100644
index 0000000..0c23292
--- /dev/null
+++ b/windows/include/flutter_openim_sdk/flutter_openim_sdk_plugin.h
@@ -0,0 +1,24 @@
+#ifndef FLUTTER_PLUGIN_FLUTTER_OPENIM_SDK_PLUGIN_H_
+#define FLUTTER_PLUGIN_FLUTTER_OPENIM_SDK_PLUGIN_H_
+
+#include
+#include
+
+#ifdef FLUTTER_PLUGIN_IMPL
+#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport)
+#else
+#define FLUTTER_PLUGIN_EXPORT __declspec(dllimport)
+#endif
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+FLUTTER_PLUGIN_EXPORT void FlutterOpenimSdkPluginRegisterWithRegistrar(
+ FlutterDesktopPluginRegistrarRef registrar);
+
+#if defined(__cplusplus)
+} // extern "C"
+#endif
+
+#endif // FLUTTER_PLUGIN_FLUTTER_OPENIM_SDK_PLUGIN_H_
diff --git a/windows/src/FLTConvert.cpp b/windows/src/FLTConvert.cpp
new file mode 100644
index 0000000..e71fdfd
--- /dev/null
+++ b/windows/src/FLTConvert.cpp
@@ -0,0 +1,46 @@
+// Copyright (c) 2022 NetEase, Inc. All rights reserved.
+// Use of this source code is governed by a MIT license that can be
+// found in the LICENSE file.
+
+#include "FLTConvert.h"
+
+Convert::Convert() {}
+
+std::string Convert::getStringFormMapForLog(
+ const flutter::EncodableMap* arguments) const {
+ if (!arguments) {
+ return "";
+ }
+
+ // todo
+ return "";
+}
+
+void Convert::getLogList(const std::string& strLog,
+ std::list& listLog) const {
+ listLog.clear();
+ int num = 15 * 1024; // 分割定长大小
+ int len = strLog.length(); // 字符串长度
+ int end = num;
+ for (int start = 0; start < len;) {
+ if (end > len) // 针对最后一个分割串
+ {
+ listLog.emplace_back(
+ strLog.substr(start, len - start)); // 最后一个字符串的原始部分
+ break;
+ }
+ listLog.emplace_back(
+ strLog.substr(start, num)); // 从0开始,分割num位字符串
+ start = end;
+ end = end + num;
+ }
+}
+
+std::string Convert::getStringFormListForLog(
+ const flutter::EncodableList* arguments) const {
+ if (!arguments) {
+ return "";
+ }
+
+ return "";
+}
diff --git a/windows/src/FLTConvert.h b/windows/src/FLTConvert.h
new file mode 100644
index 0000000..90c9764
--- /dev/null
+++ b/windows/src/FLTConvert.h
@@ -0,0 +1,29 @@
+// Copyright (c) 2022 NetEase, Inc. All rights reserved.
+// Use of this source code is governed by a MIT license that can be
+// found in the LICENSE file.
+
+#ifndef FLTCONVERT_H
+#define FLTCONVERT_H
+
+#include
+#include
+
+#include "common/FLTService.h"
+#include "common/utils/singleton.h"
+
+class Convert {
+ public:
+ SINGLETONG(Convert)
+
+ std::string getStringFormMapForLog(
+ const flutter::EncodableMap* arguments) const;
+ void getLogList(const std::string& strLog,
+ std::list& listLog) const;
+ std::string getStringFormListForLog(
+ const flutter::EncodableList* arguments) const;
+
+ private:
+ Convert();
+};
+
+#endif // FLTCONVERT_H
diff --git a/windows/src/MethodCallHandlerImpl.cpp b/windows/src/MethodCallHandlerImpl.cpp
new file mode 100644
index 0000000..988f004
--- /dev/null
+++ b/windows/src/MethodCallHandlerImpl.cpp
@@ -0,0 +1,45 @@
+// Copyright (c) 2022 NetEase, Inc. All rights reserved.
+// Use of this source code is governed by a MIT license that can be
+// found in the LICENSE file.
+
+#include "MethodCallHandlerImpl.h"
+
+#include
+#include
+#include
+
+#include
+
+#include "NimCore.h"
+
+MethodCallHandlerImpl::MethodCallHandlerImpl() {}
+
+void MethodCallHandlerImpl::onMethodCall(
+ const flutter::MethodCall &method_call,
+ std::shared_ptr > result) {
+ const auto *arguments =
+ std::get_if(method_call.arguments());
+ if (arguments) {
+ NimCore::getInstance()->onMethodCall(method_call.method_name(), arguments,
+ result);
+ } else {
+ if (result) {
+ result->NotImplemented();
+ }
+ }
+}
+
+flutter::MethodChannel *
+MethodCallHandlerImpl::startListening(flutter::PluginRegistrar *registrar) {
+ m_methodChannel =
+ std::make_unique < flutter::MethodChannel < flutter::EncodableValue >> (
+ registrar->messenger(), "flutter_openim_sdk",
+ &flutter::StandardMethodCodec::GetInstance());
+
+ NimCore::getInstance()->setMethodChannel(m_methodChannel.get());
+ return m_methodChannel.get();
+}
+
+void MethodCallHandlerImpl::stopListening() {
+ NimCore::getInstance()->setMethodChannel(nullptr);
+}
\ No newline at end of file
diff --git a/windows/src/MethodCallHandlerImpl.h b/windows/src/MethodCallHandlerImpl.h
new file mode 100644
index 0000000..115f163
--- /dev/null
+++ b/windows/src/MethodCallHandlerImpl.h
@@ -0,0 +1,34 @@
+// Copyright (c) 2022 NetEase, Inc. All rights reserved.
+// Use of this source code is governed by a MIT license that can be
+// found in the LICENSE file.
+
+#ifndef METHODCALLHANDLERIMPL_H
+#define METHODCALLHANDLERIMPL_H
+
+#include
+#include
+#include
+
+#include
+
+#include "NimCore.h"
+
+class MethodCallHandlerImpl {
+ public:
+ MethodCallHandlerImpl();
+
+ void onMethodCall(
+ const flutter::MethodCall& method_call,
+ std::shared_ptr> result);
+
+ flutter::MethodChannel* startListening(
+ flutter::PluginRegistrar* registrar);
+
+ void stopListening();
+
+ private:
+ std::unique_ptr>
+ m_methodChannel;
+};
+
+#endif // METHODCALLHANDLERIMPL_H
\ No newline at end of file
diff --git a/windows/src/NimCore.cpp b/windows/src/NimCore.cpp
new file mode 100644
index 0000000..ae4e4c2
--- /dev/null
+++ b/windows/src/NimCore.cpp
@@ -0,0 +1,252 @@
+// Copyright (c) 2022 NetEase, Inc. All rights reserved.
+// Use of this source code is governed by a MIT license that can be
+// found in the LICENSE file.
+
+#include "NimCore.h"
+
+#include
+#include
+#include
+#include
+
+#include "FLTConvert.h"
+
+#include "common/services/IMManager.h"
+
+
+const std::string kFLTNimCoreService = "serviceName";
+
+NimCore::NimCore() { regService(); }
+
+NimCore::~NimCore() {}
+
+void NimCore::regService() {
+ addService(new IMManagerService());
+
+}
+
+void NimCore::cleanService() {
+ // m_services.clear();
+
+}
+
+void NimCore::addService(FLTService* service) {
+ m_services[service->getServiceName()] = service;
+}
+
+// FLTMessageService* NimCore::getFLTMessageService() const {
+// return dynamic_cast(getService("MessageService"));
+// }
+
+FLTService* NimCore::getService(const std::string& serviceName) const {
+ auto service = m_services.find(serviceName);
+ if (m_services.end() == service) {
+ return nullptr;
+ }
+
+ return service->second;
+}
+
+void NimCore::onMethodCall(
+ const std::string& method, const flutter::EncodableMap* arguments,
+ std::shared_ptr> result) {
+ if (nullptr == arguments) {
+ if (result) {
+ result->NotImplemented();
+ }
+ return;
+ }
+
+ auto serviceName_iter =
+ arguments->find(flutter::EncodableValue("ManagerName"));
+ if (serviceName_iter != arguments->end() &&
+ !serviceName_iter->second.IsNull()) {
+ std::string serviceName = std::get(serviceName_iter->second);
+ auto* service = getService(serviceName);
+ if (service) {
+ std::shared_ptr mockResult =
+ std::make_shared(serviceName, method, result);
+ YXLOG_API(Info) << "mn: " << method << ", args: "
+ << Convert::getInstance()->getStringFormMapForLog(
+ arguments)
+ << YXLOGEnd;
+ service->onMethodCalled(method, arguments, mockResult);
+ return;
+ }
+ } else {
+ YXLOG_API(Warn) << "sn not found, mn: " << method << YXLOGEnd;
+ }
+
+ if (result) {
+ result->NotImplemented();
+ }
+}
+
+void NimCore::invokeMethod(const std::string& method,
+ const flutter::EncodableMap& arguments) {
+ if (m_channel) {
+ m_channel->InvokeMethod(
+ method, std::make_unique(arguments));
+ }
+}
+
+template
+class InterResult : public flutter::MethodResult {
+ protected:
+ void SuccessInternal(const T* result) override {
+ if (result != nullptr) {
+ NimCore::getInstance()->invokeCallback(flutter::EncodableValue(*result));
+ } else {
+ NimCore::getInstance()->invokeCallback(std::nullopt);
+ }
+ }
+
+ // Implementation of the public interface, to be provided by subclasses.
+ void ErrorInternal(const std::string& error_code,
+ const std::string& error_message,
+ const T* error_details) override {}
+
+ // Implementation of the public interface, to be provided by subclasses.
+ void NotImplementedInternal() override {}
+};
+
+void NimCore::invokeMethod(const std::string& eventName,
+ const flutter::EncodableMap& arguments,
+ const InvokeMehtodCallback& callback) {
+ invokeCallback = callback;
+ if (m_channel) {
+ m_channel->InvokeMethod(
+ eventName, std::make_unique(arguments),
+ std::make_unique>());
+ }
+}
+
+void NimCore::setMethodChannel(NimMethodChannel* channel) {
+ m_channel = channel;
+}
+
+NimCore::NimMethodChannel* NimCore::getMethodChannel() { return m_channel; }
+
+void NimCore::setAppkey(const std::string& appkey) { m_appKey = appkey; }
+
+std::string NimCore::getAppkey() const { return m_appKey; }
+
+void NimCore::setLogDir(const std::string& logDir) { m_logDir = logDir; }
+
+std::string NimCore::getLogDir() const { return m_logDir; }
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+MockMethodResult::MockMethodResult(
+ const std::string serviceName, const std::string methodName,
+ std::shared_ptr> result)
+ : m_serviceName(serviceName),
+ m_methodName(methodName),
+ m_result(std::move(result)) {}
+
+void MockMethodResult::ErrorInternal(const std::string& error_code,
+ const std::string& error_message,
+ const flutter::EncodableValue* details) {
+ YXLOG_API(Warn) << "cb error, sn: " << m_serviceName
+ << ", mn: " << m_methodName << ", error_code: " << error_code
+ << ", error_msg: " << error_message
+ << ", details: " << getStringFormEncodableValue(details)
+ << YXLOGEnd;
+ if (m_result) m_result->Success(*details);
+ // //失败情况下, 也调用success接口,避免dart层抛出异常
+ // m_result->Error(error_code, error_message, *details);
+}
+
+void MockMethodResult::NotImplementedInternal() {
+ YXLOG_API(Warn) << "cb notImplemented, sn: " << m_serviceName
+ << ", mn: " << m_methodName << YXLOGEnd;
+ if (m_result) m_result->NotImplemented();
+}
+
+void MockMethodResult::SuccessInternal(const flutter::EncodableValue* result) {
+ std::string strLog;
+ strLog.append("cb succ, sn: ")
+ .append(m_serviceName)
+ .append(", mn: ")
+ .append(m_methodName)
+ .append(", result: ")
+ .append(getStringFormEncodableValue(result));
+ std::list logList;
+ Convert::getInstance()->getLogList(strLog, logList);
+ for (auto& it : logList) {
+ YXLOG_API(Info) << it << YXLOGEnd;
+ }
+
+ if (m_result) m_result->Success(*result);
+}
+
+std::string MockMethodResult::getStringFormEncodableValue(
+ const flutter::EncodableValue* value) const {
+ if (!value) {
+ return "";
+ }
+
+ std::string result;
+ if (auto it = std::get_if(value); it) {
+ result = *it ? "true" : "false";
+ } else if (auto it1 = std::get_if(value); it1) {
+ result = std::to_string(*it1);
+ } else if (auto it2 = std::get_if(value); it2) {
+ result = std::to_string(*it2);
+ } else if (auto it3 = std::get_if(value); it3) {
+ result = std::to_string(*it3);
+ } else if (auto it4 = std::get_if(value); it4) {
+ result = *it4;
+ } else if (auto it5 = std::get_if>(value); it5) {
+ result.append("[");
+ bool bFirst = true;
+ for (auto& it5Tmp : *it5) {
+ if (!bFirst) {
+ result.append(",");
+ }
+ result.append(std::to_string(it5Tmp));
+ bFirst = false;
+ }
+ result.append("]");
+ } else if (auto it6 = std::get_if>(value); it6) {
+ result.append("[");
+ bool bFirst = true;
+ for (auto& it6Tmp : *it6) {
+ if (!bFirst) {
+ result.append(",");
+ }
+ result.append(std::to_string(it6Tmp));
+ bFirst = false;
+ }
+ result.append("]");
+ } else if (auto it7 = std::get_if>(value); it7) {
+ result.append("[");
+ bool bFirst = true;
+ for (auto& it7Tmp : *it7) {
+ if (!bFirst) {
+ result.append(",");
+ }
+ result.append(std::to_string(it7Tmp));
+ bFirst = false;
+ }
+ result.append("]");
+ } else if (auto it8 = std::get_if>(value); it8) {
+ result.append("[");
+ bool bFirst = true;
+ for (auto& it8Tmp : *it8) {
+ if (!bFirst) {
+ result.append(",");
+ }
+ result.append(std::to_string(it8Tmp));
+ bFirst = false;
+ }
+ result.append("]");
+ } else if (auto it9 = std::get_if(value); it9) {
+ result = Convert::getInstance()->getStringFormListForLog(it9);
+ } else if (auto it10 = std::get_if(value); it10) {
+ result = Convert::getInstance()->getStringFormMapForLog(it10);
+ } else {
+ // wjzh
+ }
+
+ return result;
+}
\ No newline at end of file
diff --git a/windows/src/NimCore.h b/windows/src/NimCore.h
new file mode 100644
index 0000000..7660e3a
--- /dev/null
+++ b/windows/src/NimCore.h
@@ -0,0 +1,105 @@
+// Copyright (c) 2022 NetEase, Inc. All rights reserved.
+// Use of this source code is governed by a MIT license that can be
+// found in the LICENSE file.
+
+#ifndef NIMCORE_H
+#define NIMCORE_H
+
+#include
+#include
+#include
+#include
+
+class FLTService;
+
+class FLTAuthService;
+
+class FLTMessageService;
+
+class NimCore {
+public:
+ using NimMethodChannel = flutter::MethodChannel;
+
+public:
+ SINGLETONG(NimCore)
+
+private:
+ NimCore();
+
+ ~NimCore();
+
+public:
+ using InvokeMehtodCallback =
+ std::function &)>;
+
+ InvokeMehtodCallback invokeCallback;
+
+ void regService();
+
+ void cleanService();
+
+ void addService(FLTService *service);
+
+ // FLTAuthService* getFLTAuthService() const;
+ // FLTMessageService* getFLTMessageService() const;
+ FLTService *getService(const std::string &serviceName) const;
+
+ void onMethodCall(
+ const std::string &method, const flutter::EncodableMap *arguments,
+ std::shared_ptr > result);
+
+ void invokeMethod(const std::string &method,
+ const flutter::EncodableMap &arguments);
+
+ void invokeMethod(const std::string &eventName,
+ const flutter::EncodableMap &arguments,
+ const InvokeMehtodCallback &callback);
+
+ void setMethodChannel(NimMethodChannel *channel);
+
+ NimMethodChannel *getMethodChannel();
+
+public:
+ void setAppkey(const std::string &appkey);
+
+ std::string getAppkey() const;
+
+ void setLogDir(const std::string &logDir);
+
+ std::string getLogDir() const;
+
+ std::string getAccountId() const;
+
+private:
+ std::unordered_map m_services;
+ NimMethodChannel *m_channel = nullptr;
+ std::string m_appKey = "";
+ std::string m_logDir;
+};
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+class MockMethodResult : public flutter::MethodResult<> {
+public:
+ MockMethodResult(
+ const std::string serviceName, const std::string methodName,
+ std::shared_ptr > result);
+
+ virtual void ErrorInternal(const std::string &error_code,
+ const std::string &error_message,
+ const flutter::EncodableValue *details) override;
+
+ virtual void NotImplementedInternal() override;
+
+ virtual void SuccessInternal(const flutter::EncodableValue *result) override;
+
+private:
+ std::string getStringFormEncodableValue(
+ const flutter::EncodableValue *value) const;
+
+private:
+ std::string m_serviceName;
+ std::string m_methodName;
+ std::shared_ptr > m_result;
+};
+
+#endif // NIMCORE
diff --git a/windows/src/common/FLTService.cpp b/windows/src/common/FLTService.cpp
new file mode 100644
index 0000000..1f1ca4e
--- /dev/null
+++ b/windows/src/common/FLTService.cpp
@@ -0,0 +1,65 @@
+// Copyright (c) 2022 NetEase, Inc. All rights reserved.
+// Use of this source code is governed by a MIT license that can be
+// found in the LICENSE file.
+
+#include "FLTService.h"
+
+#include "../FLTConvert.h"
+
+std::string FLTService::getServiceName() const { return m_serviceName; }
+
+void notifyEvent(const std::string& eventName,
+ flutter::EncodableMap& arguments) {
+ arguments.insert(std::make_pair(flutter::EncodableValue("serviceName"),
+ flutter::EncodableValue("")));
+ std::string strLog;
+ strLog.append("en: ")
+ .append(eventName)
+ .append(", args: ")
+ .append(Convert::getInstance()->getStringFormMapForLog(&arguments));
+ std::list logList;
+ Convert::getInstance()->getLogList(strLog, logList);
+ for (auto& it : logList) {
+ YXLOG_API(Info) << it << YXLOGEnd;
+ }
+ NimCore::getInstance()->invokeMethod(eventName, arguments);
+ YXLOG_API(Info) << "notifyEvent invoke completation." << YXLOGEnd;
+}
+
+//void FLTService::notifyEvent(const std::string& eventName,
+// flutter::EncodableMap& arguments,
+// const NimCore::InvokeMehtodCallback& callback) {
+// arguments.insert(std::make_pair(flutter::EncodableValue("serviceName"),
+// flutter::EncodableValue(m_serviceName)));
+// std::string strLog;
+// strLog.append("en: ")
+// .append(eventName)
+// .append(", args: ")
+// .append(Convert::getInstance()->getStringFormMapForLog(&arguments));
+// std::list logList;
+// Convert::getInstance()->getLogList(strLog, logList);
+// for (auto& it : logList) {
+// YXLOG_API(Info) << it << YXLOGEnd;
+// }
+// NimCore::getInstance()->invokeMethod(eventName, arguments, callback);
+// YXLOG_API(Info) << "notifyEvent invoke completation." << YXLOGEnd;
+//}
+
+void FLTService::notifyEventEx(const std::string& serviceName,
+ const std::string& eventName,
+ flutter::EncodableMap& arguments) {
+ arguments.insert(std::make_pair(flutter::EncodableValue("serviceName"),
+ flutter::EncodableValue(serviceName)));
+ std::string strLog;
+ strLog.append("en: ")
+ .append(eventName)
+ .append(", args: ")
+ .append(Convert::getInstance()->getStringFormMapForLog(&arguments));
+ std::list logList;
+ Convert::getInstance()->getLogList(strLog, logList);
+ for (auto& it : logList) {
+ YXLOG_API(Info) << it << YXLOGEnd;
+ }
+ NimCore::getInstance()->invokeMethod(eventName, arguments);
+ YXLOG_API(Info) << "notifyEventEx invoke completation." << YXLOGEnd;
+}
diff --git a/windows/src/common/FLTService.h b/windows/src/common/FLTService.h
new file mode 100644
index 0000000..8099977
--- /dev/null
+++ b/windows/src/common/FLTService.h
@@ -0,0 +1,46 @@
+// Copyright (c) 2022 NetEase, Inc. All rights reserved.
+// Use of this source code is governed by a MIT license that can be
+// found in the LICENSE file.
+
+#ifndef FLTSERVICE_H
+#define FLTSERVICE_H
+
+#include "../NimCore.h"
+#include "NimResult.h"
+#include "flutter/method_result.h"
+
+#define DECLARE_FUN(fun) \
+ void fun(const flutter::EncodableMap* arguments, \
+ FLTService::MethodResult result);
+
+void notifyEvent(const std::string& eventName,
+ flutter::EncodableMap& arguments);
+
+class FLTService {
+ public:
+ using MethodResult =
+ std::shared_ptr>;
+
+ public:
+ virtual void onMethodCalled(
+ const std::string& method, const flutter::EncodableMap* arguments,
+ std::shared_ptr>
+ result) = 0;
+
+ std::string getServiceName() const;
+
+
+
+ //void notifyEvent(const std::string& eventName,
+ // flutter::EncodableMap& arguments,
+ // const NimCore::InvokeMehtodCallback& callback);
+
+ static void notifyEventEx(const std::string& serviceName,
+ const std::string& eventName,
+ flutter::EncodableMap& arguments);
+
+ protected:
+ std::string m_serviceName;
+};
+
+#endif // FLTSERVICE_H
diff --git a/windows/src/common/NimResult.cpp b/windows/src/common/NimResult.cpp
new file mode 100644
index 0000000..5360d2b
--- /dev/null
+++ b/windows/src/common/NimResult.cpp
@@ -0,0 +1,88 @@
+// Copyright (c) 2022 NetEase, Inc. All rights reserved.
+// Use of this source code is governed by a MIT license that can be
+// found in the LICENSE file.
+
+#include "NimResult.h"
+
+using namespace flutter;
+
+EncodableValue NimResult::getErrorResult(int code, const std::string& msg) {
+ EncodableMap result;
+ result.insert(std::make_pair(EncodableValue("code"), EncodableValue(code)));
+ result.insert(
+ std::make_pair(EncodableValue("errorDetails"), EncodableValue(msg)));
+ result.insert(std::make_pair(EncodableValue("data"), EncodableValue()));
+ return EncodableValue(result);
+}
+
+EncodableValue NimResult::getErrorResult(int code, const std::string& msg,
+ const EncodableMap& data) {
+ EncodableMap result;
+ result.insert(std::make_pair(EncodableValue("code"), EncodableValue(code)));
+ result.insert(
+ std::make_pair(EncodableValue("errorDetails"), EncodableValue(msg)));
+ result.insert(std::make_pair(EncodableValue("data"), EncodableValue(data)));
+ return EncodableValue(result);
+}
+
+EncodableValue NimResult::getSuccessResult() {
+ EncodableMap result;
+ result.insert(std::make_pair(EncodableValue("code"), EncodableValue(0)));
+ result.insert(
+ std::make_pair(EncodableValue("errorDetails"), EncodableValue("")));
+ result.insert(std::make_pair(EncodableValue("data"), EncodableValue()));
+ return EncodableValue(result);
+}
+
+EncodableValue NimResult::getSuccessResult(bool data) {
+ return getSuccessResult(EncodableValue(data));
+}
+
+EncodableValue NimResult::getSuccessResult(int32_t data) {
+ return getSuccessResult(EncodableValue(data));
+}
+
+EncodableValue NimResult::getSuccessResult(int64_t data) {
+ return getSuccessResult(EncodableValue(data));
+}
+
+EncodableValue NimResult::getSuccessResult(const std::string& data) {
+ return getSuccessResult(EncodableValue(data));
+}
+
+EncodableValue NimResult::getSuccessResult(const EncodableValue& data) {
+ EncodableMap result;
+ result.insert(std::make_pair(EncodableValue("code"), EncodableValue(0)));
+ result.insert(
+ std::make_pair(EncodableValue("errorDetails"), EncodableValue("")));
+ result.insert(std::make_pair(EncodableValue("data"), data));
+ return EncodableValue(result);
+}
+
+EncodableValue NimResult::getSuccessResult(const EncodableMap& data) {
+ EncodableMap result;
+ result.insert(std::make_pair(EncodableValue("code"), EncodableValue(0)));
+ result.insert(
+ std::make_pair(EncodableValue("errorDetails"), EncodableValue("")));
+ result.insert(std::make_pair(EncodableValue("data"), data));
+ return EncodableValue(result);
+}
+
+EncodableValue NimResult::getSuccessResult(const EncodableList& data) {
+ EncodableMap result;
+ result.insert(std::make_pair(EncodableValue("code"), EncodableValue(0)));
+ result.insert(
+ std::make_pair(EncodableValue("errorDetails"), EncodableValue("")));
+ result.insert(std::make_pair(EncodableValue("data"), data));
+ return EncodableValue(result);
+}
+
+EncodableValue NimResult::getSuccessResult(const std::string& msg,
+ const EncodableMap& data) {
+ EncodableMap result;
+ result.insert(std::make_pair(EncodableValue("code"), EncodableValue(0)));
+ result.insert(
+ std::make_pair(EncodableValue("errorDetails"), EncodableValue(msg)));
+ result.insert(std::make_pair(EncodableValue("data"), EncodableValue(data)));
+ return EncodableValue(result);
+}
diff --git a/windows/src/common/NimResult.h b/windows/src/common/NimResult.h
new file mode 100644
index 0000000..99e65b2
--- /dev/null
+++ b/windows/src/common/NimResult.h
@@ -0,0 +1,34 @@
+// Copyright (c) 2022 NetEase, Inc. All rights reserved.
+// Use of this source code is governed by a MIT license that can be
+// found in the LICENSE file.
+
+#ifndef NIMRESULT_H
+#define NIMRESULT_H
+
+#include "flutter/encodable_value.h"
+
+using namespace flutter;
+
+class NimResult {
+ public:
+ static EncodableValue getErrorResult(int code, const std::string& msg);
+ static EncodableValue getErrorResult(int code, const std::string& msg,
+ const flutter::EncodableMap& data);
+
+ static EncodableValue getSuccessResult();
+ static EncodableValue getSuccessResult(bool data);
+ static EncodableValue getSuccessResult(int32_t data);
+ static EncodableValue getSuccessResult(int64_t data);
+ static EncodableValue getSuccessResult(const std::string& data);
+ static EncodableValue getSuccessResult(const flutter::EncodableValue& data);
+ static EncodableValue getSuccessResult(const flutter::EncodableMap& data);
+ static EncodableValue getSuccessResult(const flutter::EncodableList& data);
+ static EncodableValue getSuccessResult(const std::string& msg,
+ const flutter::EncodableMap& data);
+};
+
+
+
+
+
+#endif // NIMRESULT_H
diff --git a/windows/src/common/ZegoDataUtils.cpp b/windows/src/common/ZegoDataUtils.cpp
new file mode 100644
index 0000000..51bfd96
--- /dev/null
+++ b/windows/src/common/ZegoDataUtils.cpp
@@ -0,0 +1,71 @@
+#include "ZegoDataUtils.h"
+
+bool zego_value_is_null(flutter::EncodableValue value) { return value.IsNull(); }
+
+int32_t zego_value_get_int(flutter::EncodableValue value) {
+ // dart 没有 int32_t int64_t 区分,这里处理了 int32 最高位为 1(负数)的 case
+ return (int32_t)zego_value_get_long(value);
+}
+
+int64_t zego_value_get_long(flutter::EncodableValue value) { return value.LongValue(); }
+
+bool zego_value_get_bool(flutter::EncodableValue value) { return std::get(value); }
+
+double zego_value_get_double(flutter::EncodableValue value) { return std::get(value); }
+
+std::string zego_value_get_string(flutter::EncodableValue value) {
+ return std::get(value);
+}
+
+std::vector zego_value_get_vector_float(flutter::EncodableValue value) {
+ return std::get>(value);
+}
+
+std::vector zego_value_get_vector_uint8(flutter::EncodableValue value) {
+ return std::get>(value);
+}
+
+ZFMap zego_value_get_map(flutter::EncodableValue value) { return std::get(value); }
+
+ZFArray zego_value_get_list(flutter::EncodableValue value) { return std::get(value); }
+
+
+// 将 EncodableValue 转换为 nlohmann::json
+nlohmann::json EncodableValueToJson(const flutter::EncodableValue& value) {
+ if (std::holds_alternative(value)) {
+ return std::get(value);
+ } else if (std::holds_alternative(value)) {
+ return std::get(value);
+ } else if (std::holds_alternative(value)) {
+ return std::get(value);
+ } else if (std::holds_alternative(value)) {
+ return std::get(value);
+ } else if (std::holds_alternative(value)) {
+ return std::get(value);
+ } else if (std::holds_alternative(value)) {
+ nlohmann::json json_array = nlohmann::json::array();
+ for (const auto& item : std::get(value)) {
+ json_array.push_back(EncodableValueToJson(item));
+ }
+ return json_array;
+ } else if (std::holds_alternative(value)) {
+ nlohmann::json json_object = nlohmann::json::object();
+ for (const auto& pair : std::get(value)) {
+ std::string key = std::get(pair.first); // 假设键是字符串
+ json_object[key] = EncodableValueToJson(pair.second);
+ }
+ return json_object;
+ }
+ return nullptr; // 处理空值或不支持的类型
+}
+
+// 将 EncodableMap 转换为 JSON 字符串
+std::string map_2_json(const flutter::EncodableMap& map) {
+ nlohmann::json json_object = nlohmann::json::object();
+ for (const auto& pair : map) {
+ std::string key = std::get(pair.first); // 假设键是字符串
+ json_object[key] = EncodableValueToJson(pair.second);
+ }
+ auto json_string = json_object.dump(); // 序列化为 JSON 字符串
+ return json_string; // 序列化为 JSON 字符串
+}
diff --git a/windows/src/common/ZegoDataUtils.h b/windows/src/common/ZegoDataUtils.h
new file mode 100644
index 0000000..c05a29a
--- /dev/null
+++ b/windows/src/common/ZegoDataUtils.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include
+#include
+#include
+#include "json.hpp"
+
+#define ZFValue(varName) flutter::EncodableValue(varName)
+#define ZFMap flutter::EncodableMap
+#define ZFArray flutter::EncodableList
+
+#define ZFArgument flutter::EncodableMap &
+#define ZFResult std::unique_ptr>
+#define ZFEventSink std::unique_ptr>
+#define ZFMoveResult(result) std::shared_ptr>(std::move(result))
+
+#define ZFPluginRegistrar flutter::PluginRegistrarWindows
+#define ZFBinaryMessenger flutter::BinaryMessenger
+#define ZFTextureRegistrar flutter::TextureRegistrar
+
+bool zego_value_is_null(flutter::EncodableValue value);
+
+int32_t zego_value_get_int(flutter::EncodableValue value);
+int64_t zego_value_get_long(flutter::EncodableValue value);
+bool zego_value_get_bool(flutter::EncodableValue value);
+double zego_value_get_double(flutter::EncodableValue value);
+std::string zego_value_get_string(flutter::EncodableValue value);
+
+std::vector zego_value_get_vector_float(flutter::EncodableValue value);
+std::vector zego_value_get_vector_uint8(flutter::EncodableValue value);
+ZFMap zego_value_get_map(flutter::EncodableValue value);
+ZFArray zego_value_get_list(flutter::EncodableValue value);
+std::string map_2_json(const flutter::EncodableMap& map);
+
+
+
diff --git a/windows/src/common/json.hpp b/windows/src/common/json.hpp
new file mode 100644
index 0000000..82d69f7
--- /dev/null
+++ b/windows/src/common/json.hpp
@@ -0,0 +1,25526 @@
+// __ _____ _____ _____
+// __| | __| | | | JSON for Modern C++
+// | | |__ | | | | | | version 3.12.0
+// |_____|_____|_____|_|___| https://github.com/nlohmann/json
+//
+// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann
+// SPDX-License-Identifier: MIT
+
+/****************************************************************************\
+ * Note on documentation: The source files contain links to the online *
+ * documentation of the public API at https://json.nlohmann.me. This URL *
+ * contains the most recent documentation and should also be applicable to *
+ * previous versions; documentation for deprecated functions is not *
+ * removed, but marked deprecated. See "Generate documentation" section in *
+ * file docs/README.md. *
+\****************************************************************************/
+
+#ifndef INCLUDE_NLOHMANN_JSON_HPP_
+#define INCLUDE_NLOHMANN_JSON_HPP_
+
+#include // all_of, find, for_each
+#include // nullptr_t, ptrdiff_t, size_t
+#include // hash, less
+#include // initializer_list
+#ifndef JSON_NO_IO
+ #include // istream, ostream
+#endif // JSON_NO_IO
+#include // random_access_iterator_tag
+#include // unique_ptr
+#include // string, stoi, to_string
+#include // declval, forward, move, pair, swap
+#include // vector
+
+// #include
+// __ _____ _____ _____
+// __| | __| | | | JSON for Modern C++
+// | | |__ | | | | | | version 3.12.0
+// |_____|_____|_____|_|___| https://github.com/nlohmann/json
+//
+// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann
+// SPDX-License-Identifier: MIT
+
+
+
+#include
+
+// #include
+// __ _____ _____ _____
+// __| | __| | | | JSON for Modern C++
+// | | |__ | | | | | | version 3.12.0
+// |_____|_____|_____|_|___| https://github.com/nlohmann/json
+//
+// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann
+// SPDX-License-Identifier: MIT
+
+
+
+// This file contains all macro definitions affecting or depending on the ABI
+
+#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
+ #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH)
+ #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0
+ #warning "Already included a different version of the library!"
+ #endif
+ #endif
+#endif
+
+#define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum)
+#define NLOHMANN_JSON_VERSION_MINOR 12 // NOLINT(modernize-macro-to-enum)
+#define NLOHMANN_JSON_VERSION_PATCH 0 // NOLINT(modernize-macro-to-enum)
+
+#ifndef JSON_DIAGNOSTICS
+ #define JSON_DIAGNOSTICS 0
+#endif
+
+#ifndef JSON_DIAGNOSTIC_POSITIONS
+ #define JSON_DIAGNOSTIC_POSITIONS 0
+#endif
+
+#ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
+ #define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0
+#endif
+
+#if JSON_DIAGNOSTICS
+ #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag
+#else
+ #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS
+#endif
+
+#if JSON_DIAGNOSTIC_POSITIONS
+ #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS _dp
+#else
+ #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS
+#endif
+
+#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
+ #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp
+#else
+ #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON
+#endif
+
+#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION
+ #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0
+#endif
+
+// Construct the namespace ABI tags component
+#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b, c) json_abi ## a ## b ## c
+#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b, c) \
+ NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b, c)
+
+#define NLOHMANN_JSON_ABI_TAGS \
+ NLOHMANN_JSON_ABI_TAGS_CONCAT( \
+ NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \
+ NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON, \
+ NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS)
+
+// Construct the namespace version component
+#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \
+ _v ## major ## _ ## minor ## _ ## patch
+#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \
+ NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch)
+
+#if NLOHMANN_JSON_NAMESPACE_NO_VERSION
+#define NLOHMANN_JSON_NAMESPACE_VERSION
+#else
+#define NLOHMANN_JSON_NAMESPACE_VERSION \
+ NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \
+ NLOHMANN_JSON_VERSION_MINOR, \
+ NLOHMANN_JSON_VERSION_PATCH)
+#endif
+
+// Combine namespace components
+#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b
+#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \
+ NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b)
+
+#ifndef NLOHMANN_JSON_NAMESPACE
+#define NLOHMANN_JSON_NAMESPACE \
+ nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \
+ NLOHMANN_JSON_ABI_TAGS, \
+ NLOHMANN_JSON_NAMESPACE_VERSION)
+#endif
+
+#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN
+#define NLOHMANN_JSON_NAMESPACE_BEGIN \
+ namespace nlohmann \
+ { \
+ inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \
+ NLOHMANN_JSON_ABI_TAGS, \
+ NLOHMANN_JSON_NAMESPACE_VERSION) \
+ {
+#endif
+
+#ifndef NLOHMANN_JSON_NAMESPACE_END
+#define NLOHMANN_JSON_NAMESPACE_END \
+ } /* namespace (inline namespace) NOLINT(readability/namespace) */ \
+ } // namespace nlohmann
+#endif
+
+// #include
+// __ _____ _____ _____
+// __| | __| | | | JSON for Modern C++
+// | | |__ | | | | | | version 3.12.0
+// |_____|_____|_____|_|___| https://github.com/nlohmann/json
+//
+// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann
+// SPDX-License-Identifier: MIT
+
+
+
+#include // transform
+#include // array
+#include // forward_list
+#include // inserter, front_inserter, end
+#include