From 7fd25b824e22a36627de58946279ffd7f257f254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9C=D0=B0=D1=80?= =?UTF-8?q?=D0=BA=D0=BE=D0=B2?= Date: Sat, 9 Dec 2023 15:15:17 +0300 Subject: [PATCH] init commit --- .gitignore | 29 +++++++++ .metadata | 30 +++++++++ CHANGELOG.md | 3 + LICENSE | 1 + README.md | 15 +++++ analysis_options.yaml | 4 ++ aurora/CMakeLists.txt | 23 +++++++ aurora/clipboard_plugin.cpp | 38 ++++++++++++ aurora/include/clipboard/clipboard_plugin.h | 18 ++++++ aurora/include/clipboard/globals.h | 10 +++ lib/clipboard.dart | 8 +++ lib/clipboard_method_channel.dart | 17 +++++ lib/clipboard_platform_interface.dart | 29 +++++++++ pubspec.yaml | 69 +++++++++++++++++++++ 14 files changed, 294 insertions(+) create mode 100644 .gitignore create mode 100644 .metadata create mode 100644 CHANGELOG.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 analysis_options.yaml create mode 100644 aurora/CMakeLists.txt create mode 100644 aurora/clipboard_plugin.cpp create mode 100644 aurora/include/clipboard/clipboard_plugin.h create mode 100644 aurora/include/clipboard/globals.h create mode 100644 lib/clipboard.dart create mode 100644 lib/clipboard_method_channel.dart create mode 100644 lib/clipboard_platform_interface.dart create mode 100644 pubspec.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ac5aa98 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +build/ diff --git a/.metadata b/.metadata new file mode 100644 index 0000000..786054c --- /dev/null +++ b/.metadata @@ -0,0 +1,30 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: "d3e00ac70443dbc0df7d0b56bff94c18d760b02f" + channel: "master" + +project_type: plugin + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: d3e00ac70443dbc0df7d0b56bff94c18d760b02f + base_revision: d3e00ac70443dbc0df7d0b56bff94c18d760b02f + - platform: aurora + create_revision: d3e00ac70443dbc0df7d0b56bff94c18d760b02f + base_revision: d3e00ac70443dbc0df7d0b56bff94c18d760b02f + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..41cc7d8 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.0.1 + +* TODO: Describe initial release. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ba75c69 --- /dev/null +++ b/LICENSE @@ -0,0 +1 @@ +TODO: Add your license here. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ca8d518 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# clipboard + +A new Flutter plugin project. + +## Getting Started + +This project is a starting point for a Flutter +[plug-in package](https://flutter.dev/developing-packages/), +a specialized package that includes platform-specific implementation code for +Android and/or iOS. + +For help getting started with Flutter development, view the +[online documentation](https://flutter.dev/docs), which offers tutorials, +samples, guidance on mobile development, and a full API reference. + diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..a5744c1 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:flutter_lints/flutter.yaml + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/aurora/CMakeLists.txt b/aurora/CMakeLists.txt new file mode 100644 index 0000000..a2d5a15 --- /dev/null +++ b/aurora/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.10) + +set(PROJECT_NAME clipboard) +set(PLUGIN_NAME clipboard_platform_plugin) + +project(${PROJECT_NAME} LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-psabi") +set(CMAKE_CXX_FLAGS_RELEASE "-O3") + +find_package(PkgConfig REQUIRED) +pkg_check_modules(FlutterEmbedder REQUIRED IMPORTED_TARGET flutter-embedder) + +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_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 new file mode 100644 index 0000000..3fd7438 --- /dev/null +++ b/aurora/clipboard_plugin.cpp @@ -0,0 +1,38 @@ +#include +#include +#include + +void ClipboardPlugin::RegisterWithRegistrar(PluginRegistrar ®istrar) +{ + registrar.RegisterMethodChannel("clipboard", + MethodCodecType::Standard, + [this](const MethodCall &call) { this->onMethodCall(call); }); +} + +void ClipboardPlugin::onMethodCall(const MethodCall &call) +{ + const auto &method = call.GetMethod(); + + if (method == "getPlatformVersion") { + onGetPlatformVersion(call); + return; + } + + unimplemented(call); +} + +void ClipboardPlugin::onGetPlatformVersion(const MethodCall &call) +{ + utsname uname_data{}; + uname(&uname_data); + + std::string preamble = "Aurora (Linux): "; + std::string version = preamble + uname_data.version; + + call.SendSuccessResponse(version); +} + +void ClipboardPlugin::unimplemented(const MethodCall &call) +{ + call.SendSuccessResponse(nullptr); +} diff --git a/aurora/include/clipboard/clipboard_plugin.h b/aurora/include/clipboard/clipboard_plugin.h new file mode 100644 index 0000000..6b286ac --- /dev/null +++ b/aurora/include/clipboard/clipboard_plugin.h @@ -0,0 +1,18 @@ +#ifndef FLUTTER_PLUGIN_CLIPBOARD_PLUGIN_H +#define FLUTTER_PLUGIN_CLIPBOARD_PLUGIN_H + +#include +#include + +class PLUGIN_EXPORT ClipboardPlugin final : public PluginInterface +{ +public: + void RegisterWithRegistrar(PluginRegistrar ®istrar) override; + +private: + void onMethodCall(const MethodCall &call); + void onGetPlatformVersion(const MethodCall &call); + void unimplemented(const MethodCall &call); +}; + +#endif /* FLUTTER_PLUGIN_CLIPBOARD_PLUGIN_H */ diff --git a/aurora/include/clipboard/globals.h b/aurora/include/clipboard/globals.h new file mode 100644 index 0000000..7fe6c2e --- /dev/null +++ b/aurora/include/clipboard/globals.h @@ -0,0 +1,10 @@ +#ifndef FLUTTER_PLUGIN_CLIPBOARD_PLUGIN_GLOBALS_H +#define FLUTTER_PLUGIN_CLIPBOARD_PLUGIN_GLOBALS_H + +#ifdef PLUGIN_IMPL +#define PLUGIN_EXPORT __attribute__((visibility("default"))) +#else +#define PLUGIN_EXPORT +#endif + +#endif /* FLUTTER_PLUGIN_CLIPBOARD_PLUGIN_GLOBALS_H */ diff --git a/lib/clipboard.dart b/lib/clipboard.dart new file mode 100644 index 0000000..d31e852 --- /dev/null +++ b/lib/clipboard.dart @@ -0,0 +1,8 @@ + +import 'clipboard_platform_interface.dart'; + +class Clipboard { + Future getPlatformVersion() { + return ClipboardPlatform.instance.getPlatformVersion(); + } +} diff --git a/lib/clipboard_method_channel.dart b/lib/clipboard_method_channel.dart new file mode 100644 index 0000000..0f435a9 --- /dev/null +++ b/lib/clipboard_method_channel.dart @@ -0,0 +1,17 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'clipboard_platform_interface.dart'; + +/// An implementation of [ClipboardPlatform] that uses method channels. +class MethodChannelClipboard extends ClipboardPlatform { + /// The method channel used to interact with the native platform. + @visibleForTesting + final methodChannel = const MethodChannel('clipboard'); + + @override + Future getPlatformVersion() async { + final version = await methodChannel.invokeMethod('getPlatformVersion'); + return version; + } +} diff --git a/lib/clipboard_platform_interface.dart b/lib/clipboard_platform_interface.dart new file mode 100644 index 0000000..26f9714 --- /dev/null +++ b/lib/clipboard_platform_interface.dart @@ -0,0 +1,29 @@ +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +import 'clipboard_method_channel.dart'; + +abstract class ClipboardPlatform extends PlatformInterface { + /// Constructs a ClipboardPlatform. + ClipboardPlatform() : super(token: _token); + + static final Object _token = Object(); + + static ClipboardPlatform _instance = MethodChannelClipboard(); + + /// The default instance of [ClipboardPlatform] to use. + /// + /// Defaults to [MethodChannelClipboard]. + static ClipboardPlatform get instance => _instance; + + /// Platform-specific implementations should set this with their own + /// platform-specific class that extends [ClipboardPlatform] when + /// they register themselves. + static set instance(ClipboardPlatform instance) { + PlatformInterface.verifyToken(instance, _token); + _instance = instance; + } + + Future getPlatformVersion() { + throw UnimplementedError('platformVersion() has not been implemented.'); + } +} diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..80e2eba --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,69 @@ +name: clipboard +description: "A new Flutter plugin project." +version: 0.0.1 +homepage: + +environment: + sdk: '>=3.2.2 <4.0.0' + flutter: '>=3.3.0' + +dependencies: + flutter: + sdk: flutter + plugin_platform_interface: ^2.0.2 + +dev_dependencies: + flutter_test: + 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