-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[file_selector_windows] Migrate native implementation to Dart. #6467
[file_selector_windows] Migrate native implementation to Dart. #6467
Conversation
* Migrate open multiple files. * Migrate windows get save path. * Rename variable and methods, reorder functions and remove unused parameters. * Remove CPP implementation. * Update package version.
bcadce3
to
90558cd
Compare
packages/file_selector/file_selector_windows/lib/src/dart_place.dart
Outdated
Show resolved
Hide resolved
packages/file_selector/file_selector_windows/lib/src/dart_file_dialog.dart
Outdated
Show resolved
Hide resolved
packages/file_selector/file_selector_windows/lib/file_selector_windows.dart
Outdated
Show resolved
Hide resolved
packages/file_selector/file_selector_windows/lib/file_selector_windows.dart
Outdated
Show resolved
Hide resolved
packages/file_selector/file_selector_windows/lib/src/dart_file_selector_api.dart
Outdated
Show resolved
Hide resolved
Have these changes had any effect on existing dll files affecting the autoroll tests? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few quick doc/comment-related comments to start with. This is purely documentation related and I've only glanced through the first few files.
packages/file_selector/file_selector_windows/lib/src/dart_file_dialog.dart
Outdated
Show resolved
Hide resolved
packages/file_selector/file_selector_windows/lib/src/dart_file_dialog.dart
Outdated
Show resolved
Hide resolved
packages/file_selector/file_selector_windows/lib/src/dart_file_open_dialog_api.dart
Outdated
Show resolved
Hide resolved
|
||
/// FileOpenDialogAPI provider, it used to interact with an IFileOpenDialogInstance. | ||
class FileOpenDialogAPI { | ||
/// Sets dialog options. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and a few other places: avoid adding docs that add no details over the method name.
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#avoid-useless-documentation
packages/file_selector/file_selector_windows/lib/src/dart_file_selector_api.dart
Outdated
Show resolved
Hide resolved
packages/file_selector/file_selector_windows/lib/src/dart_file_selector_api.dart
Outdated
Show resolved
Hide resolved
packages/file_selector/file_selector_windows/lib/src/dart_file_selector_api.dart
Outdated
Show resolved
Hide resolved
packages/file_selector/file_selector_windows/lib/src/dart_file_selector_api.dart
Outdated
Show resolved
Hide resolved
packages/file_selector/file_selector_windows/lib/src/dart_place.dart
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did an initial skim, and left some inline comments, but as a high-level comment: I find this difficult to review because all of the classes have names that don't clearly distinguish them from each other, and then the comments for each class are a single vague sentence. Please expand on the class documentation so that each class has a clear description of what that class's responsibility is in the overall structure, so that readers (including us as reviewers) can get a clear sense of the overall structure of this code without having to reverse-engineer it from the details.
I'm also concerned about the fact that this is an all-at-once rewrite, which due to the lack of integration tests (since we can't do integration tests for native modal UI at the moment for Windows) means that all the tests are new. So in one PR we're discarding the entire real-world-tested implementation for a completely new implementation, and also discarding all of the unit tests. Could this instead be done as a series of incremental PRs, adding new Dart code piece by piece with (when possible) a clear mapping to both the native code it's replacing and a clear mapping between the unit tests? That would make this much easier to review as a delta to the existing implementation, instead of as a green-field implementation that may have regressions.
import 'src/messages.g.dart'; | ||
|
||
/// An implementation of [FileSelectorPlatform] for Windows. | ||
class FileSelectorWindows extends FileSelectorPlatform { | ||
final FileSelectorApi _hostApi = FileSelectorApi(); | ||
/// Constructor for filePicker. | ||
FileSelectorWindows([this._dartFileSelectorAPI]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the implementation of the class an argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is used for testing purposes.
packages/file_selector/file_selector_windows/lib/file_selector_windows.dart
Outdated
Show resolved
Hide resolved
packages/file_selector/file_selector_windows/lib/file_selector_windows.dart
Outdated
Show resolved
Hide resolved
packages/file_selector/file_selector_windows/lib/file_selector_windows.dart
Outdated
Show resolved
Hide resolved
packages/file_selector/file_selector_windows/lib/src/dart_file_dialog.dart
Outdated
Show resolved
Hide resolved
import 'package:win32/win32.dart'; | ||
|
||
/// FileOpenDialogAPI provider, it used to interact with an IFileOpenDialogInstance. | ||
class FileOpenDialogAPI { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is intended to wrap IFileOpenDialog
, why is it taking the dialog as an argument to every method instead of that being a constructor argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Stuart, like this class is also used to create new instances, we prefer passing IFileOpenDialog
as a parameter.
packages/file_selector/file_selector_windows/lib/src/dart_file_open_dialog_api.dart
Outdated
Show resolved
Hide resolved
packages/file_selector/file_selector_windows/lib/src/dart_shell_item_api.dart
Outdated
Show resolved
Hide resolved
import 'dart_file_open_dialog_api.dart'; | ||
import 'dart_shell_item_api.dart'; | ||
|
||
/// Dart native implementation of FileSelectorAPI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't match the extends
, which makes this comment very confusing to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Stuart, it was an error, we updated the hierarchy and the comments.
@@ -0,0 +1,687 @@ | |||
// Copyright 2013 The Flutter Authors. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't gone through this in detail yet, but it seems concerning that there are six different implementation files but only one test file. Why doesn't the test structure match the implementation structure?
* Rename files removing the dart_ prefix. * Rename Classes including API to Api. * Remane class FileSelectorAPI to FileSelector and improve its documentation. * Remove unused abstraction FileDialog. * Release resources within a finally block. * Update CHANGELOG.md entry. * Remove unused classes. * Update file_open_dialog_wrapper.dart documentation. * Remove unnecessary ternary operation. * Update the setFileTypes method to use arena instead of calloc and free.
Hi everyone, thanks for the feedback. We are taking care of the suggested changes but, we don't want to wait till cover all the comments before submitting them. The remaining uncovered comments are the following:
Cheers, |
Hi @yaakovschectman, I don't follow you, what do you mean by this?
Thanks, |
Previously, tests were failing due to a missing .dll file. Now it looks like they're failing for a different reason. |
Was there a response to my structural comment about how the PR is being done somewhere? |
…onstructor. (#15) * Update file_selector_windows constructor to match expectations. * Add license in the open_file_dialog_mock.dart file. * Add tests for the ShellItemWrapper class. * Add tests for the method getDisplayName of the ShellItemWrapper class. * Add tests for the method release and releaseItem of the ShellItemWrapper class. * Rename test files. * Add tests for the FileOpenDialogWrapper class.
Hi Stuart, about your question:
We could add the whole implementation but instead of removing the CPP code, use it for just three out of four functions, and make the other one uses the new Dart implementation. What do you think about this? Thanks, |
That doesn't address my concerns with reviewability or test equivalence since the "add the whole implementation" part is the problem. It appear that this was a from-scratch rewrite, rather than an incremental conversion, and that makes comparing quite difficult. As an example: in looking at this again, it appear that you completely dropped the window parenting. Code to pass a parent is there, but it's never populated as far as I can tell. Which means that you didn't preserve the logic from the C++ implementation, but importantly also that you didn't replicate the test coverage of file_selector_plugin_test.cpp. This is why all-at-once rewrites are problematic; there's no clear way to tell how many other similar regressions there might be here, or what test coverage was lost. At a minimum, since we can't do end-to-end integration tests (due to the modal native UI) the starting point for a completely new implementation would need to be a direct conversion of the existing C++ pseudo-inegration tests (which start at the native entry point, and only mock Windows APIs, to test all of the native code end to end) to Dart, so that we can compare the tests and easily see that we have identical coverage to what's already there. |
Hi Stuart, so we should migrate the existing code to Dart, without changing its logic. We are going to do this in parts, as you told us. The plan following:
Thanks. |
Migrate native implementation to Dart, including the following changes:
openFile
.openFiles
.getSavePath
.getDirectoryPath
.We based our development on the available filepicker_windows
[file_seletor_windows] Migrate CPP implementation to Dart. #112212
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.