Browse Source

[xdga_directories] Add PathProviderAuroraPlugin

merge-requests/1/head
Vitaliy Zarubin 2 years ago
parent
commit
fdd9b81b08
  1. 19
      packages/path_provider/path_provider_aurora/aurora/CMakeLists.txt
  2. 24
      packages/path_provider/path_provider_aurora/aurora/include/path_provider_aurora/path_provider_aurora_plugin.h
  3. 44
      packages/path_provider/path_provider_aurora/aurora/path_provider_aurora_plugin.cpp
  4. 3
      packages/path_provider/path_provider_aurora/example/aurora/CMakeLists.txt
  5. 2
      packages/path_provider/path_provider_aurora/example/aurora/flutter/generated_plugin_registrant.cpp
  6. 1
      packages/path_provider/path_provider_aurora/example/aurora/flutter/generated_plugins.cmake
  7. 4
      packages/path_provider/path_provider_aurora/example/aurora/rpm/com.example.path_provider_aurora_example.spec
  8. 33
      packages/path_provider/path_provider_aurora/example/lib/main.dart
  9. 4
      packages/path_provider/path_provider_aurora/example/pubspec.lock
  10. 66
      packages/path_provider/path_provider_aurora/example/pubspec.yaml
  11. 21
      packages/path_provider/path_provider_aurora/lib/path_provider_aurora.dart
  12. 21
      packages/path_provider/path_provider_aurora/lib/path_provider_aurora_method_channel.dart
  13. 33
      packages/path_provider/path_provider_aurora/lib/path_provider_aurora_platform_interface.dart
  14. 3
      packages/path_provider/path_provider_aurora/pubspec.yaml
  15. 58
      packages/path_provider/path_provider_aurora/test/path_provider_aurora_method_channel_test.dart
  16. 57
      packages/path_provider/path_provider_aurora/test/path_provider_aurora_test.dart
  17. 18
      packages/xdga_directories/src/CMakeLists.txt
  18. 5
      script/build_example.sh

19
packages/path_provider/path_provider_aurora/aurora/CMakeLists.txt

@ -1,12 +1,23 @@
cmake_minimum_required(VERSION 3.10)
set(PLUGIN_NAME xdga_directories)
project(${PLUGIN_NAME} LANGUAGES CXX)
set(PROJECT_NAME path_provider_aurora)
set(PLUGIN_NAME path_provider_aurora_platform_plugin)
project(${PROJECT_NAME} LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
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)
find_package(PkgConfig REQUIRED)
pkg_check_modules(FlutterEmbedder REQUIRED IMPORTED_TARGET flutter-embedder)
add_library(${PLUGIN_NAME} SHARED path_provider_aurora_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)

24
packages/path_provider/path_provider_aurora/aurora/include/path_provider_aurora/path_provider_aurora_plugin.h

@ -0,0 +1,24 @@
#ifndef FLUTTER_PLUGIN_PATH_PROVIDER_AURORA_PLUGIN_H
#define FLUTTER_PLUGIN_PATH_PROVIDER_AURORA_PLUGIN_H
#include <flutter/plugin-interface.h>
#ifdef PLUGIN_IMPL
#define PLUGIN_EXPORT __attribute__((visibility("default")))
#else
#define PLUGIN_EXPORT
#endif
class PLUGIN_EXPORT PathProviderAuroraPlugin final : public PluginInterface
{
public:
void RegisterWithRegistrar(PluginRegistrar &registrar) override;
private:
void onMethodCall(const MethodCall &call);
void onGetApplicationOrg(const MethodCall &call);
void onGetApplicationName(const MethodCall &call);
void unimplemented(const MethodCall &call);
};
#endif /* FLUTTER_PLUGIN_PATH_PROVIDER_AURORA_PLUGIN_H */

44
packages/path_provider/path_provider_aurora/aurora/path_provider_aurora_plugin.cpp

@ -0,0 +1,44 @@
#include <path_provider_aurora/path_provider_aurora_plugin.h>
#include <flutter/method-channel.h>
#include <flutter/application.h>
#include <sys/utsname.h>
void PathProviderAuroraPlugin::RegisterWithRegistrar(PluginRegistrar &registrar)
{
registrar.RegisterMethodChannel("path_provider_aurora",
MethodCodecType::Standard,
[this](const MethodCall &call) { this->onMethodCall(call); });
}
void PathProviderAuroraPlugin::onMethodCall(const MethodCall &call)
{
const auto &method = call.GetMethod();
if (method == "getApplicationOrg") {
onGetApplicationOrg(call);
return;
}
else if (method == "getApplicationName") {
onGetApplicationName(call);
return;
}
unimplemented(call);
}
void PathProviderAuroraPlugin::onGetApplicationOrg(const MethodCall &call)
{
const auto [orgname, appname] = Application::GetID();
call.SendSuccessResponse(orgname);
}
void PathProviderAuroraPlugin::onGetApplicationName(const MethodCall &call)
{
const auto [orgname, appname] = Application::GetID();
call.SendSuccessResponse(appname);
}
void PathProviderAuroraPlugin::unimplemented(const MethodCall &call)
{
call.SendSuccessResponse(nullptr);
}

