Restructure Windows plugin template (#93511)
This commit is contained in:
@@ -12,12 +12,18 @@ project(${PROJECT_NAME} LANGUAGES CXX)
|
||||
# not be changed
|
||||
set(PLUGIN_NAME "{{projectName}}_plugin")
|
||||
|
||||
# Any new source files that you add to the plugin should be added here.
|
||||
list(APPEND PLUGIN_SOURCES
|
||||
"{{pluginClassSnakeCase}}.cpp"
|
||||
"{{pluginClassSnakeCase}}.h"
|
||||
)
|
||||
|
||||
# Define the plugin library target. Its name must not be changed (see comment
|
||||
# on PLUGIN_NAME above).
|
||||
#
|
||||
# Any new source files that you add to the plugin should be added here.
|
||||
add_library(${PLUGIN_NAME} SHARED
|
||||
"{{pluginClassSnakeCase}}.cpp"
|
||||
"include/{{projectName}}/{{pluginClassSnakeCase}}_c_api.h"
|
||||
"{{pluginClassSnakeCase}}_c_api.cpp"
|
||||
${PLUGIN_SOURCES}
|
||||
)
|
||||
|
||||
# Apply a standard set of build settings that are configured in the
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_H_
|
||||
#define FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_H_
|
||||
#ifndef FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_C_API_H_
|
||||
#define FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_C_API_H_
|
||||
|
||||
#include <flutter_plugin_registrar.h>
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void {{pluginClass}}RegisterWithRegistrar(
|
||||
FLUTTER_PLUGIN_EXPORT void {{pluginClass}}CApiRegisterWithRegistrar(
|
||||
FlutterDesktopPluginRegistrarRef registrar);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_H_
|
||||
#endif // FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_C_API_H_
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "include/{{projectName}}/{{pluginClassSnakeCase}}.h"
|
||||
#include "{{pluginClassSnakeCase}}.h"
|
||||
|
||||
// This must be included before many other Windows headers.
|
||||
#include <windows.h>
|
||||
@@ -10,26 +10,10 @@
|
||||
#include <flutter/plugin_registrar_windows.h>
|
||||
#include <flutter/standard_method_codec.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
|
||||
class {{pluginClass}} : public flutter::Plugin {
|
||||
public:
|
||||
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
|
||||
|
||||
{{pluginClass}}();
|
||||
|
||||
virtual ~{{pluginClass}}();
|
||||
|
||||
private:
|
||||
// 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);
|
||||
};
|
||||
namespace {{projectName}} {
|
||||
|
||||
// static
|
||||
void {{pluginClass}}::RegisterWithRegistrar(
|
||||
@@ -72,11 +56,4 @@ void {{pluginClass}}::HandleMethodCall(
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void {{pluginClass}}RegisterWithRegistrar(
|
||||
FlutterDesktopPluginRegistrarRef registrar) {
|
||||
{{pluginClass}}::RegisterWithRegistrar(
|
||||
flutter::PluginRegistrarManager::GetInstance()
|
||||
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
|
||||
}
|
||||
} // namespace {{projectName}}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_H_
|
||||
#define FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_H_
|
||||
|
||||
#include <flutter/method_channel.h>
|
||||
#include <flutter/plugin_registrar_windows.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace {{projectName}} {
|
||||
|
||||
class {{pluginClass}} : public flutter::Plugin {
|
||||
public:
|
||||
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
|
||||
|
||||
{{pluginClass}}();
|
||||
|
||||
virtual ~{{pluginClass}}();
|
||||
|
||||
// Disallow copy and assign.
|
||||
{{pluginClass}}(const {{pluginClass}}&) = delete;
|
||||
{{pluginClass}}& operator=(const {{pluginClass}}&) = delete;
|
||||
|
||||
private:
|
||||
// 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);
|
||||
};
|
||||
|
||||
} // namespace {{projectName}}
|
||||
|
||||
#endif // FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_H_
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "include/{{projectName}}/{{pluginClassSnakeCase}}_c_api.h"
|
||||
|
||||
#include <flutter/plugin_registrar_windows.h>
|
||||
|
||||
#include "{{pluginClassSnakeCase}}.h"
|
||||
|
||||
void {{pluginClass}}CApiRegisterWithRegistrar(
|
||||
FlutterDesktopPluginRegistrarRef registrar) {
|
||||
{{projectName}}::{{pluginClass}}::RegisterWithRegistrar(
|
||||
flutter::PluginRegistrarManager::GetInstance()
|
||||
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
|
||||
}
|
||||
Reference in New Issue
Block a user