Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Prevent windows toast notification when in foreground #145

Closed
Deathspike opened this issue Sep 16, 2015 · 5 comments
Closed

Prevent windows toast notification when in foreground #145

Deathspike opened this issue Sep 16, 2015 · 5 comments
Assignees

Comments

@Deathspike
Copy link

When receiving a notification in the foreground, the platforms behave as followed:

  • Android: Dispatch 'notification' event.
  • iOS: Dispatch 'notification' event.
  • Windows: Dispatch 'notification event'. Show toast notification.

Unlike Android and iOS, Windows does show a system notification even if it is handled. This essentially means that the notification can be fired twice, and that can and will break assumptions. In the spirit of normalizing the differences between the platforms, I propose a change to stop the toast notification when handling a foreground notification on the Windows platform.

Change:

    var onNotificationReceived = function (e) {
        var result = createNotificationJSON(e);
        onSuccess(result, { keepCallback: true });
    }

To:

    var onNotificationReceived = function (e) {
        var result = createNotificationJSON(e);
        onSuccess(result, { keepCallback: true });
        e.cancel = true;
    }

On https://github.com/phonegap/phonegap-plugin-push/blob/master/src/windows/PushPluginProxy.js#L53

@Deathspike
Copy link
Author

For those that found this thread and want to do this manually (if this is not approved/merged):

push.on('notification', function (data) {
    if (data.additionalData.pushNotificationReceivedEventArgs) {
        data.additionalData.pushNotificationReceivedEventArgs.cancel = true;
    }
    // TODO: Handle the notification here.
});

@rakatyal
Copy link
Collaborator

Hi @Deathspike ,

Thanks for the detailed issue. Though you make a valid point, but by doing so we will be kicking away the default handling of the notifications by the windows OS, which most of the users might prefer rather than implementing it on their own. As you have already mentioned, the users who want to achieve that can do so by setting the cancel property to true.

@macdonst
Copy link
Member

@rakatyal we should probably add that to the readme under Windows.

@rakatyal
Copy link
Collaborator

Sure. Will do that.

@lock
Copy link

lock bot commented Jun 5, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants