Skip to content

Add check permission without user request #11

@nikminer

Description

@nikminer

Add a check for permission of browser notifications without asking the user for permission, since the NotificationService.PermissionStatus parameter is always default; it is impossible to get the current status without asking the user for permission, although in the js Notification object itself the status is available without asking for verification.

This is necessary so that the site can operate within the current user permissions and not request any additional actions.

To implement this, you can add to the script: script.js

export function getPermission() {
    return new Promise((resolve, reject) => {
        resolve(Notification.permission);
    });
}

and this method to NotificationService

public async ValueTask<PermissionType> GetPermissionAsync()
{
    var module = await _moduleTask.Value;
    string permission = await module.InvokeAsync<string>("getPermission");

    if (permission.Equals("granted", StringComparison.InvariantCultureIgnoreCase))
        PermissionStatus = PermissionType.Granted;

    if (permission.Equals("denied", StringComparison.InvariantCultureIgnoreCase))
        PermissionStatus = PermissionType.Denied;

    if (permission.Equals("default", StringComparison.InvariantCultureIgnoreCase))
        PermissionStatus = PermissionType.Default;

    return PermissionStatus;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions