chore: generate template (#17)
This commit is contained in:
committed by
GitHub
parent
5baf0dfa61
commit
699457e663
17
brick/__brick__/{{project_name.snakeCase()}}_linux/linux/.gitignore
vendored
Normal file
17
brick/__brick__/{{project_name.snakeCase()}}_linux/linux/.gitignore
vendored
Normal file
@@ -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/
|
||||
@@ -0,0 +1,21 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
set(PROJECT_NAME "{{project_name.snakeCase()}}_linux")
|
||||
project(${PROJECT_NAME} LANGUAGES CXX)
|
||||
|
||||
set(PLUGIN_NAME "${PROJECT_NAME}_plugin")
|
||||
|
||||
list(APPEND PLUGIN_SOURCES
|
||||
"{{project_name.snakeCase()}}_linux_plugin.cc"
|
||||
)
|
||||
|
||||
add_library(${PLUGIN_NAME} SHARED
|
||||
${PLUGIN_SOURCES}
|
||||
)
|
||||
apply_standard_settings(${PLUGIN_NAME})
|
||||
set_target_properties(${PLUGIN_NAME} PROPERTIES
|
||||
CXX_VISIBILITY_PRESET hidden)
|
||||
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
|
||||
target_include_directories(${PLUGIN_NAME} INTERFACE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter)
|
||||
target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK)
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef FLUTTER_PLUGIN_MY_PLUGIN_LINUX_PLUGIN_H_
|
||||
#define FLUTTER_PLUGIN_MY_PLUGIN_LINUX_PLUGIN_H_
|
||||
|
||||
#include <flutter_linux/flutter_linux.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#ifdef FLUTTER_PLUGIN_IMPL
|
||||
#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
|
||||
#else
|
||||
#define FLUTTER_PLUGIN_EXPORT
|
||||
#endif
|
||||
|
||||
G_DECLARE_FINAL_TYPE(Fl{{project_name.pascalCase()}}Plugin, fl_{{project_name.snakeCase()}}_plugin, FL,
|
||||
MY_PLUGIN_PLUGIN, GObject)
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT Fl{{project_name.pascalCase()}}Plugin* fl_{{project_name.snakeCase()}}_plugin_new(
|
||||
FlPluginRegistrar* registrar);
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void {{project_name.snakeCase()}}_plugin_register_with_registrar(
|
||||
FlPluginRegistrar* registrar);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif // FLUTTER_PLUGIN_MY_PLUGIN_LINUX_PLUGIN_H_
|
||||
@@ -0,0 +1,68 @@
|
||||
#include "include/{{project_name.snakeCase()}}_linux/{{project_name.snakeCase()}}_plugin.h"
|
||||
|
||||
#include <flutter_linux/flutter_linux.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
const char kChannelName[] = "{{project_name.snakeCase()}}_linux";
|
||||
const char kGetPlatformName[] = "getPlatformName";
|
||||
|
||||
struct _Fl{{project_name.pascalCase()}}Plugin {
|
||||
GObject parent_instance;
|
||||
|
||||
FlPluginRegistrar* registrar;
|
||||
|
||||
// Connection to Flutter engine.
|
||||
FlMethodChannel* channel;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(Fl{{project_name.pascalCase()}}Plugin, fl_{{project_name.snakeCase()}}_plugin, g_object_get_type())
|
||||
|
||||
// Called when a method call is received from Flutter.
|
||||
static void method_call_cb(FlMethodChannel* channel, FlMethodCall* method_call,
|
||||
gpointer user_data) {
|
||||
const gchar* method = fl_method_call_get_name(method_call);
|
||||
|
||||
g_autoptr(FlMethodResponse) response = nullptr;
|
||||
if (strcmp(method, kGetPlatformName) == 0)
|
||||
response = FL_METHOD_RESPONSE(fl_method_success_response_new(fl_value_new_string("Linux")));
|
||||
else
|
||||
response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
|
||||
|
||||
g_autoptr(GError) error = nullptr;
|
||||
if (!fl_method_call_respond(method_call, response, &error))
|
||||
g_warning("Failed to send method call response: %s", error->message);
|
||||
}
|
||||
|
||||
static void fl_{{project_name.snakeCase()}}_plugin_dispose(GObject* object) {
|
||||
G_OBJECT_CLASS(fl_{{project_name.snakeCase()}}_plugin_parent_class)->dispose(object);
|
||||
}
|
||||
|
||||
static void fl_{{project_name.snakeCase()}}_plugin_class_init(Fl{{project_name.pascalCase()}}PluginClass* klass) {
|
||||
G_OBJECT_CLASS(klass)->dispose = fl_{{project_name.snakeCase()}}_plugin_dispose;
|
||||
}
|
||||
|
||||
Fl{{project_name.pascalCase()}}Plugin* fl_{{project_name.snakeCase()}}_plugin_new(FlPluginRegistrar* registrar) {
|
||||
Fl{{project_name.pascalCase()}}Plugin* self = FL_MY_PLUGIN_PLUGIN(
|
||||
g_object_new(fl_{{project_name.snakeCase()}}_plugin_get_type(), nullptr));
|
||||
|
||||
self->registrar = FL_PLUGIN_REGISTRAR(g_object_ref(registrar));
|
||||
|
||||
g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
|
||||
self->channel =
|
||||
fl_method_channel_new(fl_plugin_registrar_get_messenger(registrar),
|
||||
kChannelName, FL_METHOD_CODEC(codec));
|
||||
fl_method_channel_set_method_call_handler(self->channel, method_call_cb,
|
||||
g_object_ref(self), g_object_unref);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
static void fl_{{project_name.snakeCase()}}_plugin_init(Fl{{project_name.pascalCase()}}Plugin* self) {}
|
||||
|
||||
void {{project_name.snakeCase()}}_plugin_register_with_registrar(FlPluginRegistrar* registrar) {
|
||||
Fl{{project_name.pascalCase()}}Plugin* plugin = fl_{{project_name.snakeCase()}}_plugin_new(registrar);
|
||||
g_object_unref(plugin);
|
||||
}
|
||||
Reference in New Issue
Block a user