Browse Source

[path_provider] Add package_info_plus

merge-requests/9/head
Vitaliy Zarubin 2 years ago
parent
commit
26ea231a77
  1. 5
      packages/path_provider/path_provider_aurora/README.md
  2. 26
      packages/path_provider/path_provider_aurora/aurora/CMakeLists.txt
  3. 28
      packages/path_provider/path_provider_aurora/aurora/include/path_provider_aurora/path_provider_aurora_plugin.h
  4. 47
      packages/path_provider/path_provider_aurora/aurora/path_provider_aurora_plugin.cpp
  5. 51
      packages/path_provider/path_provider_aurora/example/lib/main.dart
  6. 324
      packages/path_provider/path_provider_aurora/example/pubspec.lock
  7. 50
      packages/path_provider/path_provider_aurora/lib/path_provider_aurora.dart
  8. 25
      packages/path_provider/path_provider_aurora/lib/path_provider_aurora_method_channel.dart
  9. 37
      packages/path_provider/path_provider_aurora/lib/path_provider_aurora_platform_interface.dart
  10. 9
      packages/path_provider/path_provider_aurora/pubspec.yaml
  11. 38
      packages/path_provider/path_provider_aurora/test/path_provider_aurora_method_channel_test.dart

5
packages/path_provider/path_provider_aurora/README.md

@ -38,8 +38,3 @@ final Directory? downloadsDir = await getDownloadsDirectory();
- [ ] `getExternalCacheDirectories`
- [x] `getExternalStorageDirectories` (There is no concept of External in Aurora OS, but this interface allows you to get the pictures/music/movies directory)
- [x] `getDownloadsDirectory`
## Extra methods
PathProviderAurora.getApplicationOrg();
PathProviderAurora.getApplicationName();

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

@ -1,26 +0,0 @@
# Copyright (c) 2023. Open Mobile Platform LLC.
# License: Proprietary.
cmake_minimum_required(VERSION 3.10)
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 -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 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)

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

@ -1,28 +0,0 @@
/*
* Copyright (c) 2023. Open Mobile Platform LLC.
* License: Proprietary.
*/
#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 */

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

@ -1,47 +0,0 @@
/*
* Copyright (c) 2023. Open Mobile Platform LLC.
* License: Proprietary.
*/
#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;
}
if (method == "getApplicationName") {
onGetApplicationName(call);
return;
}
unimplemented(call);
}
void PathProviderAuroraPlugin::onGetApplicationOrg(const MethodCall &call)
{
call.SendSuccessResponse(Application::GetID().orgname);
}
void PathProviderAuroraPlugin::onGetApplicationName(const MethodCall &call)
{
call.SendSuccessResponse(Application::GetID().appname);
}
void PathProviderAuroraPlugin::unimplemented(const MethodCall &call)
{
call.SendSuccessResponse(nullptr);
}

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

