Browse Source

add aurora platform

master
parent
commit
c697a90ef4
  1. 5
      aurora/CMakeLists.txt
  2. 19
      aurora/clipboard_plugin.cpp
  3. 2
      aurora/include/clipboard/clipboard_plugin.h
  4. 5
      lib/clipboard.dart
  5. 9
      lib/clipboard_method_channel.dart
  6. 4
      lib/clipboard_platform_interface.dart
  7. 47
      pubspec.yaml

5
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)

19
aurora/clipboard_plugin.cpp

@ -1,6 +1,9 @@
#include <clipboard/clipboard_plugin.h>
#include <flutter/method-channel.h>
#include <sys/utsname.h>
#include <QClipboard>
#include <QApplication>
#include <QCoreApplication>
void ClipboardPlugin::RegisterWithRegistrar(PluginRegistrar &registrar)
{
@ -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<Encodable::String>("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)

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

5
lib/clipboard.dart

@ -2,7 +2,8 @@
import 'clipboard_platform_interface.dart';
class Clipboard {
Future<String?> getPlatformVersion() {
return ClipboardPlatform.instance.getPlatformVersion();
Future<void> setText(String value) {
return ClipboardPlatform.instance.setText(value);
}
}

9
lib/clipboard_method_channel.dart

@ -10,8 +10,11 @@ class MethodChannelClipboard extends ClipboardPlatform {
final methodChannel = const MethodChannel('clipboard');
@override
Future<String?> getPlatformVersion() async {
final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
return version;
Future<void> setText(String value) async {
if (TargetPlatform.aurora == defaultTargetPlatform) {
return methodChannel.invokeMethod<void>('setText', { 'value': value });
}
return Clipboard.setData(ClipboardData(text: value));
}
}

4
lib/clipboard_platform_interface.dart

@ -23,7 +23,7 @@ abstract class ClipboardPlatform extends PlatformInterface {
_instance = instance;
}
Future<String?> getPlatformVersion() {
throw UnimplementedError('platformVersion() has not been implemented.');
Future<void> setText(String value) {
throw UnimplementedError('setText() has not been implemented.');
}
}

47
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

Loading…
Cancel
Save