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

No new mail notification #37

Open
luisrdzruiz opened this issue Sep 19, 2020 · 15 comments
Open

No new mail notification #37

luisrdzruiz opened this issue Sep 19, 2020 · 15 comments

Comments

@luisrdzruiz
Copy link

OS: Fedora 32
Freelook Ver: 1.0.1

when receive new mail don't show notification.

@eNkru
Copy link
Owner

eNkru commented Sep 21, 2020

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

@roggenbrot
Copy link
Contributor

roggenbrot commented Sep 22, 2020

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
Copy link
Owner

eNkru commented Sep 22, 2020

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

@roggenbrot
Copy link
Contributor

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.

@roggenbrot
Copy link
Contributor

roggenbrot commented Sep 23, 2020

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.

@roggenbrot
Copy link
Contributor

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

@roggenbrot
Copy link
Contributor

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
Copy link
Owner

eNkru commented Sep 27, 2020

@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.

@roggenbrot
Copy link
Contributor

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
Copy link
Owner

eNkru commented Oct 6, 2020

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.

@roggenbrot
Copy link
Contributor

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

@roggenbrot
Copy link
Contributor

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

@hookumsnivy
Copy link

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?

@roggenbrot
Copy link
Contributor

@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
Copy link
Owner

eNkru commented Dec 12, 2022

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.

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

No branches or pull requests

4 participants