#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)); }