@ -21,8 +21,6 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
String? _error;
String? _applicationOrg;
String? _applicationName;
String? _pathApplicationSupportDirectory;
String? _pathTempDirectory;
String? _pathApplicationDocumentsPath;
@ -40,24 +38,22 @@ 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? applicationSupportDirectory =
await getApplicationSupportDirectory();
Directory? tempDirectory = await getTemporaryDirectory();
Directory? pathApplicationDocumentsPath = await getApplicationDocumentsDirectory();
Directory? pathApplicationDocumentsPath =
await getApplicationDocumentsDirectory();
Directory? pathDownloadsPath = await getDownloadsDirectory();
List<Directory>? pathPictures = await getExternalStorageDirectories(type: StorageDirectory.pictures);
List<Directory>? pathMusic = await getExternalStorageDirectories(type: StorageDirectory.music);
List<Directory>? pathMovies = await getExternalStorageDirectories(type: StorageDirectory.movies);
List<Directory>? pathPictures =
await getExternalStorageDirectories(type: StorageDirectory.pictures);
List<Directory>? pathMusic =
await getExternalStorageDirectories(type: StorageDirectory.music);
List<Directory>? pathMovies =
await getExternalStorageDirectories(type: StorageDirectory.movies);
// Update state variable
setState(() {
_applicationOrg = applicationOrg;
_applicationName = applicationName;
_pathApplicationSupportDirectory = applicationSupportDirectory.path;
_pathTempDirectory = tempDirectory.path;
_pathApplicationDocumentsPath = pathApplicationDocumentsPath.path;
@ -123,7 +119,8 @@ class _MyAppState extends State<MyApp> {
padding: const EdgeInsets.all(20),
decoration: const BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.all(Radius.circular(10.0)),
borderRadius:
BorderRadius.all(Radius.circular(10.0)),
),
child: const Text(
'Demo application demonstration implementation of path_provider',
@ -133,30 +130,6 @@ 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',

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

@ -0,0 +1,324 @@
# 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"
ffi:
dependency: transitive
description:
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
file:
dependency: transitive
description:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.4"
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"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
http:
dependency: transitive
description:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.5"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.2"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.4"
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"
package_info_plus:
dependency: transitive
description:
name: package_info_plus
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
package_info_plus_aurora:
dependency: transitive
description:
path: "packages/package_info_plus/package_info_plus_aurora"
ref: dev
resolved-ref: "47dd76ca473269566811d8c48fbfd22f1d8120f9"
url: "git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git"
source: git
version: "0.0.1"
package_info_plus_platform_interface:
dependency: transitive
description:
name: package_info_plus_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
path_provider:
dependency: "direct main"
description:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.15"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.27"
path_provider_aurora:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "0.0.1"
path_provider_foundation:
dependency: transitive
description:
name: path_provider_foundation
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.3"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.11"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.6"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.7"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
process:
dependency: transitive
description:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.4"
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"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.2"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
win32:
dependency: transitive
description:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.4"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
xdga_directories:
dependency: transitive
description:
path: "packages/xdga_directories"
ref: dev
resolved-ref: "47dd76ca473269566811d8c48fbfd22f1d8120f9"
url: "git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git"
source: git
version: "0.0.1"
sdks:
dart: ">=2.18.6 <3.0.0"
flutter: ">=3.3.0"

50
packages/path_provider/path_provider_aurora/lib/path_provider_aurora.dart

@ -2,48 +2,48 @@
* Copyright (c) 2023. Open Mobile Platform LLC.
* License: Proprietary.
*/
import 'package:package_info_plus_aurora/package_info_plus_aurora.dart';
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
import 'package:xdga_directories/xdga_directories.dart' as xdga_directories;
import 'package:package_info_plus/package_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:path/path.dart' as p;
import 'path_provider_aurora_platform_interface.dart';
/// The aurora implementation of [PathProviderPlatform]
///
/// This class implements the `package:path_provider` functionality for Aurora.
class PathProviderAurora extends PathProviderPlatform {
/// Registers this class as the default instance of [PathProviderPlatform]
static void registerWith() {
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();
if (TargetPlatform.aurora == defaultTargetPlatform) {
PackageInfoPlusAurora.registerWith();
PathProviderPlatform.instance = PathProviderAurora();
}
}
/// 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();
PackageInfo info = await PackageInfo.fromPlatform();
// QStandardPaths::AppDataLocation
return p.join(xdga_directories.getAppDataLocation(), org, name);
return p.join(
xdga_directories.getAppDataLocation(),
info.packageName,
info.appName,
);
}
/// 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();
PackageInfo info = await PackageInfo.fromPlatform();
// QStandardPaths::CacheLocation
return p.join(xdga_directories.getCacheLocation(), org, name);
return p.join(
xdga_directories.getCacheLocation(),
info.packageName,
info.appName,
);
}
/// Path to a directory where the application may place data that is
@ -73,11 +73,17 @@ class PathProviderAurora extends PathProviderPlatform {
}) async {
switch (type) {
case StorageDirectory.pictures:
return [xdga_directories.getPicturesLocation()]; // QStandardPaths::PicturesLocation
return [
xdga_directories.getPicturesLocation()
]; // QStandardPaths::PicturesLocation
case StorageDirectory.music:
return [xdga_directories.getMusicLocation()]; // QStandardPaths::MusicLocation
return [
xdga_directories.getMusicLocation()
]; // QStandardPaths::MusicLocation
case StorageDirectory.movies:
return [xdga_directories.getMoviesLocation()]; // QStandardPaths::MoviesLocation
return [
xdga_directories.getMoviesLocation()
]; // QStandardPaths::MoviesLocation
default:
throw UnimplementedError('Type "$type" not supported.');
}

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

@ -1,25 +0,0 @@
/*
* Copyright (c) 2023. Open Mobile Platform LLC.
* License: Proprietary.
*/
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');
}
}

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

@ -1,37 +0,0 @@
/*
* Copyright (c) 2023. Open Mobile Platform LLC.
* License: Proprietary.
*/
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.');
}
}

9
packages/path_provider/path_provider_aurora/pubspec.yaml

@ -20,8 +20,12 @@ dependencies:
url: git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git
ref: dev
path: packages/xdga_directories
# xdga_directories:
# path: ../../xdga_directories
package_info_plus: 4.0.0
package_info_plus_aurora:
git:
url: git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git
ref: dev
path: packages/package_info_plus/package_info_plus_aurora
dev_dependencies:
flutter_test:
@ -34,4 +38,3 @@ flutter:
platforms:
aurora:
dartPluginClass: PathProviderAurora
pluginClass: PathProviderAuroraPlugin

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

@ -1,38 +0,0 @@
/*
* Copyright (c) 2023. Open Mobile Platform LLC.
* License: Proprietary.
*/
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');
});
}
Loading…
Cancel
Save