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

Prevent windows toast notification when in foreground #145

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

Comments

Projects
None yet
3 participants
@Deathspike

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

This comment has been minimized.

Show comment
Hide comment
@Deathspike

Deathspike Sep 16, 2015

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.
});

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

This comment has been minimized.

Show comment
Hide comment
@rakatyal

rakatyal Sep 16, 2015

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.

Collaborator

rakatyal commented Sep 16, 2015

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

This comment has been minimized.

Show comment
Hide comment
@macdonst

macdonst Sep 16, 2015

Member

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

Member

macdonst commented Sep 16, 2015

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

@rakatyal

This comment has been minimized.

Show comment
Hide comment
@rakatyal

rakatyal Sep 16, 2015

Collaborator

Sure. Will do that.

Collaborator

rakatyal commented Sep 16, 2015

Sure. Will do that.

@macdonst macdonst closed this Sep 17, 2015

@lock

This comment has been minimized.

Show comment
Hide comment
@lock

lock bot Jun 5, 2018

This thread has been automatically locked.

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.