getstation / desktop-app

One app to rule them all!
https://getstation.com/
Apache License 2.0
1.35k stars 205 forks source link

Gmail Notifications #376

Open viktor44 opened 1 month ago

viktor44 commented 1 month ago

What is this PR

Fixed Notifications not working #177 for Gmail

viktor44 commented 1 month ago

Hey @magne4000 I need your bright ideas again. Here is a fix for notifications. Checking them in Gmail. It more or less works (at least from my point of view 😄 ) except one problem - Stations hangs for ~30 sec when we receive first notification after start. I don't understand why.
Please take a look when you have time.

magne4000 commented 1 month ago

I cannot test that right now, probably during the next few days I'll be able to, but in the mean time, can you explain what you did to "fix" this issue? It seems to me you just extracted BxNotification into another file, and injected it before the actual preload, is that it? If so, my guess is that something crashes before require('../../notification-center/webview-preload');, but it should then be visible in Gmail's page devtool.

viktor44 commented 1 month ago

I cannot test that right now, probably during the next few days I'll be able to, but in the mean time, can you explain what you did to "fix" this issue? It seems to me you just extracted BxNotification into another file, and injected it before the actual preload, is that it? If so, my guess is that something crashes before require('../../notification-center/webview-preload');, but it should then be visible in Gmail's page devtool.

I separated the code because of isolated context. Preload script is executed in the node context and setup window.bxApi variable which can be used inside Gmail. Preload script now doesn't have an access to page's window object, so you can't override window. Notification here. Then inject script is ran in Gmail context and override window. Notification. No ipcRenderer here. You can connect with main application only using window.bxApi.

So the algorithm is the same as before. I only changed the implementation.

require('../../notification-center/webview-preload'); is commented and isn't ran at all

magne4000 commented 1 month ago

I noticed that when I reload gmail page, and then trigger a notification, all handlers seems to be called once more. (So after 10 reload, notification is received 11 times in the rest of the app).

viktor44 commented 1 month ago

Hey @magne4000 have you had a chance to take a look at the problem Stations hangs for ~30 sec when we receive first notification after start.?

magne4000 commented 1 month ago

Hey @magne4000 have you had a chance to take a look at the problem Stations hangs for ~30 sec when we receive first notification after start.?

I did not do much since my last comment, and probably will not dig further into that matter TBH. It's one of those issue that reminds me why we changed direction back in the days at Stationâ„¢, and I'm not willing to spend too much time debugging this project anymore.

That being said, if handlers are registered on page refresh, but previous ones are not dropped, that's probably why you have this issue. If it comes from internal Services system, you can enable DEBUG=service:* to check if lifecycle seems weird. Otherwise it probably comes from somewhere related to the preload lifecycles.