diff --git a/aurora/CMakeLists.txt b/aurora/CMakeLists.txt index a2d5a15..cc25e91 100644 --- a/aurora/CMakeLists.txt +++ b/aurora/CMakeLists.txt @@ -14,10 +14,13 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O3") find_package(PkgConfig REQUIRED) pkg_check_modules(FlutterEmbedder REQUIRED IMPORTED_TARGET flutter-embedder) +set(CMAKE_AUTOMOC ON) +find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED) + add_library(${PLUGIN_NAME} SHARED clipboard_plugin.cpp) set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) -target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::FlutterEmbedder) +target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::FlutterEmbedder Qt5::Core Qt5::Gui Qt5::Widgets) target_include_directories(${PLUGIN_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_compile_definitions(${PLUGIN_NAME} PRIVATE PLUGIN_IMPL) diff --git a/aurora/clipboard_plugin.cpp b/aurora/clipboard_plugin.cpp index 3fd7438..55bcfff 100644 --- a/aurora/clipboard_plugin.cpp +++ b/aurora/clipboard_plugin.cpp @@ -1,6 +1,9 @@ #include #include #include +#include +#include +#include void ClipboardPlugin::RegisterWithRegistrar(PluginRegistrar ®istrar) { @@ -13,23 +16,23 @@ void ClipboardPlugin::onMethodCall(const MethodCall &call) { const auto &method = call.GetMethod(); - if (method == "getPlatformVersion") { - onGetPlatformVersion(call); + if (method == "setText") { + onSetText(call); return; } unimplemented(call); } -void ClipboardPlugin::onGetPlatformVersion(const MethodCall &call) +void ClipboardPlugin::onSetText(const MethodCall &call) { - utsname uname_data{}; - uname(&uname_data); + auto value = call.GetArgument("value"); - std::string preamble = "Aurora (Linux): "; - std::string version = preamble + uname_data.version; + if(QClipboard* c = QApplication::clipboard() ) { + c->setText(value.c_str()); + } - call.SendSuccessResponse(version); + call.SendSuccessResponse(nullptr); } void ClipboardPlugin::unimplemented(const MethodCall &call) diff --git a/aurora/include/clipboard/clipboard_plugin.h b/aurora/include/clipboard/clipboard_plugin.h index 6b286ac..6b2f7f1 100644 --- a/aurora/include/clipboard/clipboard_plugin.h +++ b/aurora/include/clipboard/clipboard_plugin.h @@ -11,7 +11,7 @@ public: private: void onMethodCall(const MethodCall &call); - void onGetPlatformVersion(const MethodCall &call); + void onSetText(const MethodCall &call); void unimplemented(const MethodCall &call); }; diff --git a/lib/clipboard.dart b/lib/clipboard.dart index d31e852..574d839 100644 --- a/lib/clipboard.dart +++ b/lib/clipboard.dart @@ -2,7 +2,8 @@ import 'clipboard_platform_interface.dart'; class Clipboard { - Future getPlatformVersion() { - return ClipboardPlatform.instance.getPlatformVersion(); + + Future setText(String value) { + return ClipboardPlatform.instance.setText(value); } } diff --git a/lib/clipboard_method_channel.dart b/lib/clipboard_method_channel.dart index 0f435a9..5be3fda 100644 --- a/lib/clipboard_method_channel.dart +++ b/lib/clipboard_method_channel.dart @@ -10,8 +10,11 @@ class MethodChannelClipboard extends ClipboardPlatform { final methodChannel = const MethodChannel('clipboard'); @override - Future getPlatformVersion() async { - final version = await methodChannel.invokeMethod('getPlatformVersion'); - return version; + Future setText(String value) async { + if (TargetPlatform.aurora == defaultTargetPlatform) { + return methodChannel.invokeMethod('setText', { 'value': value }); + } + + return Clipboard.setData(ClipboardData(text: value)); } } diff --git a/lib/clipboard_platform_interface.dart b/lib/clipboard_platform_interface.dart index 26f9714..6b9d16f 100644 --- a/lib/clipboard_platform_interface.dart +++ b/lib/clipboard_platform_interface.dart @@ -23,7 +23,7 @@ abstract class ClipboardPlatform extends PlatformInterface { _instance = instance; } - Future getPlatformVersion() { - throw UnimplementedError('platformVersion() has not been implemented.'); + Future setText(String value) { + throw UnimplementedError('setText() has not been implemented.'); } } diff --git a/pubspec.yaml b/pubspec.yaml index 80e2eba..13ca9cc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 0.0.1 homepage: environment: - sdk: '>=3.2.2 <4.0.0' + sdk: '>=3.1.2 <4.0.0' flutter: '>=3.3.0' dependencies: @@ -17,53 +17,8 @@ dev_dependencies: sdk: flutter flutter_lints: ^2.0.0 -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -# The following section is specific to Flutter packages. flutter: - # This section identifies this Flutter project as a plugin project. - # The 'pluginClass' specifies the class (in Java, Kotlin, Swift, Objective-C, etc.) - # which should be registered in the plugin registry. This is required for - # using method channels. - # The Android 'package' specifies package in which the registered class is. - # This is required for using method channels on Android. - # The 'ffiPlugin' specifies that native code should be built and bundled. - # This is required for using `dart:ffi`. - # All these are used by the tooling to maintain consistency when - # adding or updating assets for this project. plugin: platforms: aurora: - pluginClass: ClipboardPlugin - - # To add assets to your plugin package, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg - # - # For details regarding assets in packages, see - # https://flutter.dev/assets-and-images/#from-packages - # - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware - - # To add custom fonts to your plugin package, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts in packages, see - # https://flutter.dev/custom-fonts/#from-packages + pluginClass: ClipboardPlugin \ No newline at end of file