diff --git a/packages/shared_preferences/.gitignore b/packages/shared_preferences/.gitignore new file mode 100644 index 0000000..abc5ecc --- /dev/null +++ b/packages/shared_preferences/.gitignore @@ -0,0 +1,31 @@ +# 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/ +.packages +build/ +.metadata \ No newline at end of file diff --git a/packages/shared_preferences/README.md b/packages/shared_preferences/README.md new file mode 100644 index 0000000..f966827 --- /dev/null +++ b/packages/shared_preferences/README.md @@ -0,0 +1,3 @@ +# shared_preferences + +A new Flutter FFI plugin project. \ No newline at end of file diff --git a/packages/shared_preferences/analysis_options.yaml b/packages/shared_preferences/analysis_options.yaml new file mode 100644 index 0000000..a5744c1 --- /dev/null +++ b/packages/shared_preferences/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/packages/shared_preferences/aurora/CMakeLists.txt b/packages/shared_preferences/aurora/CMakeLists.txt new file mode 100644 index 0000000..2a058bc --- /dev/null +++ b/packages/shared_preferences/aurora/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.10) + +set(PLUGIN_NAME shared_preferences) +project(${PLUGIN_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") + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_BINARY_DIR}/shared) diff --git a/packages/shared_preferences/example/.gitignore b/packages/shared_preferences/example/.gitignore new file mode 100644 index 0000000..24476c5 --- /dev/null +++ b/packages/shared_preferences/example/.gitignore @@ -0,0 +1,44 @@ +# 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 +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/packages/shared_preferences/example/README.md b/packages/shared_preferences/example/README.md new file mode 100644 index 0000000..3122994 --- /dev/null +++ b/packages/shared_preferences/example/README.md @@ -0,0 +1,16 @@ +# shared_preferences_example + +Demonstrates how to use the shared_preferences plugin. + +## Getting Started + +This project is a starting point for a Flutter application. + +A few resources to get you started if this is your first Flutter project: + +- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) +- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) + +For help getting started with Flutter development, view the +[online documentation](https://docs.flutter.dev/), which offers tutorials, +samples, guidance on mobile development, and a full API reference. diff --git a/packages/shared_preferences/example/analysis_options.yaml b/packages/shared_preferences/example/analysis_options.yaml new file mode 100644 index 0000000..61b6c4d --- /dev/null +++ b/packages/shared_preferences/example/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/packages/shared_preferences/example/aurora/.gitignore b/packages/shared_preferences/example/aurora/.gitignore new file mode 100644 index 0000000..d3896c9 --- /dev/null +++ b/packages/shared_preferences/example/aurora/.gitignore @@ -0,0 +1 @@ +flutter/ephemeral diff --git a/packages/shared_preferences/example/aurora/CMakeLists.txt b/packages/shared_preferences/example/aurora/CMakeLists.txt new file mode 100644 index 0000000..8773a3d --- /dev/null +++ b/packages/shared_preferences/example/aurora/CMakeLists.txt @@ -0,0 +1,47 @@ +cmake_minimum_required(VERSION 3.10) +project(com.example.shared_preferences_example LANGUAGES CXX) + +include(GNUInstallDirs) + +set(BINARY_NAME ${CMAKE_PROJECT_NAME}) +set(FLUTTER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/flutter) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_CXX_FLAGS "-Wall -Wextra") +set(CMAKE_CXX_FLAGS_RELEASE "-O3") + +set(CMAKE_SKIP_RPATH OFF) +set(CMAKE_INSTALL_RPATH "\$ORIGIN/../share/${BINARY_NAME}/lib") + +find_package(PkgConfig REQUIRED) +pkg_check_modules(FlutterEmbedder REQUIRED IMPORTED_TARGET flutter-embedder) + +add_executable(${BINARY_NAME} main.cpp ${FLUTTER_DIR}/generated_plugin_registrant.cpp) +target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::FlutterEmbedder) +target_include_directories(${BINARY_NAME} PRIVATE ${FLUTTER_DIR}) + +include(flutter/generated_plugins.cmake) + +set(PACKAGE_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME}) +set(DESKTOP_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/applications) +set(ICONS_INSTALL_ROOT_DIR ${CMAKE_INSTALL_DATADIR}/icons/hicolor) + +add_custom_command(TARGET ${BINARY_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libflutter-embedder.so + ${PROJECT_BINARY_DIR}/bundle/lib/libflutter-embedder.so) + +install(FILES ${PROJECT_BINARY_DIR}/bundle/icudtl.dat DESTINATION ${PACKAGE_INSTALL_DIR}) +install(DIRECTORY ${PROJECT_BINARY_DIR}/bundle/flutter_assets DESTINATION ${PACKAGE_INSTALL_DIR}) +install(DIRECTORY ${PROJECT_BINARY_DIR}/bundle/lib DESTINATION ${PACKAGE_INSTALL_DIR}) + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(FILES desktop/${BINARY_NAME}.desktop DESTINATION ${DESKTOP_INSTALL_DIR}) + +foreach(ICONS_SIZE 86x86 108x108 128x128 172x172) + install(FILES icons/${ICONS_SIZE}.png + RENAME ${BINARY_NAME}.png + DESTINATION ${ICONS_INSTALL_ROOT_DIR}/${ICONS_SIZE}/apps/) +endforeach(ICONS_SIZE) diff --git a/packages/shared_preferences/example/aurora/desktop/com.example.shared_preferences_example.desktop b/packages/shared_preferences/example/aurora/desktop/com.example.shared_preferences_example.desktop new file mode 100644 index 0000000..78c23e2 --- /dev/null +++ b/packages/shared_preferences/example/aurora/desktop/com.example.shared_preferences_example.desktop @@ -0,0 +1,12 @@ +[Desktop Entry] +Type=Application +Name=shared_preferences_example +Comment=Demonstrates how to use the shared_preferences plugin. +Icon=com.example.shared_preferences_example +Exec=/usr/bin/com.example.shared_preferences_example +X-Nemo-Application-Type=silica-qt5 + +[X-Application] +Permissions= +OrganizationName=com.example +ApplicationName=shared_preferences_example diff --git a/packages/shared_preferences/example/aurora/flutter/generated_plugin_registrant.cpp b/packages/shared_preferences/example/aurora/flutter/generated_plugin_registrant.cpp new file mode 100644 index 0000000..b315972 --- /dev/null +++ b/packages/shared_preferences/example/aurora/flutter/generated_plugin_registrant.cpp @@ -0,0 +1,14 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#include + +#include "generated_plugin_registrant.h" + +void RegisterPlugins() { + Application::RegisterPlugins({ + }); +} diff --git a/packages/shared_preferences/example/aurora/flutter/generated_plugin_registrant.h b/packages/shared_preferences/example/aurora/flutter/generated_plugin_registrant.h new file mode 100644 index 0000000..648dcb3 --- /dev/null +++ b/packages/shared_preferences/example/aurora/flutter/generated_plugin_registrant.h @@ -0,0 +1,12 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#ifndef GENERATED_PLUGIN_REGISTRANT +#define GENERATED_PLUGIN_REGISTRANT + +void RegisterPlugins(); + +#endif /* GENERATED_PLUGIN_REGISTRANT */ diff --git a/packages/shared_preferences/example/aurora/flutter/generated_plugins.cmake b/packages/shared_preferences/example/aurora/flutter/generated_plugins.cmake new file mode 100644 index 0000000..73b50df --- /dev/null +++ b/packages/shared_preferences/example/aurora/flutter/generated_plugins.cmake @@ -0,0 +1,31 @@ +# +# Generated file, do not edit. +# +set(ROOT_PROJECT_BINARY_DIR "${PROJECT_BINARY_DIR}") + +function(add_library TARGET) + _add_library(${TARGET} ${ARGN}) + + if(NOT "${TARGET}" MATCHES "^PkgConfig::.*") + add_custom_command(TARGET ${TARGET} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "$" + "${ROOT_PROJECT_BINARY_DIR}/bundle/lib/$") + endif(NOT "${TARGET}" MATCHES "^PkgConfig::.*") +endfunction() + +list(APPEND FLUTTER_PLATFORM_PLUGIN_LIST +) + +list(APPEND FLUTTER_FFI_PLUGIN_LIST + shared_preferences +) + +foreach(PLUGIN ${FLUTTER_PLATFORM_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${PLUGIN}/aurora plugins/${PLUGIN}) + target_link_libraries(${BINARY_NAME} PRIVATE ${PLUGIN}_platform_plugin) +endforeach(PLUGIN) + +foreach(FFI_PLUGIN ${FLUTTER_FFI_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${FFI_PLUGIN}/aurora plugins/${FFI_PLUGIN}) +endforeach(FFI_PLUGIN) diff --git a/packages/shared_preferences/example/aurora/icons/108x108.png b/packages/shared_preferences/example/aurora/icons/108x108.png new file mode 100644 index 0000000..984893d Binary files /dev/null and b/packages/shared_preferences/example/aurora/icons/108x108.png differ diff --git a/packages/shared_preferences/example/aurora/icons/128x128.png b/packages/shared_preferences/example/aurora/icons/128x128.png new file mode 100644 index 0000000..2d552ef Binary files /dev/null and b/packages/shared_preferences/example/aurora/icons/128x128.png differ diff --git a/packages/shared_preferences/example/aurora/icons/172x172.png b/packages/shared_preferences/example/aurora/icons/172x172.png new file mode 100644 index 0000000..9dc271b Binary files /dev/null and b/packages/shared_preferences/example/aurora/icons/172x172.png differ diff --git a/packages/shared_preferences/example/aurora/icons/86x86.png b/packages/shared_preferences/example/aurora/icons/86x86.png new file mode 100644 index 0000000..5923bb1 Binary files /dev/null and b/packages/shared_preferences/example/aurora/icons/86x86.png differ diff --git a/packages/shared_preferences/example/aurora/main.cpp b/packages/shared_preferences/example/aurora/main.cpp new file mode 100644 index 0000000..2dd2f52 --- /dev/null +++ b/packages/shared_preferences/example/aurora/main.cpp @@ -0,0 +1,10 @@ +#include +#include "generated_plugin_registrant.h" + +int main(int argc, char *argv[]) { + Application::Initialize(argc, argv); + Application::SetPixelRatio(1.8); + RegisterPlugins(); + Application::Launch(); + return 0; +} diff --git a/packages/shared_preferences/example/aurora/rpm/com.example.shared_preferences_example.spec b/packages/shared_preferences/example/aurora/rpm/com.example.shared_preferences_example.spec new file mode 100644 index 0000000..b66ae7d --- /dev/null +++ b/packages/shared_preferences/example/aurora/rpm/com.example.shared_preferences_example.spec @@ -0,0 +1,31 @@ +%global __provides_exclude_from ^%{_datadir}/%{name}/lib/.*$ +%global __requires_exclude ^lib(dconf|flutter-embedder|maliit-glib|appmanifest-.+|.+_platform_plugin)\\.so.*$ + +Name: com.example.shared_preferences_example +Summary: Demonstrates how to use the shared_preferences plugin. +Version: 0.1.0 +Release: 1 +License: Proprietary +Source0: %{name}-%{version}.tar.zst + +BuildRequires: cmake +BuildRequires: pkgconfig(flutter-embedder) + +%description +%{summary}. + +%prep +%autosetup + +%build +%cmake -DCMAKE_BUILD_TYPE=%{_flutter_build_type} +%make_build + +%install +%make_install + +%files +%{_bindir}/%{name} +%{_datadir}/%{name}/* +%{_datadir}/applications/%{name}.desktop +%{_datadir}/icons/hicolor/*/apps/%{name}.png diff --git a/packages/shared_preferences/example/defaultuser@ b/packages/shared_preferences/example/defaultuser@ new file mode 100644 index 0000000..87b4552 Binary files /dev/null and b/packages/shared_preferences/example/defaultuser@ differ diff --git a/packages/shared_preferences/example/lib/main.dart b/packages/shared_preferences/example/lib/main.dart new file mode 100644 index 0000000..43494b6 --- /dev/null +++ b/packages/shared_preferences/example/lib/main.dart @@ -0,0 +1,75 @@ +import 'package:flutter/material.dart'; +import 'dart:async'; + +import 'package:shared_preferences/shared_preferences.dart' + as shared_preferences; + +void main() { + runApp(const MyApp()); +} + +class MyApp extends StatefulWidget { + const MyApp({super.key}); + + @override + _MyAppState createState() => _MyAppState(); +} + +class _MyAppState extends State { + late int sumResult; + late Future sumAsyncResult; + + @override + void initState() { + super.initState(); + sumResult = shared_preferences.sum(1, 2); + sumAsyncResult = shared_preferences.sumAsync(3, 4); + } + + @override + Widget build(BuildContext context) { + const textStyle = TextStyle(fontSize: 25); + const spacerSmall = SizedBox(height: 10); + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('Native Packages'), + ), + body: SingleChildScrollView( + child: Container( + padding: const EdgeInsets.all(10), + child: Column( + children: [ + const Text( + 'This calls a native function through FFI that is shipped as source in the package. ' + 'The native code is built as part of the Flutter Runner build.', + style: textStyle, + textAlign: TextAlign.center, + ), + spacerSmall, + Text( + 'sum(1, 2) = $sumResult', + style: textStyle, + textAlign: TextAlign.center, + ), + spacerSmall, + FutureBuilder( + future: sumAsyncResult, + builder: (BuildContext context, AsyncSnapshot value) { + final displayValue = + (value.hasData) ? value.data : 'loading'; + return Text( + 'await sumAsync(3, 4) = $displayValue', + style: textStyle, + textAlign: TextAlign.center, + ); + }, + ), + ], + ), + ), + ), + ), + ); + } +} diff --git a/packages/shared_preferences/example/pubspec.lock b/packages/shared_preferences/example/pubspec.lock new file mode 100644 index 0000000..708ef84 --- /dev/null +++ b/packages/shared_preferences/example/pubspec.lock @@ -0,0 +1,175 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + url: "https://pub.dartlang.org" + source: hosted + version: "2.9.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.16.0" + cupertino_icons: + dependency: "direct main" + description: + name: cupertino_icons + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.5" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.1" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + lints: + dependency: transitive + description: + name: lints + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + matcher: + dependency: transitive + description: + name: matcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.12" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.5" + meta: + dependency: transitive + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.0" + path: + dependency: transitive + description: + name: path + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.2" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" + shared_preferences: + dependency: "direct main" + description: + path: ".." + relative: true + source: path + version: "0.0.1" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: transitive + description: + name: source_span + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "1.10.0" + stream_channel: + dependency: transitive + description: + name: stream_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + test_api: + dependency: transitive + description: + name: test_api + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.12" + vector_math: + dependency: transitive + description: + name: vector_math + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.2" +sdks: + dart: ">=2.18.6 <3.0.0" + flutter: ">=2.11.0" diff --git a/packages/shared_preferences/example/pubspec.yaml b/packages/shared_preferences/example/pubspec.yaml new file mode 100644 index 0000000..b81209b --- /dev/null +++ b/packages/shared_preferences/example/pubspec.yaml @@ -0,0 +1,98 @@ +name: shared_preferences_example +description: Demonstrates how to use the shared_preferences plugin. + +# The following line prevents the package from being accidentally published to +# pub.dev using `flutter pub publish`. This is preferred for private packages. +publish_to: 'none' # Remove this line if you wish to publish to pub.dev + +# The following defines the version and build number for your application. +# A version number is three numbers separated by dots, like 1.2.43 +# followed by an optional build number separated by a +. +# Both the version and the builder number may be overridden in flutter +# build by specifying --build-name and --build-number, respectively. +# In Android, build-name is used as versionName while build-number used as versionCode. +# Read more about Android versioning at https://developer.android.com/studio/publish/versioning +# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. +# Read more about iOS versioning at +# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html +# In Windows, build-name is used as the major, minor, and patch parts +# of the product and file versions while build-number is used as the build suffix. +version: 1.0.0+1 + +environment: + sdk: '>=2.18.6 <3.0.0' + +# Dependencies specify other packages that your package needs in order to work. +# To automatically upgrade your package dependencies to the latest versions +# consider running `flutter pub upgrade --major-versions`. Alternatively, +# dependencies can be manually updated by changing the version numbers below to +# the latest version available on pub.dev. To see which dependencies have newer +# versions available, run `flutter pub outdated`. +dependencies: + flutter: + sdk: flutter + + shared_preferences: + # When depending on this package from a real application you should use: + # shared_preferences: ^x.y.z + # See https://dart.dev/tools/pub/dependencies#version-constraints + # The example app is bundled with the plugin so we use a path dependency on + # the parent directory to use the current plugin's version. + path: ../ + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: ^1.0.2 + +dev_dependencies: + flutter_test: + sdk: flutter + + # The "flutter_lints" package below contains a set of recommended lints to + # encourage good coding practices. The lint set provided by the package is + # activated in the `analysis_options.yaml` file located at the root of your + # package. See that file for information about deactivating specific lint + # rules and activating additional ones. + 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: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + # To add assets to your application, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware + + # For details regarding adding assets from package dependencies, see + # https://flutter.dev/assets-and-images/#from-packages + + # To add custom fonts to your application, 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 from package dependencies, + # see https://flutter.dev/custom-fonts/#from-packages diff --git a/packages/shared_preferences/ffigen.yaml b/packages/shared_preferences/ffigen.yaml new file mode 100644 index 0000000..9e0d4b1 --- /dev/null +++ b/packages/shared_preferences/ffigen.yaml @@ -0,0 +1,22 @@ +# Run with `flutter pub run ffigen --config ffigen.yaml`. +name: SharedPreferencesBindings +llvm-path: + - '/usr/lib/llvm-14/lib/libclang.so' # Ubuntu 22.04 + - '/usr/lib/llvm-15/lib/libclang.so' # Ubuntu 23.04 +description: | + Bindings for `src/shared_preferences.h`. + + Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`. +output: 'lib/shared_preferences_bindings_generated.dart' +headers: + entry-points: + - 'src/shared_preferences.h' + include-directives: + - 'src/shared_preferences.h' +preamble: | + // ignore_for_file: always_specify_types + // ignore_for_file: camel_case_types + // ignore_for_file: non_constant_identifier_names +comments: + style: any + length: full \ No newline at end of file diff --git a/packages/shared_preferences/lib/shared_preferences.dart b/packages/shared_preferences/lib/shared_preferences.dart new file mode 100644 index 0000000..c1a0203 --- /dev/null +++ b/packages/shared_preferences/lib/shared_preferences.dart @@ -0,0 +1,131 @@ + +import 'dart:async'; +import 'dart:ffi'; +import 'dart:io'; +import 'dart:isolate'; + +import 'shared_preferences_bindings_generated.dart'; + +/// A very short-lived native function. +/// +/// For very short-lived functions, it is fine to call them on the main isolate. +/// They will block the Dart execution while running the native function, so +/// only do this for native functions which are guaranteed to be short-lived. +int sum(int a, int b) => _bindings.sum(a, b); + +/// A longer lived native function, which occupies the thread calling it. +/// +/// Do not call these kind of native functions in the main isolate. They will +/// block Dart execution. This will cause dropped frames in Flutter applications. +/// Instead, call these native functions on a separate isolate. +/// +/// Modify this to suit your own use case. Example use cases: +/// +/// 1. Reuse a single isolate for various different kinds of requests. +/// 2. Use multiple helper isolates for parallel execution. +Future sumAsync(int a, int b) async { + final SendPort helperIsolateSendPort = await _helperIsolateSendPort; + final int requestId = _nextSumRequestId++; + final _SumRequest request = _SumRequest(requestId, a, b); + final Completer completer = Completer(); + _sumRequests[requestId] = completer; + helperIsolateSendPort.send(request); + return completer.future; +} + +const String _libName = 'shared_preferences'; + +/// The dynamic library in which the symbols for [SharedPreferencesBindings] can be found. +final DynamicLibrary _dylib = () { + if (Platform.isMacOS || Platform.isIOS) { + return DynamicLibrary.open('$_libName.framework/$_libName'); + } + if (Platform.isAndroid || Platform.isLinux) { + return DynamicLibrary.open('lib$_libName.so'); + } + if (Platform.isWindows) { + return DynamicLibrary.open('$_libName.dll'); + } + throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}'); +}(); + +/// The bindings to the native functions in [_dylib]. +final SharedPreferencesBindings _bindings = SharedPreferencesBindings(_dylib); + + +/// A request to compute `sum`. +/// +/// Typically sent from one isolate to another. +class _SumRequest { + final int id; + final int a; + final int b; + + const _SumRequest(this.id, this.a, this.b); +} + +/// A response with the result of `sum`. +/// +/// Typically sent from one isolate to another. +class _SumResponse { + final int id; + final int result; + + const _SumResponse(this.id, this.result); +} + +/// Counter to identify [_SumRequest]s and [_SumResponse]s. +int _nextSumRequestId = 0; + +/// Mapping from [_SumRequest] `id`s to the completers corresponding to the correct future of the pending request. +final Map> _sumRequests = >{}; + +/// The SendPort belonging to the helper isolate. +Future _helperIsolateSendPort = () async { + // The helper isolate is going to send us back a SendPort, which we want to + // wait for. + final Completer completer = Completer(); + + // Receive port on the main isolate to receive messages from the helper. + // We receive two types of messages: + // 1. A port to send messages on. + // 2. Responses to requests we sent. + final ReceivePort receivePort = ReceivePort() + ..listen((dynamic data) { + if (data is SendPort) { + // The helper isolate sent us the port on which we can sent it requests. + completer.complete(data); + return; + } + if (data is _SumResponse) { + // The helper isolate sent us a response to a request we sent. + final Completer completer = _sumRequests[data.id]!; + _sumRequests.remove(data.id); + completer.complete(data.result); + return; + } + throw UnsupportedError('Unsupported message type: ${data.runtimeType}'); + }); + + // Start the helper isolate. + await Isolate.spawn((SendPort sendPort) async { + final ReceivePort helperReceivePort = ReceivePort() + ..listen((dynamic data) { + // On the helper isolate listen to requests and respond to them. + if (data is _SumRequest) { + final int result = _bindings.sum_long_running(data.a, data.b); + final _SumResponse response = _SumResponse(data.id, result); + sendPort.send(response); + return; + } + throw UnsupportedError('Unsupported message type: ${data.runtimeType}'); + }); + + // Send the the port to the main isolate on which we can receive requests. + sendPort.send(helperReceivePort.sendPort); + }, receivePort.sendPort); + + // Wait until the helper isolate has sent us back the SendPort on which we + // can start sending requests. + return completer.future; +}(); diff --git a/packages/shared_preferences/lib/shared_preferences_bindings_generated.dart b/packages/shared_preferences/lib/shared_preferences_bindings_generated.dart new file mode 100644 index 0000000..dce4212 --- /dev/null +++ b/packages/shared_preferences/lib/shared_preferences_bindings_generated.dart @@ -0,0 +1,69 @@ +// ignore_for_file: always_specify_types +// ignore_for_file: camel_case_types +// ignore_for_file: non_constant_identifier_names + +// AUTO GENERATED FILE, DO NOT EDIT. +// +// Generated by `package:ffigen`. +import 'dart:ffi' as ffi; + +/// Bindings for `src/shared_preferences.h`. +/// +/// Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`. +/// +class SharedPreferencesBindings { + /// Holds the symbol lookup function. + final ffi.Pointer Function(String symbolName) + _lookup; + + /// The symbols are looked up in [dynamicLibrary]. + SharedPreferencesBindings(ffi.DynamicLibrary dynamicLibrary) + : _lookup = dynamicLibrary.lookup; + + /// The symbols are looked up with [lookup]. + SharedPreferencesBindings.fromLookup( + ffi.Pointer Function(String symbolName) + lookup) + : _lookup = lookup; + + /// A very short-lived native function. + /// + /// For very short-lived functions, it is fine to call them on the main isolate. + /// They will block the Dart execution while running the native function, so + /// only do this for native functions which are guaranteed to be short-lived. + int sum( + int a, + int b, + ) { + return _sum( + a, + b, + ); + } + + late final _sumPtr = + _lookup>( + 'sum'); + late final _sum = _sumPtr.asFunction(); + + /// A longer lived native function, which occupies the thread calling it. + /// + /// Do not call these kind of native functions in the main isolate. They will + /// block Dart execution. This will cause dropped frames in Flutter applications. + /// Instead, call these native functions on a separate isolate. + int sum_long_running( + int a, + int b, + ) { + return _sum_long_running( + a, + b, + ); + } + + late final _sum_long_runningPtr = + _lookup>( + 'sum_long_running'); + late final _sum_long_running = + _sum_long_runningPtr.asFunction(); +} diff --git a/packages/shared_preferences/pubspec.yaml b/packages/shared_preferences/pubspec.yaml new file mode 100644 index 0000000..f68b559 --- /dev/null +++ b/packages/shared_preferences/pubspec.yaml @@ -0,0 +1,73 @@ +name: shared_preferences +description: A new Flutter FFI plugin project. +version: 0.0.1 +homepage: + +environment: + sdk: '>=2.18.6 <3.0.0' + flutter: ">=2.11.0" + +dependencies: + flutter: + sdk: flutter + plugin_platform_interface: ^2.0.2 + +dev_dependencies: + ffi: ^1.2.1 + ffigen: ^5.0.1 + 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. + # + # Please refer to README.md for a detailed explanation. + plugin: + platforms: + aurora: + ffiPlugin: true + + # 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 diff --git a/packages/shared_preferences/src/CMakeLists.txt b/packages/shared_preferences/src/CMakeLists.txt new file mode 100644 index 0000000..e5ea665 --- /dev/null +++ b/packages/shared_preferences/src/CMakeLists.txt @@ -0,0 +1,17 @@ +# The Flutter tooling requires that developers have CMake 3.10 or later +# installed. You should not increase this version, as doing so will cause +# the plugin to fail to compile for some customers of the plugin. +cmake_minimum_required(VERSION 3.10) + +project(shared_preferences_library VERSION 0.0.1 LANGUAGES C) + +add_library(shared_preferences SHARED + "shared_preferences.c" +) + +set_target_properties(shared_preferences PROPERTIES + PUBLIC_HEADER shared_preferences.h + OUTPUT_NAME "shared_preferences" +) + +target_compile_definitions(shared_preferences PUBLIC DART_SHARED_LIB) diff --git a/packages/shared_preferences/src/shared_preferences.c b/packages/shared_preferences/src/shared_preferences.c new file mode 100644 index 0000000..ca9b678 --- /dev/null +++ b/packages/shared_preferences/src/shared_preferences.c @@ -0,0 +1,23 @@ +#include "shared_preferences.h" + +// A very short-lived native function. +// +// For very short-lived functions, it is fine to call them on the main isolate. +// They will block the Dart execution while running the native function, so +// only do this for native functions which are guaranteed to be short-lived. +FFI_PLUGIN_EXPORT intptr_t sum(intptr_t a, intptr_t b) { return a + b; } + +// A longer-lived native function, which occupies the thread calling it. +// +// Do not call these kind of native functions in the main isolate. They will +// block Dart execution. This will cause dropped frames in Flutter applications. +// Instead, call these native functions on a separate isolate. +FFI_PLUGIN_EXPORT intptr_t sum_long_running(intptr_t a, intptr_t b) { + // Simulate work. +#if _WIN32 + Sleep(5000); +#else + usleep(5000 * 1000); +#endif + return a + b; +} diff --git a/packages/shared_preferences/src/shared_preferences.h b/packages/shared_preferences/src/shared_preferences.h new file mode 100644 index 0000000..084c642 --- /dev/null +++ b/packages/shared_preferences/src/shared_preferences.h @@ -0,0 +1,30 @@ +#include +#include +#include + +#if _WIN32 +#include +#else +#include +#include +#endif + +#if _WIN32 +#define FFI_PLUGIN_EXPORT __declspec(dllexport) +#else +#define FFI_PLUGIN_EXPORT +#endif + +// A very short-lived native function. +// +// For very short-lived functions, it is fine to call them on the main isolate. +// They will block the Dart execution while running the native function, so +// only do this for native functions which are guaranteed to be short-lived. +FFI_PLUGIN_EXPORT intptr_t sum(intptr_t a, intptr_t b); + +// A longer lived native function, which occupies the thread calling it. +// +// Do not call these kind of native functions in the main isolate. They will +// block Dart execution. This will cause dropped frames in Flutter applications. +// Instead, call these native functions on a separate isolate. +FFI_PLUGIN_EXPORT intptr_t sum_long_running(intptr_t a, intptr_t b); diff --git a/script/build_example.sh b/script/build_example.sh index 3d4a9b0..286104c 100755 --- a/script/build_example.sh +++ b/script/build_example.sh @@ -1,27 +1,31 @@ #!/bin/bash -## Build example, sign rpm, upload rpm to device +## Build example, sign rpm, upload/install/run rpm to device ## Usage +## ## chmod +x ./build_example.sh -## ./build_example.sh -p xdga_directories -u 192.168.1.59:/home/defaultuser/Downloads -k /home/user/sign/system_keys +## +## ./build_example.sh \ +## -p xdga_directories \ +## -d : \ +## -s /home/user/sign/system_keys ## Flatter path FLATTER="$HOME/.local/opt/flutter-sdk/bin/flutter" -## https://community.omprussia.ru/documentation/software_development/psdk/setup.html +## https://developer.auroraos.ru/doc/software_development/psdk/setup ## Install Platform SDK path -## PLATFORM_SDK_ROOT="/srv/mer" ## You may not have set the PSDK_DIR environment variable. -## export PSDK_DIR="$PLATFORM_SDK_ROOT/sdks/sfossdk" +## export PSDK_DIR=$HOME/AuroraPlatformSDK/sdks/aurora_psdk -while getopts p:u:k: flag; do +while getopts p:d:s: flag; do case "${flag}" in p) package=${OPTARG} ;; - u) upload=${OPTARG} ;; - k) keys_folder=${OPTARG} ;; + d) device=${OPTARG} ;; + s) sign=${OPTARG} ;; *) - echo "usage: $0 [-v] [-r]" >&2 + echo "usage: $0 [-p] [-d] [-s]" >&2 exit 1 ;; esac @@ -42,16 +46,16 @@ else $FLATTER build aurora --release fi -if [ -n "$keys_folder" ]; then +if [ -n "$sign" ]; then - key=$(ls "$keys_folder"/*key.pem) + key=$(ls "$sign"/*key.pem) if [ -z "$key" ]; then echo "Key *key.pem not found." exit fi - cert=$(ls "$keys_folder"/*cert.pem) + cert=$(ls "$sign"/*cert.pem) if [ -z "$cert" ]; then echo "Key *cert.pem not found." @@ -65,10 +69,22 @@ if [ -n "$keys_folder" ]; then build/aurora/arm/release/RPMS/*.rpm fi -if [ -n "$upload" ]; then +if [ -n "$device" ]; then + + IFS=':' read -ra ADDR <<< "$device" + + D_IP="${ADDR[0]}" + D_PASS="${ADDR[1]}" # shellcheck disable=SC2012 rpm=$(ls "$PWD"/build/aurora/arm/release/RPMS/*.rpm | sort -r | head -n 1) - scp "$rpm" defaultuser@"$upload" -fi + # upload rpm + scp "$rpm" defaultuser@"$D_IP:/home/defaultuser/Downloads" + + # install rpm + ssh -t defaultuser@$D_IP "echo $D_PASS | devel-su pkcon -y install-local /home/defaultuser/Downloads/*$package*.rpm" + + # run application + ssh -t defaultuser@$D_IP "/usr/bin/com.example.${package}_example" +fi \ No newline at end of file