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

darwin-notifications: Migrate darwin-notifications to electron's native Notifications. #1022

Closed
wants to merge 2 commits into from

Conversation

manavmehta
Copy link
Collaborator

@manavmehta manavmehta commented Aug 18, 2020

What's this PR do?
Electron's native Notifications now supports inline replies on macOS and thus we don't need any 3rd party package.
This commit removes the usage of node-mac-notifier and brings native Notification in picture.

For comprehensibility, ipc-helpers.ts will contain the functions which make use of Main process APIs with already functioning code in Renderer process.

Any background context you want to provide?
This is a potential solution to people not getting notifications on macOS.

You have tested this PR on:

  • macOS Catalina 10.15.6

Follow-ups

  • Display sender's profile picture on each notification

@manavmehta manavmehta force-pushed the mac-notif branch 3 times, most recently from f4e6c2f to e07a4a6 Compare August 24, 2020 20:20
@manavmehta manavmehta changed the title [WIP] darwin-notifications: Migrate darwin-notifications to electron's native Notifications darwin-notifications: Migrate darwin-notifications to electron's native Notifications. Aug 25, 2020
@manavmehta manavmehta force-pushed the mac-notif branch 2 times, most recently from aaaef3d to cd9712b Compare August 25, 2020 17:20
@zulipbot zulipbot added size: XL and removed size: L labels Aug 26, 2020
@manavmehta manavmehta force-pushed the mac-notif branch 2 times, most recently from adfc7a3 to de45ae3 Compare August 26, 2020 17:01
Copy link
Member

@andersk andersk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chrome now also supports inline notification replies. I think it would be better to use that API to implement this feature in the web app so we don’t have to maintain this platform-specific monkey patch in zulip-desktop.

*/
import {Notification, nativeImage} from 'electron';

import fetch from 'node-fetch';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node-fetch doesn’t use the Electron network stack, so this won’t work with custom certificates, proxies, etc. We should use electron.net like everything else.

const response = await fetch(imageURL);
const buffer = await response.buffer();
const base64String = buffer.toString('base64');
const dataUri = `data:image/png;base64,${base64String}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we know it’s a PNG?

Copy link
Collaborator Author

@manavmehta manavmehta Aug 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. Referring to this piece of code, I missed this part somehow fiddling around. Adding it back.

ipcRenderer.send('create-notification', notificationOptions, profilePicURL);
ipcRenderer.on('replied', async (_event: Electron.IpcRendererEvent, response: string) => {
await this.notificationHandler({response});
ipcRenderer.removeAllListeners('replied');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removeAllListeners? Did you just want to use ipcRenderer.once instead?

Comment on lines +95 to +96
// Method specific to Zulip's notification module, not the package used to create the same.
// If at all the need arises to migrate to another API (or npm package), DO NOT REMOVE THIS.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t understand this new comment. Notification.close() is part of the standard Notification API. It’s not Zulip-specific.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous comment got me believing that this was specific to node-mac-notifier. So I tried to refine it. I'll remodel it.

profilePicURL: string
) => {
const profilePic = await getNativeImagefromUrl(profilePicURL);
notificationOptions.icon = profilePic;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to go through the NativeImage dance? Can we not just set icon to the URL?

Copy link
Collaborator Author

@manavmehta manavmehta Aug 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to do that from the beginning but it throws this error while converting
this

Copy link
Member

@akashnimare akashnimare Sep 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andersk the API doesn't support passing the URL directly. That's why we have to go through the nativeImage process.
https://www.electronjs.org/docs/api/notification#new-notificationoptions

cc @priyank-p

@zulipbot
Copy link
Member

Heads up @manavmehta, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/master branch and resolve your pull request's merge conflicts accordingly.

@akashnimare
Copy link
Member

@manavmehta would you be up for finishing this?

@mateuszmandera
Copy link

Any updates on this?

@manavmehta
Copy link
Collaborator Author

@mateuszmandera Sorry I was really occupied the last two months. I'll try to get back by Tuesday :)

@mateuszmandera
Copy link

@manavmehta Awesome, thanks!

@manavmehta
Copy link
Collaborator Author

@mateuszmandera do you have macOS too?

…ve Notifications.

Electron's native Notifications now supports inline replies on macOS and thus we don't need any 3rd party package.
This commit removes the usage of node-mac-notifier and brings native Notification in picture.

For comprehensibility, ipc-helpers will contain the functions which make use of Main process APIs with already functioning code in Renderer process.
This is a potential solution to people not getting notifications on macOS.
@mateuszmandera
Copy link

@manavmehta Sadly no 😞

andersk added a commit to andersk/zulip-desktop that referenced this pull request Dec 2, 2020
node-mac-notifier no longer builds on macOS with Electron 11 (error:
no template named 'remove_cv_t' in namespace 'std').  It was
previously implicated in crashes on macOS (zulip#1016).  And we no longer
have any macOS developers that seem to be maintaining this
feature (e.g. zulip#1022 is stalled).

Signed-off-by: Anders Kaseorg <anders@zulip.com>
andersk added a commit to andersk/zulip-desktop that referenced this pull request Dec 2, 2020
node-mac-notifier no longer builds on macOS with Electron 11 (error:
no template named 'remove_cv_t' in namespace 'std').  It was
previously implicated in crashes on macOS (zulip#1016).  And we no longer
have any macOS developers that seem to be maintaining this
feature (e.g. zulip#1022 is stalled).

Signed-off-by: Anders Kaseorg <anders@zulip.com>
@manavmehta
Copy link
Collaborator Author

Considering the discussion going on in CZO stream, I will be closing this PR for now.

@manavmehta manavmehta closed this Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants