timche / gmail-desktop

:postbox: Nifty Gmail desktop app for macOS, Linux & Windows
MIT License
845 stars 90 forks source link

app does not handle network change events #157

Closed cyfrost closed 3 years ago

cyfrost commented 5 years ago

Hi, push notifications for new emails are a great feature, thanks for building it.

I've observed a few scenarios where it may not work as intended:

Scene 1:

  1. Turn off wifi or whichever the active network connection is.
  2. Open the Gmail app and see that the site is not loaded (a blank screen is visible instead)
  3. Now turn the network connection back on.

Ideally, the app should listen to network changes and connect to Gmail when connection is back online and also display any missed push notifications for emails since launch time.

Scene 2:

  1. With network connected, open the Gmail app and verify the site it loaded and tray icon active.
  2. Now close gmail to tray.
  3. Put the laptop to sleep (S3).
  4. Wait a few moments and wake the laptop.
  5. Now try sending a test email from another email account to the account active in the Gmail app.

The push notifications don't come through at all or sometimes arrive minutes later (can stem from kernel refreshing existing sockets periodically).

Please note that the reproducing Scene #2 may not always work, in which case, we can either try reproducing it reliably or drop it as a non-issue.

Possible solution

Subscribe to network changes and handle them appropriately. Fortunately, Electron already has these APIs.

I'm working on this bug and will soon open a PR. Any thoughts?

mskelton commented 5 years ago

@cyfrost Push notifications in Gmail Desktop have been a long standing pain point for me (see #15 and #38). Because the notifications use the default "browser-style" notifications and not native electron notifications, they limit what we are able to do with them.

One approach I've considered but haven't had a chance to try is listening to network traffic and creating our own notifications when those requests are received. This would open an interesting door as we would then be able to fully customize notification content, support sticky and disabled notifications, and potentially fix issues with custom styles in windows opened when clicking on notifications.

This GitHub project has an example of what I'm referring to, although much more in-depth than what would probably be necessary: https://github.com/KartikTalwar/gmail.js/blob/9e69719b294c7386017b41bb37539c9588e4701f/src/gmail.js#L1164

timche commented 4 years ago

Point 1 is now handled by cd951ca.

timche commented 4 years ago

Point 2 could be solved by reloading Gmail when the machine wakes up. Wdyt?