diff --git a/packages/path_provider/path_provider_aurora/README.md b/packages/path_provider/path_provider_aurora/README.md index b83d936..d51d7ef 100644 --- a/packages/path_provider/path_provider_aurora/README.md +++ b/packages/path_provider/path_provider_aurora/README.md @@ -24,8 +24,8 @@ import 'package:path_provider/path_provider.dart'; - [x] `getTemporaryDirectory` - [ ] `getApplicationSupportDirectory` - [ ] `getLibraryDirectory` -- [ ] `getApplicationDocumentsDirectory` +- [x] `getApplicationDocumentsDirectory` - [ ] `getExternalStorageDirectory` - [ ] `getExternalCacheDirectories` -- [ ] `getExternalStorageDirectories` -- [ ] `getDownloadsDirectory` \ No newline at end of file +- [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` \ No newline at end of file diff --git a/packages/path_provider/path_provider_aurora/example/lib/main.dart b/packages/path_provider/path_provider_aurora/example/lib/main.dart index 286f7f1..cdb1bf2 100644 --- a/packages/path_provider/path_provider_aurora/example/lib/main.dart +++ b/packages/path_provider/path_provider_aurora/example/lib/main.dart @@ -16,57 +16,204 @@ class MyApp extends StatefulWidget { } class _MyAppState extends State { - Future? _tempDirectory; + String? _error; + String? _pathApplicationSupportDirectory; + String? _pathTempDirectory; + String? _pathApplicationDocumentsPath; + String? _pathDownloadsPath; + String? _pathPictures; + String? _pathMusic; + String? _pathMovies; @override void initState() { super.initState(); // @todo it's work - // PathProviderAurora.registerWith(); + PathProviderAurora.registerWith(); + // Get directories from path_provider + loadPathDirectory(); } - void _requestTempDirectory() { - setState(() { - _tempDirectory = getTemporaryDirectory(); - }); - } + /// Asynchronous function receiving directory paths + Future loadPathDirectory() async { + try { + // Get directories + Directory? applicationSupportDirectory = await getApplicationSupportDirectory(); + Directory? tempDirectory = await getTemporaryDirectory(); + Directory? pathApplicationDocumentsPath = await getApplicationDocumentsDirectory(); + Directory? pathDownloadsPath = await getDownloadsDirectory(); + List? pathPictures = await getExternalStorageDirectories(type: StorageDirectory.pictures); + List? pathMusic = await getExternalStorageDirectories(type: StorageDirectory.music); + List? pathMovies = await getExternalStorageDirectories(type: StorageDirectory.movies); - Widget _buildDirectory( - BuildContext context, AsyncSnapshot snapshot) { - Text text = const Text(''); - if (snapshot.connectionState == ConnectionState.done) { - if (snapshot.hasError) { - text = Text('Error: ${snapshot.error}'); - } else if (snapshot.hasData) { - text = Text('path: ${snapshot.data!.path}'); - } else { - text = const Text('path unavailable'); - } + // Update state variable + setState(() { + _pathApplicationSupportDirectory = applicationSupportDirectory.path; + _pathTempDirectory = tempDirectory.path; + _pathApplicationDocumentsPath = pathApplicationDocumentsPath.path; + _pathDownloadsPath = pathDownloadsPath?.path; + _pathPictures = pathPictures?.first.path; + _pathMusic = pathMusic?.first.path; + _pathMovies = pathMovies?.first.path; + }); + } on Exception catch (e) { + setState(() { + _error = e.toString(); + }); } - return Padding(padding: const EdgeInsets.all(16.0), child: text); } @override Widget build(BuildContext context) { + const textStyleWhite = TextStyle(fontSize: 18, color: Colors.white); + const textStyleTitle = TextStyle(fontSize: 20, color: Colors.black); + const textStylePath = TextStyle(fontSize: 18, color: Colors.black54); + + const spaceMedium = SizedBox(height: 20); + const spaceSmall = SizedBox(height: 10); + return MaterialApp( home: Scaffold( - appBar: AppBar( - title: const Text('Plugin example app'), - ), - body: Column( - children: [ - FutureBuilder( - future: _tempDirectory, - builder: _buildDirectory, + appBar: AppBar( + title: const Text('Example path_provider'), + ), + body: Stack( + children: [ + // Error message + Visibility( + visible: _error != null, + child: Center( + child: Padding( + padding: const EdgeInsets.all(16), + child: Container( + padding: const EdgeInsets.all(20), + decoration: const BoxDecoration( + color: Colors.redAccent, + borderRadius: BorderRadius.all(Radius.circular(10.0)), + ), + child: Text( + _error ?? '', + style: textStyleWhite, + ), + ), + ), ), - ElevatedButton( - onPressed: _requestTempDirectory, - child: const Text( - 'Get Temporary Directory', + ), + // List directories path + Visibility( + visible: _error == null, + child: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(16), + child: Center( + child: Column( + children: [ + // Info + Container( + padding: const EdgeInsets.all(20), + decoration: const BoxDecoration( + color: Colors.green, + borderRadius: BorderRadius.all(Radius.circular(10.0)), + ), + child: const Text( + 'Demo application demonstration implementation of path_provider', + style: textStyleWhite, + textAlign: TextAlign.center, + ), + ), + const SizedBox(height: 30), + + // TempDirectory + const Text( + 'ApplicationSupportDirectory', + style: textStyleTitle, + ), + spaceSmall, + Text( + _pathApplicationSupportDirectory ?? 'Not found.', + style: textStylePath, + ), + + spaceMedium, + // TempDirectory + const Text( + 'TempDirectory', + style: textStyleTitle, + ), + spaceSmall, + Text( + _pathTempDirectory ?? 'Not found.', + style: textStylePath, + ), + spaceMedium, + + // ApplicationDocumentsPath + const Text( + 'ApplicationDocumentsPath', + style: textStyleTitle, + ), + spaceSmall, + Text( + _pathApplicationDocumentsPath ?? 'Not found.', + style: textStylePath, + ), + spaceMedium, + + // DownloadsPath + const Text( + 'DownloadsPath', + style: textStyleTitle, + ), + spaceSmall, + Text( + _pathDownloadsPath ?? 'Not found.', + style: textStylePath, + ), + spaceMedium, + + // Pictures + const Text( + 'Pictures', + style: textStyleTitle, + ), + spaceSmall, + Text( + _pathPictures ?? 'Not found.', + style: textStylePath, + ), + spaceMedium, + + // Music + const Text( + 'Music', + style: textStyleTitle, + ), + spaceSmall, + Text( + _pathMusic ?? 'Not found.', + style: textStylePath, + ), + spaceMedium, + + // Movies + const Text( + 'Movies', + style: textStyleTitle, + ), + spaceSmall, + Text( + _pathMovies ?? 'Not found.', + style: textStylePath, + ), + ], + ), + ), ), ), - ], - )), + ), + ], + ), + ), ); } } diff --git a/packages/path_provider/path_provider_aurora/example/pubspec.lock b/packages/path_provider/path_provider_aurora/example/pubspec.lock index d8bab81..ec74c3b 100644 --- a/packages/path_provider/path_provider_aurora/example/pubspec.lock +++ b/packages/path_provider/path_provider_aurora/example/pubspec.lock @@ -257,11 +257,9 @@ packages: xdga_directories: dependency: transitive description: - path: "packages/xdga_directories" - ref: xdga_directories - resolved-ref: fb19ee472cac234c924a2f222ecc66a03a808ce2 - url: "git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git" - source: git + path: "../../../xdga_directories" + relative: true + source: path version: "0.0.1" sdks: dart: ">=2.18.6 <3.0.0" diff --git a/packages/path_provider/path_provider_aurora/lib/path_provider_aurora.dart b/packages/path_provider/path_provider_aurora/lib/path_provider_aurora.dart index d50b760..d1f41be 100644 --- a/packages/path_provider/path_provider_aurora/lib/path_provider_aurora.dart +++ b/packages/path_provider/path_provider_aurora/lib/path_provider_aurora.dart @@ -11,7 +11,54 @@ class PathProviderAurora extends PathProviderPlatform { PathProviderPlatform.instance = PathProviderAurora(); } + /// Path to a directory where the application may place application support files. @override - Future getTemporaryPath() async => - xdga_directories.getCacheLocation(); -} \ No newline at end of file + Future getApplicationSupportPath() async { + return xdga_directories.getAppDataLocation(); + } + + /// Path to the temporary directory on the device that is not backed up and is + /// suitable for storing caches of downloaded files. + @override + Future getTemporaryPath() async { + // QStandardPaths::CacheLocation + return xdga_directories.getCacheLocation(); + } + + /// Path to a directory where the application may place data that is + /// user-generated, or that cannot otherwise be recreated by your application. + @override + Future getApplicationDocumentsPath() async { + // QStandardPaths::DocumentsLocation + return xdga_directories.getDocumentsLocation(); + } + + /// Path to the directory where downloaded files can be stored. + /// This is typically only relevant on desktop operating systems. + @override + Future getDownloadsPath() async { + // QStandardPaths::DownloadLocation + return xdga_directories.getDownloadLocation(); + } + + /// Paths to directories where application specific data can be stored. + /// These paths typically reside on external storage like separate partitions + /// or SD cards. Phones may have multiple storage directories available. + @override + Future?> getExternalStoragePaths({ + /// Optional parameter. See [StorageDirectory] for more informations on + /// how this type translates to Android storage directories. + StorageDirectory? type, + }) async { + switch (type) { + case StorageDirectory.pictures: + return [xdga_directories.getPicturesLocation()]; // QStandardPaths::PicturesLocation + case StorageDirectory.music: + return [xdga_directories.getMusicLocation()]; // QStandardPaths::MusicLocation + case StorageDirectory.movies: + return [xdga_directories.getMoviesLocation()]; // QStandardPaths::MoviesLocation + default: + throw UnimplementedError('Type "$type" not supported.'); + } + } +} diff --git a/packages/path_provider/path_provider_aurora/pubspec.yaml b/packages/path_provider/path_provider_aurora/pubspec.yaml index 986d08c..cd66bb6 100644 --- a/packages/path_provider/path_provider_aurora/pubspec.yaml +++ b/packages/path_provider/path_provider_aurora/pubspec.yaml @@ -18,13 +18,17 @@ dependencies: flutter: sdk: flutter path_provider_platform_interface: ^2.0.6 + ## @todo + ## Publishable packages can't have 'git' dependencies xdga_directories: - ## @todo - ## Publishable packages can't have 'git' dependencies - git: - url: git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git - ref: xdga_directories - path: packages/xdga_directories + ## from folder + path: ../../xdga_directories + ## from git +# xdga_directories: +# git: +# url: git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git +# ref: xdga_directories +# path: packages/xdga_directories dev_dependencies: flutter_test: diff --git a/packages/xdga_directories/example/lib/main.dart b/packages/xdga_directories/example/lib/main.dart index e2e20db..d7e80bf 100644 --- a/packages/xdga_directories/example/lib/main.dart +++ b/packages/xdga_directories/example/lib/main.dart @@ -13,6 +13,7 @@ class MyApp extends StatefulWidget { } class _MyAppState extends State { + late String appDataLocation; late String cacheLocation; late String documentsLocation; late String downloadLocation; @@ -24,6 +25,8 @@ class _MyAppState extends State { @override void initState() { super.initState(); + // Get paths + appDataLocation = xdga_directories.getAppDataLocation(); cacheLocation = xdga_directories.getCacheLocation(); documentsLocation = xdga_directories.getDocumentsLocation(); downloadLocation = xdga_directories.getDownloadLocation(); @@ -35,120 +38,135 @@ class _MyAppState extends State { @override Widget build(BuildContext context) { - const textStyleNormal = TextStyle(fontSize: 20); - final textStyleSmall = const TextStyle(fontSize: 18).copyWith(color: Colors.black54); + const textStyleWhite = TextStyle(fontSize: 18, color: Colors.white); + const textStyleTitle = TextStyle(fontSize: 20, color: Colors.black); + const textStylePath = TextStyle(fontSize: 18, color: Colors.black54); - const spacerNormal = SizedBox(height: 16); + const spaceMedium = SizedBox(height: 16); const spacerSmall = SizedBox(height: 8); return MaterialApp( home: Scaffold( appBar: AppBar( - title: const Text('Directories Example'), + title: const Text('Example XDGA'), ), body: SingleChildScrollView( - child: Container( - padding: const EdgeInsets.all(10), - child: Column( - children: [ - Container( - decoration: const BoxDecoration( + child: Center( + child: Container( + padding: const EdgeInsets.all(10), + child: Column( + children: [ + Container( + decoration: const BoxDecoration( color: Colors.green, - borderRadius: BorderRadius.all(Radius.circular(10.0))), - child: Padding( - padding: const EdgeInsets.all(20), - child: Text( - 'A Dart package for reading directory path on Aurora OS.', - style: textStyleNormal.copyWith(color: Colors.white), - textAlign: TextAlign.center, + borderRadius: BorderRadius.all(Radius.circular(10.0)), ), + child: const Padding( + padding: EdgeInsets.all(20), + child: Text( + 'A Dart package for reading directory path on Aurora OS.', + style: textStyleWhite, + ), + ), + ), + const SizedBox(height: 30), + + // getAppDataLocation + const Text( + 'getAppDataLocation()', + style: textStyleTitle, + ), + spacerSmall, + Text( + appDataLocation, + style: textStylePath, + ), + spaceMedium, + + // getCacheLocation + const Text( + 'getCacheLocation()', + style: textStyleTitle, + ), + spacerSmall, + Text( + cacheLocation, + style: textStylePath, + ), + spaceMedium, + + // getDocumentsLocation + const Text( + 'getDocumentsLocation()', + style: textStyleTitle, + ), + spacerSmall, + Text( + documentsLocation, + style: textStylePath, + ), + spaceMedium, + + // getDocumentsLocation + const Text( + 'getDownloadLocation()', + style: textStyleTitle, + ), + spacerSmall, + Text( + downloadLocation, + style: textStylePath, + ), + spaceMedium, + + // getDocumentsLocation + const Text( + 'getMusicLocation()', + style: textStyleTitle, + ), + spacerSmall, + Text( + musicLocation, + style: textStylePath, + ), + spaceMedium, + + // getDocumentsLocation + const Text( + 'getPicturesLocation()', + style: textStyleTitle, + ), + spacerSmall, + Text( + picturesLocation, + style: textStylePath, + ), + spaceMedium, + + // getDocumentsLocation + const Text( + 'getGenericDataLocation()', + style: textStyleTitle, + ), + spacerSmall, + Text( + genericDataLocation, + style: textStylePath, + ), + spaceMedium, + + // getDocumentsLocation + const Text( + 'getMoviesLocation()', + style: textStyleTitle, + ), + spacerSmall, + Text( + moviesLocation, + style: textStylePath, ), - ), - const SizedBox(height: 30), - const Text( - 'getCacheLocation()', - style: textStyleNormal, - textAlign: TextAlign.center, - ), - spacerSmall, - Text( - cacheLocation, - style: textStyleSmall, - textAlign: TextAlign.center, - ), - spacerNormal, - const Text( - 'getDocumentsLocation()', - style: textStyleNormal, - textAlign: TextAlign.center, - ), - spacerSmall, - Text( - documentsLocation, - style: textStyleSmall, - textAlign: TextAlign.center, - ), - spacerNormal, - const Text( - 'getDownloadLocation()', - style: textStyleNormal, - textAlign: TextAlign.center, - ), - spacerSmall, - Text( - downloadLocation, - style: textStyleSmall, - textAlign: TextAlign.center, - ), - spacerNormal, - const Text( - 'getMusicLocation()', - style: textStyleNormal, - textAlign: TextAlign.center, - ), - spacerSmall, - Text( - musicLocation, - style: textStyleSmall, - textAlign: TextAlign.center, - ), - spacerNormal, - const Text( - 'getPicturesLocation()', - style: textStyleNormal, - textAlign: TextAlign.center, - ), - spacerSmall, - Text( - picturesLocation, - style: textStyleSmall, - textAlign: TextAlign.center, - ), - spacerNormal, - const Text( - 'getGenericDataLocation()', - style: textStyleNormal, - textAlign: TextAlign.center, - ), - spacerSmall, - Text( - genericDataLocation, - style: textStyleSmall, - textAlign: TextAlign.center, - ), - spacerNormal, - const Text( - 'getMoviesLocation()', - style: textStyleNormal, - textAlign: TextAlign.center, - ), - spacerSmall, - Text( - moviesLocation, - style: textStyleSmall, - textAlign: TextAlign.center, - ), - ], + ], + ), ), ), ), diff --git a/packages/xdga_directories/lib/xdga_directories.dart b/packages/xdga_directories/lib/xdga_directories.dart index 7533176..0b77018 100644 --- a/packages/xdga_directories/lib/xdga_directories.dart +++ b/packages/xdga_directories/lib/xdga_directories.dart @@ -17,6 +17,9 @@ final XdgaDirectoriesBindings _bindings = XdgaDirectoriesBindings(_dylib); /// QStandardPaths::CacheLocation String getCacheLocation() => _bindings.getCacheLocation().cast().toDartString(); +/// QStandardPaths::AppDataLocation +String getAppDataLocation() => _bindings.getAppDataLocation().cast().toDartString(); + /// QStandardPaths::DocumentsLocation String getDocumentsLocation() => _bindings.getDocumentsLocation().cast().toDartString(); diff --git a/packages/xdga_directories/lib/xdga_directories_bindings_generated.dart b/packages/xdga_directories/lib/xdga_directories_bindings_generated.dart index 0350b39..c48bdb0 100644 --- a/packages/xdga_directories/lib/xdga_directories_bindings_generated.dart +++ b/packages/xdga_directories/lib/xdga_directories_bindings_generated.dart @@ -32,6 +32,16 @@ class XdgaDirectoriesBindings { late final _getCacheLocation = _getCacheLocationPtr.asFunction Function()>(); + ffi.Pointer getAppDataLocation() { + return _getAppDataLocation(); + } + + late final _getAppDataLocationPtr = + _lookup Function()>>( + 'getAppDataLocation'); + late final _getAppDataLocation = + _getAppDataLocationPtr.asFunction Function()>(); + ffi.Pointer getDocumentsLocation() { return _getDocumentsLocation(); } diff --git a/packages/xdga_directories/src/xdga_directories.cpp b/packages/xdga_directories/src/xdga_directories.cpp index e0ef7b2..3707be9 100644 --- a/packages/xdga_directories/src/xdga_directories.cpp +++ b/packages/xdga_directories/src/xdga_directories.cpp @@ -7,6 +7,11 @@ char *getCacheLocation() return QStandardPaths::writableLocation(QStandardPaths::CacheLocation).toUtf8().data(); } +char *getAppDataLocation() +{ + return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).toUtf8().data(); +} + char *getDocumentsLocation() { return QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation).toUtf8().data(); diff --git a/packages/xdga_directories/src/xdga_directories.h b/packages/xdga_directories/src/xdga_directories.h index e72656d..e2f3187 100644 --- a/packages/xdga_directories/src/xdga_directories.h +++ b/packages/xdga_directories/src/xdga_directories.h @@ -4,6 +4,8 @@ extern "C" { char *getCacheLocation(); +char *getAppDataLocation(); + char *getDocumentsLocation(); char *getDownloadLocation();