You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
3.7 KiB
110 lines
3.7 KiB
#include "include/flutter_openim_sdk/flutter_openim_sdk_plugin.h"
|
|
|
|
// This must be included before many other Windows headers.
|
|
#include <windows.h>
|
|
|
|
// For getPlatformVersion; remove unless needed for your plugin implementation.
|
|
#include <VersionHelpers.h>
|
|
|
|
#include <flutter/method_channel.h>
|
|
#include <flutter/plugin_registrar_windows.h>
|
|
#include <flutter/standard_method_codec.h>
|
|
|
|
#include <memory>
|
|
#include <sstream>
|
|
#include "src/MethodCallHandlerImpl.h"
|
|
#include "src/common/stable.h"
|
|
#include "src/common/ThreadUtil.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 <flutter::EncodableValue> &method_call,
|
|
std::unique_ptr <flutter::MethodResult<flutter::EncodableValue>> result);
|
|
|
|
public:
|
|
std::unique_ptr<MethodCallHandlerImpl> m_channel;
|
|
};
|
|
|
|
//std::string ws2s(const std::wstring& wstr) {
|
|
// using convert_typeX = std::codecvt_utf8<wchar_t>;
|
|
// std::wstring_convert<convert_typeX, wchar_t> 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);
|
|
|
|
// Initialize ThreadUtil to capture the platform thread ID
|
|
// This is called on the platform thread already, so it will initialize correctly
|
|
ThreadUtil::InitializePlatformThreadId();
|
|
YXLOG_API(Info) << "ThreadUtil initialized on platform thread" << YXLOGEnd;
|
|
|
|
auto plugin = std::make_unique<FlutterOpenimSdkPlugin>();
|
|
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<MethodCallHandlerImpl>();
|
|
}
|
|
|
|
FlutterOpenimSdkPlugin::~FlutterOpenimSdkPlugin() {
|
|
m_channel.reset(nullptr);
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlutterOpenimSdkPlugin::HandleMethodCall(
|
|
const flutter::MethodCall <flutter::EncodableValue> &method_call,
|
|
std::unique_ptr <flutter::MethodResult<flutter::EncodableValue>> result) {
|
|
m_channel->onMethodCall(method_call, std::move(result));
|
|
}
|
|
|
|
|
|
void FlutterOpenimSdkPluginRegisterWithRegistrar(FlutterDesktopPluginRegistrarRef registrar) {
|
|
FlutterOpenimSdkPlugin::RegisterWithRegistrar(
|
|
flutter::PluginRegistrarManager::GetInstance()
|
|
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
|
|
}
|
|
|