eNkru/freelook

No new mail notification

luisrdzruiz opened this issue · 15 comments

OS: Fedora 32
Freelook Ver: 1.0.1

when receive new mail don't show notification.

eNkru commented

MS changed the unread div class every time when they do a new release. That's why I make the lookup class configurable.

Could you please check what's the value you put into that configuration? the following is mine.

image

I think the problem is the check against the aria-label and the configured language.

If the configured language is not english, the following check will fail

      var unread = messages[0].querySelectorAll('div[aria-label^="Unread"]');

since Unread will be translated to configured language (e.g. for german aria-label will be Ungelesen ...., for spanish no leído or inédito????)

The only thing which should work for each configured language is searching for div's with a left border (Unread message). At least in my environment this border is always set to class WHHpfJX04sHbd6jCFcPxS

eNkru commented

good to know that. this class value will change anytime when Microsoft update outlook.com

It's been changed a few times in the passed.

I'll have a look if there is a better solution for that

Wouldn't it be easier to use the count of unread messages directly from the navigation bar instead trying to parse all messages?

image

The mutation observer callback should already contain the span element that contains the count of unread messages, so it wouldn't even be necessary to parse the DOM for the unread message count.

When storing the previous count it would be also possible to show the delta count of new messages received since last notification/application start.

Or do i miss something?

If you want I can create a pull request for this change.

Maybe i found a even better way, that would also remove the need for the span class name at all.

Every time a new mail is received, Outlook will perform multiple request to fetch the new mail, notification sound .....

image

In electron it's possible to register a callback for webrequests: https://www.electronjs.org/docs/api/web-request

So it would be possible to listen for the webrequest of the e.g. newmail.mp3

this.win.webContents.on('dom-ready', () => {
            this.win.webContents.insertCSS(CssInjector.main);
            if (!showWindowFrame) this.win.webContents.insertCSS(CssInjector.noFrame);

            // this.addUnreadNumberObserver();
            session.defaultSession.webRequest.onBeforeRequest({urls: ["*://*/**/newmail.mp3"]},()=>{
                this.win.webContents.executeJavaScript(`
     
                                
                            try{
                                require('electron').ipcRenderer.send('updateUnread', true);
                                var notification = new Notification("Outlook - receiving new messages.", {
                                    icon: "assets/outlook_linux_black.png"
                                });
                                notification.onclick = () => {
                                        require('electron').ipcRenderer.send('show');
                                };
                            }catch(ex){
                                alert(ex);
                            }
                             
                        `);
            });

            this.win.show()
        });

This will even work if newmail.mp3 is cached by the browser

I'm not sure if this also works for hotmail and if its possible to disable the sound so that the download of newmail.mp3 is not performed.

I think it might be even possible to intercept the subscription response, to receive also the email body, but I haven't found out yet if the push is done via websocket or a SSE.

Request executed to create the push seems to be same as described in https://docs.microsoft.com/en-us/previous-versions/office/office-365-api/api/version-2.0/notify-rest-operations

Just reconized that outlook uses fabric ui. Notifications/Callouts in fabri ui are rendered in special div, so it's also possible to add a observer to this area to receive email subject, body ....

    addUnreadNumberObserver() {

        this.win.webContents.executeJavaScript(`
            setTimeout(() => {
                const layerDiv = document.querySelector(".ms-Layer-content");
                const observer = new MutationObserver(mutations => {
                    
                    const emailDiv = document.querySelector("._9Ie6sVh0VX-ro9NAPwFKb");
                    // First childnode == email adress, Second childnode == subject, Third child node == email body
                    if(emailDiv){
                        const notification = new Notification("Outlook - received new message " + emailDiv.childNodes[1].textContent, {
                            body: emailDiv.childNodes[0].textContent  + "\\n" +  emailDiv.childNodes[1].textContent + "\\n" +  emailDiv.childNodes[2].textContent,
                            icon: "assets/outlook_linux_black.png"
                        });
                        notification.onclick = () => {
                            require('electron').ipcRenderer.send('show');
                        };

                    }
                });
            
                observer.observe(layerDiv, {childList: true, subtree: true});

            }, 10000);
        `)
    }
eNkru commented

@roggenbrot listen to the newmail.mp3 sounds very hacky for me and I reckon it might not working in the variate user settings. I am quite like your fabric ui solution. Could you make a pull request? and I'll test on the hotmail account see if that works. Many thanks.

I think i found a even better solution. In the browser you are able to enable desktop notifications in the settings

image

This feature is disabled in the electron app because of the missing/wrong user-agent header.

image

So instead registering a observer, parsing the DOM .... the easiest solution is to set the user-agent when loading the page:

this.win.loadURL(homepageUrl, {userAgent: 'Chrome'});

After setting the user-agent, the desktop notification can be enabled in the settings and will also work for other O365 notifications (e.g. calendar notifications ...)

I've changed the pull request

eNkru commented

I think i found a even better solution. In the browser you are able to enable desktop notifications in the settings

image

This feature is disabled in the electron app because of the missing/wrong user-agent header.

image

So instead registering a observer, parsing the DOM .... the easiest solution is to set the user-agent when loading the page:

this.win.loadURL(homepageUrl, {userAgent: 'Chrome'});

After setting the user-agent, the desktop notification can be enabled in the settings and will also work for other O365 notifications (e.g. calendar notifications ...)

I've changed the pull request

@roggenbrot have you changed this solution in the PR? I still see the previous observer in the PR. Let me know when you change it, I'll merge it in with your spell checking logic as well.

The outlook desktop notification do not work as I expected.

grafik

They only show notifications when outlook is closed, but browser is still open.

In my local test it just worked because firefox was still running, so it was firefox that showed the notification, not electron :(

So back to observer ......

I'm trying to find a better approach to get rid of the class names. I'm trying to implement a function at the moment that searches on startup based on a checksum the correct class name, and only fallback to configured class names if the user changes it in the settings.

Normally content of component styles are changed not very often in a apps like owa,so if the class name changes cause of a recompile/new version, the checksum mechanism should still work

Finished the pull request. Can someone test if the notifications for emails/reminders also work on hotmail?

I'm having the same problem:
KDE Neon 5.19
Freelock v1.0.1

The span appears to be correct:
image

The intention is to show a system notification, right?

@hookumsnivy You can try the pull request if this will fix your problems (I could also create a AppImage of the pull request)

I've also fixed a bug in the pull request that caused settings to reset on next startup

eNkru commented

This solution looks very hacky and can stopped to work in any time. I'd like to keep this open until have a better solution. Any idea is welcomed.