Skip to content
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

Feature request: notification listener #51

Open
SamRSA opened this issue Jan 15, 2020 · 1 comment
Open

Feature request: notification listener #51

SamRSA opened this issue Jan 15, 2020 · 1 comment

Comments

@SamRSA
Copy link

SamRSA commented Jan 15, 2020

Is it possible to extend library with the ability to listen and read user notifications ?
More details here: https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/notification-listener (example code in article is completely in C#)

I have already started doing it (like 40% complete), but stock on "UserNotificationListenerAccessStatus accessStatus = await listener.RequestAccessAsync();" stage.

Here is code:

ComPtr<IUserNotificationListenerStatics> notificationListener;
HRESULT hr = DllImporter::Wrap_GetActivationFactory(WinToastStringWrapper(RuntimeClass_Windows_UI_Notifications_Management_UserNotificationListener).Get(), &notificationListener);
if (SUCCEEDED(hr)) {

    ComPtr<IUserNotificationListener> listener;
    hr = notificationListener->get_Current(&listener);
    if (SUCCEEDED(hr)) {

        // ComPtr<UserNotificationListenerAccessStatus> accessStatus;
        ComPtr<__FIAsyncOperation_1_Windows__CUI__CNotifications__CManagement__CUserNotificationListenerAccessStatus> accessStatus;

        // UserNotificationListenerAccessStatus accessStatus = await listener.RequestAccessAsync();
        hr = listener->RequestAccessAsync(&accessStatus);
        if (SUCCEEDED(hr)) {

            switch (accessStatus)
            {
                case UserNotificationListenerAccessStatus_Allowed:
                    std::wcout << L"Toast Allowed" << std::endl;
                    break;

                case UserNotificationListenerAccessStatus_Denied:
                    std::wcout << L"Toast Denied" << std::endl;
                    break;

                case UserNotificationListenerAccessStatus_Unspecified:
                    std::wcout << L"Toast Unspecified" << std::endl;
                    break;
            }
            
        }
    }

Has anyone already done this in C++ ? If not, let's add this functionality together.

@mohabouje
Copy link
Owner

Do you have a working version of this feature that we can merge into a PR? I am organizing the features for the coming version and thinking to add support for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants