-
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] [WIP] Windows implementation of notifications #1473
base: master
Are you sure you want to change the base?
Conversation
Hey @kennethnym, I've cloned your branch and built the source, and a simple plain notification worked totally fine for me. |
I tried using the default templates but it would just show "New notification" instead of the actual body. |
@azchohfi To illustrate, this is the code that I have at the moment: const auto doc = winrt::Windows::UI::Notifications::ToastNotificationManager::GetTemplateContent(winrt::Windows::UI::Notifications::ToastTemplateType::ToastText01);
const auto nodes = doc.GetElementsByTagName(L"text");
nodes.Item(0).AppendChild(doc.CreateTextNode(winrt::to_hstring(title)));
winrt::Windows::UI::Notifications::ToastNotification notif{ doc };
const auto notifier = winrt::Windows::UI::Notifications::ToastNotificationManager::CreateToastNotifier(L"com.dexterous.example");
notifier.Show(notif);
|
Ahh thanks, that makes sense now. I am not a C++ programmer, so I really appreciate your help! |
Hi, is it working as expected now after your latest commits? |
Basic title body notification is working, but nothing beyond that. |
@lzzy12 Just an update: I have implemented |
FYI this reminds me that Edit: had trouble adding |
@kennethnym any updates on this PR? |
Hi sorry, busy with coursework at the moment, I will continue the work this weekend. |
Just a bit of progress update: I am currently in the process of implementing onSelectNotification callback. Update: onSelectNotification now works, but only when the program is active. |
At the moment, |
Sorry for the silence, I am currently busy with courseworks. At the moment I am still stuck with the issue above. I would really appreciate it If anyone can help me with it. |
Hello @kennethnym. I've tried your branch and I managed to make it work more than once. Cherry-pick this commit from my fork: |
@kennethnym I tried your WIP branch and had some issues with notifications and msix packaging, |
Thanks for bring that to attention, I'll investigate how to handle msix apps as well. |
@sidevesh Can you test if the latest commit fixes your issue? |
I get the following error when building an app with the latest commit:
|
Thanks for reporting, it's an easy fix. |
@sidevesh the issue should be fixed. |
Hey @kennethnym , after the latest commit, I am able to build the app but notification has stopped showing up now. |
Thanks for reporting, I'll look into this.
It should be possible to implement this behavior on Windows as well. |
@sidevesh From the issue you linked earlier, @azchohfi mentioned:
I have in fact integrated this into the code in previous commits already: if (hasIdentity.value())
toastNotifier = winrt::Windows::UI::Notifications::ToastNotificationManager::CreateToastNotifier();
else
toastNotifier = winrt::Windows::UI::Notifications::ToastNotificationManager::CreateToastNotifier(winrt::to_hstring(aumid)); Is the app name still not showing up correctly? As for the other issues, I still need some time to figure out what's going on that is causing them to occur. |
hey @kennethnym , tried it again and same behavior, notifications have stopped showing up, |
Like I mentioned previously I had simply replaced the |
I am struggling to understand why it would stop working altogether. Exams are coming up for me; I'll start working on it again after exams. |
Also, any pointers about the issue: |
I have no idea what is causing that issue either. It wasn't happening before, and I never changed the code related to that. |
Okay, I will try testing this in a non msix build to see if msix packaging is causing the difference in behavior, might help us debug this issue. |
I'm looking forward to using this on Windows, Is it a long way from launch? |
Sorry for the silence. I've been very busy lately, so I was not able to squeeze time to work on this. I will give this another look over the weekend. |
Hello, guys |
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 found some parts in the code that could be improved, could you please take a look?
|
||
const auto bindingNode = doc.SelectSingleNode(L"//binding[1]"); | ||
|
||
if (title.has_value()) { |
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.
According to this link: https://docs.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/adaptive-interactive-toasts?tabs=xml
Maybe we can pass the XML text directly to the plugin and then combine the title and content etc into XML text on the Dart code side?
In this way, more Toast styles can be easily supported in the future.
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.
That is something that I have thought about actually - a Windows specific method that allows users to pass in XML of the notification toast directly.
/// <summary> | ||
/// String representation of the callback GUID. | ||
/// </summary> | ||
const std::string CALLBACK_GUID_STR = "{68d0c89d-760f-4f79-a067-ae8d4220ccc1}"; |
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.
According the resources doc in UpdateRegistry. It looks like every application should have a unique GUID, so the GUID here should be configurable. Maybe change the GUID to be passed from the initialization parameter instead?
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.
Gotcha, will fix.
|
||
UINT32 length; | ||
auto err = GetCurrentPackageFullName(&length, nullptr); | ||
if (err != ERROR_INSUFFICIENT_BUFFER) { |
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.
When I run the example here, it returns the error code 87(ERROR_INVALID_PARAMETER) which causes the initialization to fail. But when I still return false(not std:nullopt) here, the plugin still works fine.
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 found the cause of the problem. The variable length
needs to be initialized.
Replace UINT32 length;
to UINT32 length = 0;
could resolve this issue.
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.
Wow! Can't wait! Thank you guys for working on this.
Quick update - I recently switched to working on a MacBook fully as I will be away from my main computer for an extended period. Parallel seems to be a good option for running Windows on a MacBook. As soon as I get that up and running I should be able to start working on this (longrunning) PR, addressing @lightrabbit 's helpful comments as well. |
Hello everybody! |
I think this is a known issue at the moment. Unfortunately I don't have the time at the moment to look into this, but when I do I will see what's going I'll see what I can do to fix it! |
hi @kennethnym is there any news for support on windows ? |
This draft PR contains Windows implementation of this plugin. Still a WIP.
initialize
WIPshow
WIPperiodicallyShow
(not sure if possible due to limitation of win32)cancel
cancelAll
pendingNotificationRequests
onSelectNotification
WIPcc @azchohfi
Related issue: #746