-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flutter_local_notifications_windows] Windows FFI plugin #2366
base: master
Are you sure you want to change the base?
Conversation
flutter_local_notifications_windows/lib/src/details/notification_text.dart
Outdated
Show resolved
Hide resolved
Thanks for making the changes. I left one comment. Other thing was I wasn't too sure if you were done addressing the visibility of methods to with XML conversion. Since you mentioned it's good to go then FYI that there are still some methods that are publicly visible. I've commented on the parts that I could see are still visible to be more explicit. Apologies for spam on that but though it help make them easier to find. FYI that the way to verify is to follow the steps here to generate the API docs for the Windows plugin. Just noticed that there's also errors on the dependency/version conflict that wasn't there before. Presumably ffigen got bumped that it's no longer compatible with what was stated before on Dart 3.1 being the minimum Edit: when I checked the API docs for the Windows plugin and Linux one, I've noticed an existing problem where the docs for the stub is what is shown. Not a showstopper for the PR right now as it's an existing problem already that I've not seen anyone raise with the Linux implementation. Not sure how to solve this one but open to ideas. Off the top of my head, I suspect either the stub needs to have the same API docs that would be a bit of a hack or see if there's a way that only the real |
When a subclass overrides a member, that member inherits its docs from the overriden version in the parent class, so long as docs are not explicitly provided on the override itself. This seems to be why the Linux version shows the stub docs -- the stub's overrides all have doc comments. To fix this, we should just not provide documentation on the stub class and let in inherit directly from the base class. That just leaves the documentation on the class itself. I think the simplest fix would then be to copy the base class's documentation onto the stub class, which is a lot less work than copying every single member. So now:
|
Yup, from
Those specific features aren't used by us in this exact case, but the features from ffigen 10.0 -- 13.0 (soon to be 14.0) will be, especially exhaustive enum checking. I think it would be worth bumping the minimum SDK version to |
I actually figured it would probably be more convenient to leave them public. Since we offer a way to show notifications as raw XML, this would allow developers to build that XML using elements from the public API. Let's say they want to use their own If we really wanted to keep everything private, I could move them all to extensions, and then Regarding the naming convention, I switched everything to |
- Changed `toXml` to `buildXml` - Fixed comments on stub class - Bumped Dart version to ^3.2 - Fixed `enableMultithreading` not being always annotated - Only test on Windows
Good callout as I admittedly forgot about that. Works for me and will update the approach used for Linux as well. Thanks!
Thanks though building for 3.13 will fail as the main plugin itself has a minimum of 3.13 so that and pipeline would need updating as part of the PR too. I've withheld bumping for this plugin for a while and would still need to be careful of it in the future as it could affect the minimum supported OS versions
Yep would like to keep these hidden. These methods depend on an existing object passed through so AFAICT there's some prerequisites on what needs to be done before calling these |
Bumped
Got it, moved all that to extensions in On another note, I restricted the tests to run on Windows only, but the current workflows are running on |
i would like to note that public repos actions are free, so i think the rate is not a problem? https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#about-billing-for-github-actions |
@Levi-Lesches sorry for late response, was recovering from surgery. It looks like there's still a conflict. Based on my understanding of the constraints set by ffigen 13.0, this actually needs Flutter 3.19/Dart 3.3 (reference: table under stable at https://docs.flutter.dev/release/archive). Are you able to help resolve this
I could be mistaken but presumably as they're unit tests, the priviledges to be concerned about. Given what @abdelaziz-mahdy has said, you think you could push an update to have the tests run on Windows? On a related note, is it possible to make updates so that so that the example app is built on Windows as part of the GitHub workflow too? Would require updates to melos.yaml and validate.yml I've also noticed there's a lot of files with changes picked up if I run Edit: I've merged in #2398 that should help highlight formatting issues in the future |
Sorry to hear, hope that's going well 🙂
That's annoying, I checked the changelog and found mention of
I didn't mock everything out, as I was interested in maintaining tests that the XML does in fact conform to the Windows API. So the unit tests actually do send full XML to the Windows API and try to send notifications. If this doesn't work on the server, I'd still like to keep them, but maybe we'll just run them manually when changing XML code and configure the CI to only run "safe" tests. Speaking of, I added a global
Hit an annoying issue where "skip these tests on Windows" was actually causing Linux tests to fail. Filed dart-lang/test#2277 to propose to change that, but in the meantime I exclude
Done and pushed On another note, I had previously tried to make the Dart package completely separate from Flutter so it can be used in CLI apps. I still believe there is value to that, but when running Package validation found the following error:
* pubspec.yaml allows Flutter SDK version 1.9.x, which does not support the flutter.plugin.platforms key.
Please consider increasing the Flutter SDK requirement to ^1.10.0 (environment.sdk.flutter)
See https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin Basically, even though having a My recommendation is to run |
I'll take a look and come back to you on these but thought I'd reply in case you missed it since it wasn't brought up in your last message and mention that builds are failing due to the meta version specified |
Good eye -- fixed |
Thanks minor surgery and still bit of discomfort but all good besides that :)
I forgot to ask but is this realistically possible? In the case of the platform interface, this would normally be a transitive dependency. In the case of the Windows plugin, I don't know if you could build a CLI app that shows notifications on the Windows platform? Presumably what you mean is the equivalent of using Visual Studio to create a console app and referencing the Windows APIs to display notifications
This is what I get besides the Flutter one
I've taken a look at the issue you linked and conscious it's been open for a while. I do have a number of thoughts relating to this to and may be missing some additional context and other information so do let me know if I'm missing anything. If issue linked addressed and there are valid cases for CLI apps, I wonder if it'd be better for the "greater good" to go ahead with the Flutter requirement and revisit this. Those who use this plugin would be those looking to build a multiplatform apps. Other aspect of this is if the issue you raised is addressed, then this presumably requires newer version of the Dart SDK. If so, this would cause the Flutter SDK requirement to go even higher and limit the reach even further. If it's possible to build a Dart CLI app that can show notifications on Windows then this sounds like it one target a very small audience if such an audience even exists. I'm basing this on the assumption that this implies that this is a developer who works on the Windows platform and rather than building a Windows console application, has decided to use Dart. Is this what it would mean? If so, this seems like an odd choice to me. In my experience, companies that build dedicated solutions targeting Windows would employ devs and leverage based on .NET On a different note, it looks like Windows example is failing to built I'm not sure what's the cause there. However, I'm noticing that the integration tests are failing to run for Android. It seems as though the deprecation warning is being treated as a error but can't reproduce this locally even if I run the integration tests via melos. Given I had raised a PR recently to update one of the workflows and didn't have this issue, I wonder if something got changed that impacted this? |
It's been a while since I've worked on Windows apps so didn't get to spend much time on it but ran into the following problems relating my previous post
Based on the above it looks like trying to support CLI apps isn't actually possible, at least not in the current state either |
PWSTR fullName = (PWSTR) malloc(length * sizeof(*fullName)); | ||
if (fullName == nullptr) return std::nullopt; | ||
error = GetCurrentPackageFullName(&length, fullName); | ||
if (error != ERROR_SUCCESS) return std::nullopt; | ||
free(fullName); |
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.
Use a std::vector. You currently have a memory leak in the case of an error.
Update: I went in and simplified the code since yesterday, it's now in a reviewable state. If it would help, I can rebase + commit the first 50 or so commits and start with a cleaner slate.
This is a spin off of #2349, which implements the same logic but with an FFI plugin instead of method channels. I'm happy with it so far, here's the gist:
The C/C++ code
src/ffi_api.h
: a C API between C++ and Dartsrc/plugin.hpp
: A C++ class that holds Windows-specific API handlessrc/ffi_api.cpp
: C++ code to implement the C API using the C++ classThe Dart code
flutter_local_notifications_windows
that implements the same functionality as before.lib/src/details
holds all the platform-specific detailslib/src/ffi
holds basic FFI stuff, like generated bindings and utilslib/src/plugin
holds the Windows plugin interface, the real FFI implementation, and a stub, becausedart:ffi
will break web apps (note, the API does referencedart:io
but it still compiles on web)Notes
HandleMethodCall
function that had to handle every possibility. I'm glad that's gone. Now we have a similar mechanism with Dart <--> C <--> C++ andpackage:ffigen
sets everything up for us."hello".toNativeString()
, but other types require allocating memory manually.Benefits
flutter_local_notifications_windows
instead of hijacking the original package and half-sharing some of the original implementations. That means no more platform checks, all the logic can be safely dealt with in a Windows-only context.Summary of changes
That's only ~2,200 additions. the other half GitHub is reporting is automatically generated, like the example's new
windows
folder.Important
FFI is a more recent development than method channels. As such, some more advanced FFI features are locked behind some more recent Dart versions. I already had to downgrade
package:ffigen
from a beta 13.0 to a whopping 7.0, but more pressing is that for C to call a Dart function from another thread (eg, when a notification is pressed), you need to use features from Dart 3.1. The current constraint is only 2.17.Including this new implementation will force Dart ^3.1.0 on end-users. At this point, 2.17 is two years old, 3.1 is about one year old, and null safety is almost 3.5 years old. Age aside, I also don't believe going from 2.17 to 3.1 is so burdensome, especially since 2.17 is already after null-safety, and the Dart team's official position is that 3.0 is not really a breaking change in practice. In other words, I'm not sure I see a situation where someone is really stuck. They can either upgrade any pre-null-safety code, not upgrade this package further, or fork this package to add null Windows or future updates as needed.
Overall, I'd recommend bumping the SDK version of the front-facing package to 3.1.0 as well to better advertise this, and to benefit from any features, since 2.17 and beyond -- better null promotion, FFI for mobile platforms, class modifiers, macros, and more.