Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

adpinola
Copy link
Contributor

@adpinola adpinola commented Oct 12, 2022

This PR migrates the Windows CPP implementation to Dart.
These changes have no impact on the API.

We also kept consistency along method signatures and return values across all classes between CPP and Dart versions.

We followed the styling guide from these recommendations, but it is important to note that in order for the format check to pass, some of those recommendations can't be followed, like this one.

This PR includes the changes in:

which are partial migrations from involved classes. (feedback and last updates were not applied there)

Issue: [file_selector_windows] Migrate CPP implementation to Dart. #112212

The following images show the current functionality tested against the example app located at file_selector_windows/example

eodopentxt
Open File

eodopenimage
Open Image

openmultipleimages
Open Multiple Images

eodfilesaved
Save a File

eodgetdirectorypath
Get Directory Path

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@adpinola adpinola force-pushed the file_selector/windows/66671-replace-file-selector-api-with-new-implementation branch from e346432 to 13fbe29 Compare October 12, 2022 18:01
@eugerossetto eugerossetto force-pushed the file_selector/windows/66671-replace-file-selector-api-with-new-implementation branch from 13fbe29 to 604d464 Compare October 12, 2022 20:59
@adpinola adpinola marked this pull request as ready for review October 12, 2022 22:49
@eugerossetto eugerossetto force-pushed the file_selector/windows/66671-replace-file-selector-api-with-new-implementation branch from 6fb9f00 to 5b1388c Compare October 12, 2022 23:30
@adpinola
Copy link
Contributor Author

adpinola commented Oct 13, 2022

I've seen that this check legacy-version-analyze CHANNEL:2.10.5 is failing, and as far as I understand, It is related to new dependencies like win32 and ffi; both of them declare in their own pubspec.yml file the following:

environment:
  sdk: '>=2.17.0 <3.0.0'

I'm not sure how to address this situation, But I'm wondering if we should change the environment settings in the package

from:

environment:
  sdk: ">=2.12.0 <3.0.0"
  flutter: ">=2.10.0"

to:

environment:
  sdk: ">=2.17.0 <3.0.0"
  flutter: ">=3.0.0"

Will that avoid running the legacy-version-analyze check?

@adpinola adpinola force-pushed the file_selector/windows/66671-replace-file-selector-api-with-new-implementation branch from f38a4a5 to 73bd832 Compare October 20, 2022 17:06
@adpinola
Copy link
Contributor Author

adpinola commented Oct 20, 2022

Hi @timsneath thanks for your feedback, we applied some changes, can you take a look again?

What we did specifically was:

  • Replaced TEXT() usage with ToNativeUtf16(allocator: arena) to handle allocations as we did previously in other parts of the code.
  • Applied the styling guide from these recommendations, but it is important to note that in order for the format check to pass, some of those recommendations can't be followed, like this one.

@adpinola adpinola force-pushed the file_selector/windows/66671-replace-file-selector-api-with-new-implementation branch 2 times, most recently from a50ef98 to 602c020 Compare November 2, 2022 14:47
@adpinola
Copy link
Contributor Author

Hi @loic-sharma, thanks for your feedback.
I'll be attending to your comments today.

At a glance, there are some cases when we are returning an empty string or not throwing an exception. The reason for this was to maintain the exact implementation that was written in C++. If you agree, I'll make the changes to throw a WindowsException in those cases.

Thanks!!

@loic-sharma
Copy link
Member

At a glance, there are some cases when we are returning an empty string or not throwing an exception. The reason for this was to maintain the exact implementation that was written in C++.

Gotcha, that makes perfect sense! This Dart migration is already a major change; I agree that minimizing the differences between the two implementations is valuable.

If you agree, I'll make the changes to throw a WindowsException in those cases.

I'm not very familiar with the existing C++ implementation, I'll take a closer look at that and get back to you.

@adpinola adpinola force-pushed the file_selector/windows/66671-replace-file-selector-api-with-new-implementation branch 2 times, most recently from 904da58 to 674daad Compare November 10, 2022 19:34
@adpinola
Copy link
Contributor Author

Thanks, @loic-sharma.

Regarding my previous comment, I applied this one:

As per FileSelectorPlatform's documentation, this should return null if the user cancels the operation. However, a WindowsException(E_FAIL) exception is thrown instead in this scenario by FileSelectorApi._showDialog.

to match the API expectation, regardless of the previous C++ implementation. (Pigeons used to handle this in the top level as I recently double-checked)

Moreover, since the ShellWin32Api wrapper is new, It's better to actually throw the exception instead of the empty string, as you suggested. So I applied that, also.

I think we are now in better shape.

Thanks!!

@adpinola adpinola force-pushed the file_selector/windows/66671-replace-file-selector-api-with-new-implementation branch 2 times, most recently from 022482b to 25b65a5 Compare November 10, 2022 20:56
@adpinola adpinola force-pushed the file_selector/windows/66671-replace-file-selector-api-with-new-implementation branch 3 times, most recently from 9e06460 to bc78285 Compare November 17, 2022 19:29
@adpinola adpinola force-pushed the file_selector/windows/66671-replace-file-selector-api-with-new-implementation branch from bc78285 to 24ae23b Compare November 17, 2022 19:35
@stuartmorgan
Copy link
Contributor

From triage: what's the status of this PR? Is it waiting for new updates, or for re-review?

@timsneath
Copy link
Contributor

timsneath commented Jan 22, 2023 via email

@adpinola
Copy link
Contributor Author

adpinola commented Jan 23, 2023

From triage: what's the status of this PR? Is it waiting for new updates, or for re-review?

@stuartmorgan It is ready for re-review.

@stuartmorgan
Copy link
Contributor

Apologies if I missed or forgot some discussion elsewhere, but what are the changes in approach here relative to https://github.com/flutter/plugins/pull/6467to address #6467 (comment)? There were incremental PRs, but those got re-combined, so it seems like we're back to a full from-scratch rewrite here.

@adpinola
Copy link
Contributor Author

Hi, the main difference is that we kept a 1:1 relation between Dart and Cpp classes. Morevorer, method's were implemented following the same logic as they used to have in old Cpp implementation, like input and returned values.

@stuartmorgan
Copy link
Contributor

We've just completed the migration of the plugin code to the flutter/packages repository, as described in https://flutter.dev/go/flutter-plugins-repo-migration, and this repository is now being archived. Unfortunately that means that all in-progress PRs here must be moved to flutter/packages.

Please see our instructions for an explanation of how to move your PR, and if you have any issues moving your PR please don't hesitate to reach out in the #hackers-ecosystem channel in Discord.

Our apologies that your PR was caught in this one-time transition. We're aware that it's disruptive in the short term, and appreciate your help in getting us to a better long-term state!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants