From fa80ef6132510b90b77d2b812f4a4b2d2fcef64b Mon Sep 17 00:00:00 2001 From: Miguel Ruivo Date: Mon, 10 Aug 2020 15:35:43 +0100 Subject: [PATCH] Updates MacOS directory picker to applescript --- file_picker/CHANGELOG.md | 3 +++ file_picker/go/file_darwin.go | 20 ++++++++++++++++--- file_picker/pubspec.yaml | 2 +- .../lib/method_channel_file_picker.dart | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/file_picker/CHANGELOG.md b/file_picker/CHANGELOG.md index 91a59a5..725daae 100644 --- a/file_picker/CHANGELOG.md +++ b/file_picker/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.13.3 +Go: Updates MacOS directory picker to applescript (thank you @trister1997). + ## 1.13.2 Android: fixes picking paths from Downloads directory on versions below Android Q. diff --git a/file_picker/go/file_darwin.go b/file_picker/go/file_darwin.go index 1d918aa..e8ee007 100644 --- a/file_picker/go/file_darwin.go +++ b/file_picker/go/file_darwin.go @@ -75,9 +75,23 @@ func fileDialog(title string, filter string) (string, error) { } func dirDialog(title string) (string, error) { - dirPath, _, err := dlgs.File(title, `*.*`, true) + osascript, err := exec.LookPath("osascript") if err != nil { - return "", errors.Wrap(err, "failed to open dialog picker") + return "", err } - return dirPath, nil + + output, err := exec.Command(osascript, "-e", `choose folder with prompt "`+title+`"`).Output() + if err != nil { + if exitError, ok := err.(*exec.ExitError); ok { + fmt.Printf("miguelpruivo/plugins_flutter_file_picker/go: folder dialog exited with code %d and output `%s`\n", exitError.ExitCode(), string(output)) + return "", nil // user probably canceled or closed the selection window + } + return "", errors.Wrap(err, "failed to open folder dialog") + } + + trimmedOutput := strings.TrimSpace(string(output)) + + pathParts := strings.Split(trimmedOutput, ":") + path := string(filepath.Separator) + filepath.Join(pathParts[1:]...) + return path, nil } diff --git a/file_picker/pubspec.yaml b/file_picker/pubspec.yaml index e004d40..2940e87 100644 --- a/file_picker/pubspec.yaml +++ b/file_picker/pubspec.yaml @@ -1,7 +1,7 @@ name: file_picker description: A package that allows you to use a native file explorer to pick single or multiple absolute file paths, with extension filtering support. homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker -version: 1.13.2 +version: 1.13.3 dependencies: flutter: diff --git a/file_picker_platform_interface/lib/method_channel_file_picker.dart b/file_picker_platform_interface/lib/method_channel_file_picker.dart index 61cf5db..be0e271 100644 --- a/file_picker_platform_interface/lib/method_channel_file_picker.dart +++ b/file_picker_platform_interface/lib/method_channel_file_picker.dart @@ -33,7 +33,7 @@ class MethodChannelFilePicker extends FilePickerPlatform { @override Future getDirectoryPath() async { try { - return await _channel.invokeMethod('dir'); + return await _channel.invokeMethod('dir', {}); } on PlatformException catch (ex) { if (ex.code == "unknown_path") { print(