3
packages/path_provider/path_provider_aurora/example/aurora/CMakeLists.txt

@ -16,11 +16,10 @@ set(CMAKE_SKIP_RPATH OFF)
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../share/${BINARY_NAME}/lib")
find_package(PkgConfig REQUIRED)
find_package(Qt5 COMPONENTS Core 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 Qt5::Core)
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::FlutterEmbedder)
target_include_directories(${BINARY_NAME} PRIVATE ${FLUTTER_DIR})
include(flutter/generated_plugins.cmake)

2
packages/path_provider/path_provider_aurora/example/aurora/flutter/generated_plugin_registrant.cpp

@ -5,10 +5,12 @@
// clang-format off
#include <flutter/application.h>
#include <path_provider_aurora/path_provider_aurora_plugin.h>
#include "generated_plugin_registrant.h"
void RegisterPlugins() {
Application::RegisterPlugins({
std::make_shared<PathProviderAuroraPlugin>(),
});
}

1
packages/path_provider/path_provider_aurora/example/aurora/flutter/generated_plugins.cmake

@ -15,6 +15,7 @@ function(add_library TARGET)
endfunction()
list(APPEND FLUTTER_PLATFORM_PLUGIN_LIST
path_provider_aurora
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST

4
packages/path_provider/path_provider_aurora/example/aurora/rpm/com.example.path_provider_aurora_example.spec

@ -1,12 +1,12 @@
%global __provides_exclude_from ^%{_datadir}/%{name}/lib/.*$
%global __requires_exclude ^lib(dconf|flutter-embedder|maliit-glib|.+_platform_plugin)\\.so.*$
%global __requires_exclude ^lib(dconf|flutter-embedder|maliit-glib|appmanifest-.+|.+_platform_plugin)\\.so.*$
Name: com.example.path_provider_aurora_example
Summary: Demonstrates how to use the path_provider_aurora plugin.
Version: 0.1.0
Release: 1
License: Proprietary
Source0: %{name}-%{version}.tar.bz2
Source0: %{name}-%{version}.tar.zst
BuildRequires: cmake
BuildRequires: pkgconfig(flutter-embedder)

33
packages/path_provider/path_provider_aurora/example/lib/main.dart

@ -17,6 +17,8 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
String? _error;
String? _applicationOrg;
String? _applicationName;
String? _pathApplicationSupportDirectory;
String? _pathTempDirectory;
String? _pathApplicationDocumentsPath;
@ -34,6 +36,10 @@ class _MyAppState extends State<MyApp> {
/// Asynchronous function receiving directory paths
Future<void> loadPathDirectory() async {
try {
// Get names
String? applicationOrg = await PathProviderAurora.getApplicationOrg();
String? applicationName = await PathProviderAurora.getApplicationName();
// Get directories
Directory? applicationSupportDirectory = await getApplicationSupportDirectory();
Directory? tempDirectory = await getTemporaryDirectory();
@ -45,6 +51,9 @@ class _MyAppState extends State<MyApp> {
// Update state variable
setState(() {
_applicationOrg = applicationOrg;
_applicationName = applicationName;
_pathApplicationSupportDirectory = applicationSupportDirectory.path;
_pathTempDirectory = tempDirectory.path;
_pathApplicationDocumentsPath = pathApplicationDocumentsPath.path;
@ -120,6 +129,30 @@ class _MyAppState extends State<MyApp> {
),
const SizedBox(height: 30),
// ApplicationOrg
const Text(
'Application Org',
style: textStyleTitle,
),
spaceSmall,
Text(
_applicationOrg ?? 'Not found.',
style: textStylePath,
),
spaceMedium,
// ApplicationName
const Text(
'Application Name',
style: textStyleTitle,
),
spaceSmall,
Text(
_applicationName ?? 'Not found.',
style: textStylePath,
),
spaceMedium,
// TempDirectory
const Text(
'ApplicationSupportDirectory',

4
packages/path_provider/path_provider_aurora/example/pubspec.lock

@ -129,7 +129,7 @@ packages:
name: path_provider_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.24"
version: "2.0.26"
path_provider_aurora:
dependency: "direct main"
description:
@ -258,7 +258,7 @@ packages:
dependency: transitive
description:
path: "../../../xdga_directories"
relative: true
relative: false
source: path
version: "0.0.1"
sdks:

66
packages/path_provider/path_provider_aurora/example/pubspec.yaml

@ -1,23 +1,85 @@
name: path_provider_aurora_example
description: Demonstrates how to use the path_provider_aurora plugin.
publish_to: 'none'
# 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
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
path_provider: ^2.0.7
path_provider_aurora:
# When depending on this package from a real application you should use:
# path_provider_aurora: ^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:
uses-material-design: true
# 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

21
packages/path_provider/path_provider_aurora/lib/path_provider_aurora.dart

@ -1,5 +1,8 @@
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
import 'package:xdga_directories/xdga_directories.dart' as xdga_directories;
import 'package:path/path.dart' as p;
import 'path_provider_aurora_platform_interface.dart';
/// The aurora implementation of [PathProviderPlatform]
///
@ -10,19 +13,33 @@ class PathProviderAurora extends PathProviderPlatform {
PathProviderPlatform.instance = PathProviderAurora();
}
/// Get application name
static Future<String?> getApplicationName() {
return PathProviderAuroraPlatform.instance.getApplicationName();
}
/// Get application org
static Future<String?> getApplicationOrg() {
return PathProviderAuroraPlatform.instance.getApplicationOrg();
}
/// Path to a directory where the application may place application support files.
@override
Future<String?> getApplicationSupportPath() async {
String? org = await getApplicationOrg();
String? name = await getApplicationName();
// QStandardPaths::AppDataLocation
return xdga_directories.getAppDataLocation();
return p.join(xdga_directories.getAppDataLocation(), org, name);
}
/// Path to the temporary directory on the device that is not backed up and is
/// suitable for storing caches of downloaded files.
@override
Future<String> getTemporaryPath() async {
String? org = await getApplicationOrg();
String? name = await getApplicationName();
// QStandardPaths::CacheLocation
return xdga_directories.getCacheLocation();
return p.join(xdga_directories.getCacheLocation(), org, name);
}
/// Path to a directory where the application may place data that is

21
packages/path_provider/path_provider_aurora/lib/path_provider_aurora_method_channel.dart

@ -0,0 +1,21 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'path_provider_aurora_platform_interface.dart';
/// An implementation of [PathProviderAuroraPlatform] that uses method channels.
class MethodChannelPathProviderAurora extends PathProviderAuroraPlatform {
/// The method channel used to interact with the native platform.
@visibleForTesting
final methodChannel = const MethodChannel('path_provider_aurora');
@override
Future<String?> getApplicationOrg() async {
return await methodChannel.invokeMethod<String>('getApplicationOrg');
}
@override
Future<String?> getApplicationName() async {
return await methodChannel.invokeMethod<String>('getApplicationName');
}
}

33
packages/path_provider/path_provider_aurora/lib/path_provider_aurora_platform_interface.dart

@ -0,0 +1,33 @@
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'path_provider_aurora_method_channel.dart';
abstract class PathProviderAuroraPlatform extends PlatformInterface {
/// Constructs a PathProviderAuroraPlatform.
PathProviderAuroraPlatform() : super(token: _token);
static final Object _token = Object();
static PathProviderAuroraPlatform _instance = MethodChannelPathProviderAurora();
/// The default instance of [PathProviderAuroraPlatform] to use.
///
/// Defaults to [MethodChannelPathProviderAurora].
static PathProviderAuroraPlatform get instance => _instance;
/// Platform-specific implementations should set this with their own
/// platform-specific class that extends [PathProviderAuroraPlatform] when
/// they register themselves.
static set instance(PathProviderAuroraPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}
Future<String?> getApplicationOrg() {
throw UnimplementedError('getApplicationOrg() has not been implemented.');
}
Future<String?> getApplicationName() {
throw UnimplementedError('getApplicationName() has not been implemented.');
}
}

3
packages/path_provider/path_provider_aurora/pubspec.yaml

@ -13,10 +13,13 @@ flutter:
platforms:
aurora:
dartPluginClass: PathProviderAurora
pluginClass: PathProviderAuroraPlugin
dependencies:
flutter:
sdk: flutter
path: ^1.8.2
plugin_platform_interface: ^2.0.2
path_provider_platform_interface: ^2.0.6
## @todo
## Publishable packages can't have 'git' dependencies

58
packages/path_provider/path_provider_aurora/test/path_provider_aurora_method_channel_test.dart

@ -1,24 +1,34 @@
// import 'package:flutter/services.dart';
// import 'package:flutter_test/flutter_test.dart';
// import 'package:path_provider_aurora/path_provider_aurora_method_channel.dart';
//
// void main() {
// MethodChannelPathProviderAurora platform = MethodChannelPathProviderAurora();
// const MethodChannel channel = MethodChannel('path_provider_aurora');
//
// TestWidgetsFlutterBinding.ensureInitialized();
//
// setUp(() {
// channel.setMockMethodCallHandler((MethodCall methodCall) async {
// return '42';
// });
// });
//
// tearDown(() {
// channel.setMockMethodCallHandler(null);
// });
//
// test('getPlatformVersion', () async {
// expect(await platform.getPlatformVersion(), '42');
// });
// }
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:path_provider_aurora/path_provider_aurora_method_channel.dart';
void main() {
MethodChannelPathProviderAurora platform = MethodChannelPathProviderAurora();
const MethodChannel channel = MethodChannel('path_provider_aurora');
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
switch (methodCall.method) {
case 'getApplicationOrg':
return 'com.example';
case 'getApplicationName':
return 'path_provider_aurora';
}
return '';
});
});
tearDown(() {
channel.setMockMethodCallHandler(null);
});
test('onGetApplicationOrg', () async {
expect(await platform.getApplicationOrg(), 'com.example');
});
test('onGetApplicationName', () async {
expect(await platform.getApplicationName(), 'path_provider_aurora');
});
}

57
packages/path_provider/path_provider_aurora/test/path_provider_aurora_test.dart

@ -1,21 +1,36 @@
// import 'package:flutter_test/flutter_test.dart';
// import 'package:path_provider_aurora/path_provider_aurora.dart';
// import 'package:path_provider_aurora/path_provider_aurora_platform_interface.dart';
// import 'package:path_provider_aurora/path_provider_aurora_method_channel.dart';
// import 'package:plugin_platform_interface/plugin_platform_interface.dart';
//
// class MockPathProviderAuroraPlatform
// with MockPlatformInterfaceMixin
// implements PathProviderAuroraPlatform {
//
// @override
// Future<String?> getPlatformVersion() => Future.value('42');
// }
//
// void main() {
// final PathProviderAuroraPlatform initialPlatform = PathProviderAuroraPlatform.instance;
//
// test('$MethodChannelPathProviderAurora is the default instance', () {
// expect(initialPlatform, isInstanceOf<MethodChannelPathProviderAurora>());
// });
// }
import 'package:flutter_test/flutter_test.dart';
import 'package:path_provider_aurora/path_provider_aurora.dart';
import 'package:path_provider_aurora/path_provider_aurora_platform_interface.dart';
import 'package:path_provider_aurora/path_provider_aurora_method_channel.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
class MockPathProviderAuroraPlatform
with MockPlatformInterfaceMixin
implements PathProviderAuroraPlatform {
@override
Future<String?> getApplicationName() {
return Future.value('path_provider_aurora');
}
@override
Future<String?> getApplicationOrg() {
return Future.value('com.example');
}
}
void main() {
final PathProviderAuroraPlatform initialPlatform = PathProviderAuroraPlatform.instance;
test('$MethodChannelPathProviderAurora is the default instance', () {
expect(initialPlatform, isInstanceOf<MethodChannelPathProviderAurora>());
});
test('getDownloadsPath', () async {
PathProviderAurora pathProviderAuroraPlugin = PathProviderAurora();
MockPathProviderAuroraPlatform fakePlatform = MockPathProviderAuroraPlatform();
PathProviderAuroraPlatform.instance = fakePlatform;
expect(await pathProviderAuroraPlugin.getDownloadsPath(), '/home/defaulter/Downloads');
});
}

18
packages/xdga_directories/src/CMakeLists.txt

@ -1,15 +1,21 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.10)
project(xdga_directories VERSION 0.0.1)
find_package(Qt5 COMPONENTS Core REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(Qt5Core REQUIRED IMPORTED_TARGET Qt5Core)
add_library(xdga_directories SHARED xdga_directories.cpp)
add_library(xdga_directories SHARED
"xdga_directories.cpp"
)
target_link_libraries(xdga_directories Qt5::Core)
target_link_libraries(xdga_directories PRIVATE PkgConfig::Qt5Core)
set_target_properties(xdga_directories PROPERTIES
PUBLIC_HEADER xdga_directories.h
PUBLIC_HEADER "xdga_directories.h"
OUTPUT_NAME "xdga_directories"
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Hex_Identity_ID_Goes_Here"
)
target_compile_definitions(xdga_directories PUBLIC DART_SHARED_LIB)

5
script/build_example.sh

@ -32,8 +32,13 @@ if [ -z "$package" ]; then
exit
else
cd "../packages/$package" 2>/dev/null || eval 'echo "Package \"$package\" not found." && exit'
## Update dependency
$FLATTER pub get
## Run ffigen if has
$FLATTER pub run ffigen --config ffigen.yaml 2>/dev/null
## Open example dir
cd "example" || exit
## Build aurora example app
$FLATTER build aurora --release
fi

Loading…
Cancel
Save