mohabouje / WinToast

WinToast is a lightly library written in C++ which brings a complete integration of the modern toast notifications of Windows 8 & Windows 10. Toast notifications allows your app to inform the users about relevant information and timely events that they should see and take action upon inside your app, such as a new instant message, a new friend request, breaking news, or a calendar event.
MIT License
688 stars 127 forks source link

Expiration time note #30

Closed malja closed 6 years ago

malja commented 6 years ago

I added short comment on expiration time method and source code example. Required in issue #29.

However after testing, expiration time affects the time notification is shown to user before moved to Action Center. I do not think this is intended.

There are many applications with working notifications. How do they bypass this? Would you please point me to anything more I can do about this?

mohabouje commented 6 years ago

Taking a look in the src code (this part was not done by myself) I see that we use the interface ExpirationTime Property. From the official Microsoft documentation, I found:

ExpirationTime Property: Gets or sets the time after which a toast notification should not be displayed.

And also:

The date and time after which the toast is no longer considered current or valid and should not be displayed. Windows attempts to raise toast notifications immediately after you call Show, so this property is rarely used.

Another interesting fact:

For Windows Phone 8.x app: this property also causes the toast notification to be removed from the action center once the specified date and time is reached.

So, it seems that this expiration date has two usages:

So, there is 3 behavior to test & document.

By the way, I saw something strange in the code, the class MyDateTime aims to set up an expiration time by taking the current time (Now) and increasing it with the expiration time. In this in this [line](class MyDateTime : public IReference).

_dateTime.UniversalTime = Now() + millisecondsFromNow * 10000;

I think that the idea is to convert the msecs to nanoseconds, so the conversion factor is not correct. I have to check the documentation about the DateTime class.

[EXTRA INFO]

Should check this:

https://blogs.msdn.microsoft.com/tiles_and_toasts/2015/07/08/toast-notification-and-action-center-overview-for-windows-10/

The notifications are grouped on a per-app basis and ordered chronologically inside action center. Each app can have up to 20 notifications in it (older notifications eventually get pushed out by new ones). A toast notification will stay in action center for 7 days until it expires (which will then be removed from action center), unless an earlier expiration time is specified during the creation of the toast.

mohabouje commented 6 years ago

UPDATE: Taking a look in to the Microsoft documentation about the DateTime class, we have to focus in the FILETIME structure, there we found:

Note that the FILETIME structure is based on 100-nanosecond intervals.

So the conversion is correct.

mohabouje commented 6 years ago

You are right @malja, after testing:

However after testing, expiration time affects the time notification is shown to user before moved to Action Center. I do not think this is intended

This is not the normal behavior but it's what the lib is doing :S.

[UPDATE]

@malja after a long debugging I found something that can describe the problem.

The expiration time is not related with the time the toast is showed in the screen.

This time is managed by the "duration" field of the XML: https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-toast

This parameter can be "short" or "long".

By default is short, but if you add actions to the toast is set up to "long" to give enough time to the user to react to the toast.

Try to launch a notification without actions or with actions to see the differences.

By the way, in the next version I will add a new setter/getter to allow modifications. And some interesting features as the groups/tags. Best regards.

malja commented 6 years ago

@mohabouje You are right. I apologize. I did some changes to system configuration and thought it was effect of setExpiration method. Nevertheless, as I pointed out in #29, you still may want to allow saving notifications in Action center for each app. On my installation, it was not set by default.

Do you need any help with future update?

mohabouje commented 6 years ago

@malja Definitely! Feel free to contribute. It's not something requested but it seems to be something interesting. My idea is to add some extra features that are available in modern Windows version like:

  1. RemoteID: sets a remote id for the notification that enables the system to correlate this notification with another one generated on another device.
  2. Group: sets the group identifier for the notification.
  3. Tag: sets the unique identifier of this notification within the notification Group.

Then the library will give you a better way to manage/group your task.