Desktop support (Linux, Windows)
I see that you are trying to implement macOS support and it would be appropriate to add Windows and Linux as well. Windows has a native Win32 API, while Linux uses libnotify library, which covers cases for different desktop environments.
- [x] Linux
- [ ] Windows
As the plugin implements a federated plugin structure, the ability to add support for other platforms is open to the community to do so. It sounds like you're interested in leveraging that work, if so then I would suggest you contribute back by adding support for the other platforms.
Yes, I'll try to help you as soon as I get free time.
Note that I'm not familiar with either Win32 or Linux. As far as I know, they require using C++, which I'm not particularly familiar with so I'm not well-positioned to implement this myself, though I could probably scrap bits of knowledge here and there to review code if needed
In general, any language that supports FFI can be used. But C++ is probably the easiest option.
Although it might be worth using Dart + FFI (but it still beta).
Hi! Our team want to help with this issue (windows part of it). Is there any new information about this feature?
If you want to help then the best way is to submit a PR. There's a draft one for Linux support https://github.com/MaikuB/flutter_local_notifications/pull/888 that you help the author with, help test out etc
We have some decision for windows notifications. It uses a process_run plugin and powershell commands. It works perfectly in debug, but in realise version of the app there are some problems. If you interesting you can find our variant here.
For linux i found a lib using gnome/gtk notification model https://github.com/canonical/desktop_notifications.dart, might want to take a peek. Saw a pr that already tried to use this model but had some issues iirc, maybe this one could work better.
This still an issue!!
@jinfagang this wasn't closed and has a needs help label even so as mentioned before in #1183, support for this would need a PRs/contributions from the community
A PoC of notification plugin on Android/iOS/Windows/Linux/macOS: https://github.com/woodemi/quick_notify
I'll be taking over Linux (and possibly Windows) support shortly. Thanks @Sunbreak, I will use your example implementation as a starting point to adapt the flutter_local_notifications API.
Started on working https://github.com/MaikuB/flutter_local_notifications/pull/1208
Duplicated from https://github.com/MaikuB/flutter_local_notifications/pull/1208#issuecomment-868767764:
At the moment I'm planning on using libnotify and C++. But there is an option to use DBus package, as is done in this project: https://github.com/canonical/desktop_notifications.dart. This will allow to write the Linux part entirely in Dart. What do you think about it?
Similarly, we can use win32 package for notifications, without using native C++ code, only Dart.
At the moment I'm planning on using
libnotifyand C++. But there is an option to use DBus package, as is done in this project: https://github.com/canonical/desktop_notifications.dart. This will allow to write the Linux part entirely in Dart. What do you think about it?
https://github.com/canonical/desktop_notifications.dart is great and it is maintained by Canonical, the company of Ubuntu
Similarly, we can use win32 package for notifications, without using native C++ code, only Dart.
There're still something to implement within win32 in order to call ToastNotificationManager: https://github.com/timsneath/win32/pull/246
@Sunbreak
https://github.com/canonical/desktop_notifications.dart is great and it is maintained by Canonical, the company of Ubuntu
Do you mean to use it inside flutter_local_notifications? Or just use DBus, instead of libnotify?
@proninyaroslav you could take advantage of desktop_notifications to implement flutter_local_notifications
@Sunbreak
I don't think this is a good idea as flutter_local_notifications tries to avoid external dependencies. It might be worth considering dbus package, or implementing DBus calls in native code if dbus package is not suitable in this case. @MaikuB what do you think about this?
@proninyaroslav agreed, the only dependency this plugin should take is to use dbus to make calls to show notifications or consume a plugin that implements Linux support by implementing the platform interface. Using desktop_notifications would make maintenance more difficult
Linux support implementation is ready, I invite everyone to take part in the review and testing https://github.com/MaikuB/flutter_local_notifications/pull/1208
The Linux implementation was swiftly removed again in v 7.0 because of a conflict with the web builds.
Is this going to be a trivial issue to fix or should I not expect Linux notification support anytime soon?
There's an open PR on this already https://github.com/MaikuB/flutter_local_notifications/pull/1249.
Once that is merged in though, I'm going to look to have Linux support be in a pre-release instead to be safe given how it went last time and to let it "bake" for bit longer
I'm currently taking a crack at Windows implementation, however I am struggling with calling WinRT API in a win32 context. Calls to WinRT APIs always throws hresult_from_win32(ERROR_NOT_FOUND, which after days of extensive research seems to indicate that the WinRT projection is not properly integrated (I think the program has to be bundled into an appx bundle). I would appreciate it if anyone can offer some guidance.
What I've done
I have followed this page to enable calling WinRT API from win32 programs, by making the following changes in CMakeLists.txt:
- Installing the WinRT/C++ nuget package:
set(NUGET_PACKAGES_PATH "${CMAKE_BINARY_DIR_WIN_STYLE_PATH}\\packages")
function(install_nuget_package pkg ver)
exec_program(${NUGET}
ARGS install ${pkg}
-ExcludeVersion
-Version ${ver}
-Source "https://api.nuget.org/v3/index.json"
-OutputDirectory ${NUGET_PACKAGES_PATH})
target_link_libraries(${PLUGIN_NAME} PRIVATE "${NUGET_PACKAGES_PATH}\\${pkg}\\build\\native\\${pkg}.targets")
endfunction()
install_nuget_package("Microsoft.Windows.CppWinRT" 2.0.210722.2)
- Setting the following target properties:
set_target_properties(${PLUGIN_NAME} PROPERTIES
CXX_VISIBILITY_PRESET hidden
VS_GLOBAL_TargetFramework "net5.0-windows10.0.17763.0"
VS_GLOBAL_CppWinRTPath "${NUGET_PACKAGES_PATH}\\Microsoft.Windows.CppWinRT\\bin\\"
)
- Enabling these compile options:
target_compile_options(${PLUGIN_NAME} PRIVATE /bigobj /await)
Related issues: https://github.com/microsoft/microsoft-ui-xaml/issues/2773
I would appreciate it if anyone can offer some guidance.
Commented at https://github.com/MaikuB/flutter_local_notifications/issues/746#issuecomment-862322428
I set VS_PROJECT_IMPORT as well and I am still having issue.
@MaikuB Any plans to publish pre-release with the Linux support? I can't wait to test it out in real conditions :D
I set
VS_PROJECT_IMPORTas well and I am still having issue.
@kennethnym We'd better discuss in another thread: How to setup WinRT/C++ for Flutter plugin on Windows
Is anyone planning to submit a PR for Windows?
I did, and it was already merged 😁 it's mostly working despite some issues
@kennethnym Thanks for your reply.
Sorry, I couldn't find out your PR. Could you tell me the link of PR and how I can use it?
Ahh sorry, thought this was flutter_secure_storage. I did manage to get notifications working on windows in my own projects, I will make a pr when I am free.
@kennethnym Thank you! I'm looking forward to your PR.
@kennethnym Thank you! I'm looking forward to your PR.
https://github.com/woodemi/quick_notify could be a workaround
https://pub.dev/packages/desktoasts works good on Windows. I could make a PR using it!
Well, it has been stated before that "flutter_local_notifications tries to avoid external dependencies",
so I suppose we could use desktoasts as a template but we would need to implement our own version of all of it.
I completely forgot about this. I think I still have working notification on windows, I just need to integrate the logic to this library. I will try to come up with something next week.
Would a PR that uses the Windows App SDK be accepted? It is an external dependency, but it is/will be the recommended way of using the notifications APIs on Windows. Full support should be available in 1.1 (https://github.com/microsoft/WindowsAppSDK#roadmap) This should work in both un-packaged (a simple exe), or packaged (using the msix package) scenario, and it should also properly activate/open the app if it is closed, in both scenarios.
In my implementation I am using the winrt api that I pulled from nuget, but I don't think it counts as a third party dependency because it is from Microsoft themselves.
@kennethnym Alright! Let me know how I can help you. I want to see this landing as soon as possible. This is one of the most used Flutter dependencies, and I know that many apps would be unblocked by this work.
If it uses something official then sure. As an example, the Linux implementation uses the dbus package maintained by Canonical
Does windows notification avaiable now?
Not yet, still a WIP
@kennethnym https://github.com/MaikuB/flutter_local_notifications/issues/746#issuecomment-890505993
set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden VS_GLOBAL_TargetFramework "net5.0-windows10.0.17763.0" VS_GLOBAL_CppWinRTPath "${NUGET_PACKAGES_PATH}\\Microsoft.Windows.CppWinRT\\bin\\" )
Not sure what is your blocking issue. But net5.0 is not necessary
BTW WinRT Notification is not available on Windows 7 if I record correctly
My visual studio install broke recently. I am trying to get it fixed.
Quick update: Flutter now bundles winrt so I no longer need to pull the winrt package manually from nuget. However, the bundled winrt seems to behave differently. I was able to send notifications successfully with the nuget version of winrt. WIth the bundled version of winrt, Windows shows "New notifications" as the content of the notification, instead of the body that I passed to it. I need to investigate further.
Edit: for context i am using VS 2022 with Windows 11.
I believe it is not Flutter that does this, but the Windows SDK itself. There is a C++/WinRT version there, but you should always use the latest from nuget.org. I have a snippet that helps installing it on cmake:
https://github.com/Baseflow/flutter-geolocator/blob/726f928ac7662f417c69bb1958e4456afd173929/geolocator_windows/windows/CMakeLists.txt#L15-L45
You will probably also need these two compiler changes (to call async code, which most of the WinRT APIs do):
https://github.com/Baseflow/flutter-geolocator/blob/726f928ac7662f417c69bb1958e4456afd173929/geolocator_windows/windows/CMakeLists.txt#L54-L55
You might also need to link to the windowsapp lib, if you call any API from it:
target_link_libraries(${PLUGIN_NAME} PRIVATE windowsapp)
Let me know if this helps you.
That is very helpful. Thanks for the info!
Unfortunately, I am still having the same issue. If I use XML template to show notification, nothing would happen; if I use one of the default templates, only "New notifications" would appear.
Could you share the code so I can take a look?
I will make a draft PR.
Is it coming soon?
It will still take a while. Appreciate your patience!
Hello, what is the state of this issue? With full support for desktop, this library is now a must for a lot of apps.
Hello, I'd love to close this as soon as possible, but I am still currently stuck at some issues (more in #1473 ). If someone could step in and help that would be great.
Looking forwards to the implementation.