From 8137dc429b6265e2124988e4563e1fefcbffcb84 Mon Sep 17 00:00:00 2001 From: Thomas Verbeek Date: Mon, 23 Dec 2019 14:57:20 +0100 Subject: [PATCH 1/7] path_provider now supports getDownloadsDirectory() on macOS. Fixes #47676 --- packages/path_provider/lib/path_provider.dart | 20 +++++++++++++++++++ .../path_provider_macos/CHANGELOG.md | 4 ++++ .../macos/Classes/PathProviderPlugin.swift | 2 ++ .../path_provider_macos/pubspec.yaml | 2 +- .../test/path_provider_test.dart | 8 ++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/path_provider/lib/path_provider.dart b/packages/path_provider/lib/path_provider.dart index 52aceb786477..b27cc4bc3fcb 100644 --- a/packages/path_provider/lib/path_provider.dart +++ b/packages/path_provider/lib/path_provider.dart @@ -216,3 +216,23 @@ Future> getExternalStorageDirectories({ return paths.map((String path) => Directory(path)).toList(); } + +/// Path to the directory where downloaded files can be stored. +/// This is typically only relevant on desktop operating systems. +/// +/// On Android and on iOS, this function throws an [UnsupportedError] as no equivalent +/// path exists. +Future getDownloadsDirectory() async { + if (_platform.isAndroid) { + throw UnsupportedError('Functionality not available on Android'); + } + if (_platform.isIOS) { + throw UnsupportedError('Functionality not available on iOS'); + } + final String path = + await _channel.invokeMethod('getDownloadsDirectory'); + if (path == null) { + return null; + } + return Directory(path); +} diff --git a/packages/path_provider/path_provider_macos/CHANGELOG.md b/packages/path_provider/path_provider_macos/CHANGELOG.md index 3e3607e44a33..21593a70f078 100644 --- a/packages/path_provider/path_provider_macos/CHANGELOG.md +++ b/packages/path_provider/path_provider_macos/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.0.3+1 + +* Added support for user's downloads directory. + ## 0.0.2+1 * Update README. diff --git a/packages/path_provider/path_provider_macos/macos/Classes/PathProviderPlugin.swift b/packages/path_provider/path_provider_macos/macos/Classes/PathProviderPlugin.swift index 4ceb00634097..cb56fc49769c 100644 --- a/packages/path_provider/path_provider_macos/macos/Classes/PathProviderPlugin.swift +++ b/packages/path_provider/path_provider_macos/macos/Classes/PathProviderPlugin.swift @@ -49,6 +49,8 @@ public class PathProviderPlugin: NSObject, FlutterPlugin { result(path) case "getLibraryDirectory": result(getDirectory(ofType: FileManager.SearchPathDirectory.libraryDirectory)) + case "getDownloadsDirectory": + result(getDirectory(ofType: FileManager.SearchPathDirectory.downloadsDirectory)) default: result(FlutterMethodNotImplemented) } diff --git a/packages/path_provider/path_provider_macos/pubspec.yaml b/packages/path_provider/path_provider_macos/pubspec.yaml index 82acee955a0a..f345ed6a16c1 100644 --- a/packages/path_provider/path_provider_macos/pubspec.yaml +++ b/packages/path_provider/path_provider_macos/pubspec.yaml @@ -1,6 +1,6 @@ name: path_provider_macos description: macOS implementation of the path_provider plugin -version: 0.0.2+1 +version: 0.0.3+1 homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_macos flutter: diff --git a/packages/path_provider/test/path_provider_test.dart b/packages/path_provider/test/path_provider_test.dart index 7af37888492f..5b875e3bc51e 100644 --- a/packages/path_provider/test/path_provider_test.dart +++ b/packages/path_provider/test/path_provider_test.dart @@ -226,4 +226,12 @@ void main() { ); expect(directories.map((Directory d) => d.path).toList(), equals(paths)); }); + + test('DownloadsDirectory path macos test', () async { + setMockPathProviderPlatform(FakePlatform(operatingSystem: 'macos')); + final String fakePath = "/foo/bar/baz"; + response = fakePath; + final Directory directory = await getDownloadsDirectory(); + expect(directory.path, equals(fakePath)); + }); } From 992bc553b5c872f9ec87a1c14684222fa0ad500a Mon Sep 17 00:00:00 2001 From: Thomas Verbeek Date: Mon, 23 Dec 2019 15:37:36 +0100 Subject: [PATCH 2/7] fixed version number of sub module path_provider_macos --- packages/path_provider/path_provider_macos/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/path_provider/path_provider_macos/pubspec.yaml b/packages/path_provider/path_provider_macos/pubspec.yaml index f345ed6a16c1..23aef10aa1a4 100644 --- a/packages/path_provider/path_provider_macos/pubspec.yaml +++ b/packages/path_provider/path_provider_macos/pubspec.yaml @@ -1,6 +1,6 @@ name: path_provider_macos description: macOS implementation of the path_provider plugin -version: 0.0.3+1 +version: 0.0.2+2 homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_macos flutter: From 7702d7293632dce2fd3e27a42ee5bb2b59edb115 Mon Sep 17 00:00:00 2001 From: Thomas Verbeek Date: Mon, 23 Dec 2019 14:57:20 +0100 Subject: [PATCH 3/7] path_provider now supports getDownloadsDirectory() on macOS. Fixes #47676 --- packages/path_provider/lib/path_provider.dart | 20 +++++++++++++++++++ .../path_provider_macos/CHANGELOG.md | 4 ++++ .../macos/Classes/PathProviderPlugin.swift | 2 ++ .../path_provider_macos/pubspec.yaml | 2 +- .../test/path_provider_test.dart | 8 ++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/path_provider/lib/path_provider.dart b/packages/path_provider/lib/path_provider.dart index 52aceb786477..b27cc4bc3fcb 100644 --- a/packages/path_provider/lib/path_provider.dart +++ b/packages/path_provider/lib/path_provider.dart @@ -216,3 +216,23 @@ Future> getExternalStorageDirectories({ return paths.map((String path) => Directory(path)).toList(); } + +/// Path to the directory where downloaded files can be stored. +/// This is typically only relevant on desktop operating systems. +/// +/// On Android and on iOS, this function throws an [UnsupportedError] as no equivalent +/// path exists. +Future getDownloadsDirectory() async { + if (_platform.isAndroid) { + throw UnsupportedError('Functionality not available on Android'); + } + if (_platform.isIOS) { + throw UnsupportedError('Functionality not available on iOS'); + } + final String path = + await _channel.invokeMethod('getDownloadsDirectory'); + if (path == null) { + return null; + } + return Directory(path); +} diff --git a/packages/path_provider/path_provider_macos/CHANGELOG.md b/packages/path_provider/path_provider_macos/CHANGELOG.md index 3e3607e44a33..21593a70f078 100644 --- a/packages/path_provider/path_provider_macos/CHANGELOG.md +++ b/packages/path_provider/path_provider_macos/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.0.3+1 + +* Added support for user's downloads directory. + ## 0.0.2+1 * Update README. diff --git a/packages/path_provider/path_provider_macos/macos/Classes/PathProviderPlugin.swift b/packages/path_provider/path_provider_macos/macos/Classes/PathProviderPlugin.swift index 4ceb00634097..cb56fc49769c 100644 --- a/packages/path_provider/path_provider_macos/macos/Classes/PathProviderPlugin.swift +++ b/packages/path_provider/path_provider_macos/macos/Classes/PathProviderPlugin.swift @@ -49,6 +49,8 @@ public class PathProviderPlugin: NSObject, FlutterPlugin { result(path) case "getLibraryDirectory": result(getDirectory(ofType: FileManager.SearchPathDirectory.libraryDirectory)) + case "getDownloadsDirectory": + result(getDirectory(ofType: FileManager.SearchPathDirectory.downloadsDirectory)) default: result(FlutterMethodNotImplemented) } diff --git a/packages/path_provider/path_provider_macos/pubspec.yaml b/packages/path_provider/path_provider_macos/pubspec.yaml index 82acee955a0a..f345ed6a16c1 100644 --- a/packages/path_provider/path_provider_macos/pubspec.yaml +++ b/packages/path_provider/path_provider_macos/pubspec.yaml @@ -1,6 +1,6 @@ name: path_provider_macos description: macOS implementation of the path_provider plugin -version: 0.0.2+1 +version: 0.0.3+1 homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_macos flutter: diff --git a/packages/path_provider/test/path_provider_test.dart b/packages/path_provider/test/path_provider_test.dart index 7af37888492f..5b875e3bc51e 100644 --- a/packages/path_provider/test/path_provider_test.dart +++ b/packages/path_provider/test/path_provider_test.dart @@ -226,4 +226,12 @@ void main() { ); expect(directories.map((Directory d) => d.path).toList(), equals(paths)); }); + + test('DownloadsDirectory path macos test', () async { + setMockPathProviderPlatform(FakePlatform(operatingSystem: 'macos')); + final String fakePath = "/foo/bar/baz"; + response = fakePath; + final Directory directory = await getDownloadsDirectory(); + expect(directory.path, equals(fakePath)); + }); } From 4294bc36dcd1118120ae9b085fabde61be1f6484 Mon Sep 17 00:00:00 2001 From: Thomas Verbeek Date: Mon, 23 Dec 2019 15:37:36 +0100 Subject: [PATCH 4/7] fixed version number of sub module path_provider_macos --- packages/path_provider/path_provider_macos/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/path_provider/path_provider_macos/pubspec.yaml b/packages/path_provider/path_provider_macos/pubspec.yaml index f345ed6a16c1..23aef10aa1a4 100644 --- a/packages/path_provider/path_provider_macos/pubspec.yaml +++ b/packages/path_provider/path_provider_macos/pubspec.yaml @@ -1,6 +1,6 @@ name: path_provider_macos description: macOS implementation of the path_provider plugin -version: 0.0.3+1 +version: 0.0.2+2 homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_macos flutter: From be10c4eda94adbfce3860dde5f5f01744f85b75e Mon Sep 17 00:00:00 2001 From: Thomas Verbeek Date: Fri, 27 Dec 2019 10:05:32 +0100 Subject: [PATCH 5/7] set version number of sub module path_provider_macos to 0.0.3 --- packages/path_provider/path_provider_macos/CHANGELOG.md | 2 +- packages/path_provider/path_provider_macos/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/path_provider/path_provider_macos/CHANGELOG.md b/packages/path_provider/path_provider_macos/CHANGELOG.md index 21593a70f078..ae674a2113a5 100644 --- a/packages/path_provider/path_provider_macos/CHANGELOG.md +++ b/packages/path_provider/path_provider_macos/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.0.3+1 +## 0.0.3 * Added support for user's downloads directory. diff --git a/packages/path_provider/path_provider_macos/pubspec.yaml b/packages/path_provider/path_provider_macos/pubspec.yaml index 23aef10aa1a4..ca04d59a7fd8 100644 --- a/packages/path_provider/path_provider_macos/pubspec.yaml +++ b/packages/path_provider/path_provider_macos/pubspec.yaml @@ -1,6 +1,6 @@ name: path_provider_macos description: macOS implementation of the path_provider plugin -version: 0.0.2+2 +version: 0.0.3 homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_macos flutter: From 06aa76648668dabb08b1f8c266bc55e93245f8b4 Mon Sep 17 00:00:00 2001 From: Thomas Verbeek Date: Fri, 24 Jan 2020 09:29:15 +0100 Subject: [PATCH 6/7] Increased path_provider version to 1.5.2 and added change log entry. --- packages/path_provider/CHANGELOG.md | 4 ++++ packages/path_provider/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/path_provider/CHANGELOG.md b/packages/path_provider/CHANGELOG.md index ee7163f1cf56..37765ef7b010 100644 --- a/packages/path_provider/CHANGELOG.md +++ b/packages/path_provider/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.5.2 + +* macOS support now allows for retrieving the user's downloads directory. + ## 1.5.1 * Remove the deprecated `author:` field from pubspec.yaml diff --git a/packages/path_provider/pubspec.yaml b/packages/path_provider/pubspec.yaml index 730e7a5b5c1e..51ab5b5d7811 100644 --- a/packages/path_provider/pubspec.yaml +++ b/packages/path_provider/pubspec.yaml @@ -2,7 +2,7 @@ name: path_provider description: Flutter plugin for getting commonly used locations on the Android & iOS file systems, such as the temp and app data directories. homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider -version: 1.5.1 +version: 1.5.2 flutter: plugin: From 3c74f1dc1739d515614855de1a6b1dbe342df7bb Mon Sep 17 00:00:00 2001 From: Thomas Verbeek Date: Tue, 28 Jan 2020 15:50:52 +0100 Subject: [PATCH 7/7] bumped version to 1.6.0. Adapted changelog. --- packages/path_provider/CHANGELOG.md | 5 +++-- packages/path_provider/pubspec.yaml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/path_provider/CHANGELOG.md b/packages/path_provider/CHANGELOG.md index 37765ef7b010..ad26ead1ca3b 100644 --- a/packages/path_provider/CHANGELOG.md +++ b/packages/path_provider/CHANGELOG.md @@ -1,6 +1,7 @@ -## 1.5.2 +## 1.6.0 -* macOS support now allows for retrieving the user's downloads directory. +* Support for retrieving the downloads directory was added. + The call for this is `getDownloadsDirectory`. ## 1.5.1 diff --git a/packages/path_provider/pubspec.yaml b/packages/path_provider/pubspec.yaml index 51ab5b5d7811..e884c0f4aecd 100644 --- a/packages/path_provider/pubspec.yaml +++ b/packages/path_provider/pubspec.yaml @@ -2,7 +2,7 @@ name: path_provider description: Flutter plugin for getting commonly used locations on the Android & iOS file systems, such as the temp and app data directories. homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider -version: 1.5.2 +version: 1.6.0 flutter: plugin: